cbh4ou / CryptoRebalanceSVC

A script to run that will balance a crypto portfolio to specific ratios using CCXT
MIT License
1 stars 0 forks source link

Enhance order creation #4

Open cbh4ou opened 1 year ago

cbh4ou commented 1 year ago

We can be fast, or be cheap. Most importantly we need to make sure calculations are accurate. Will add ability for market or limit orders

For finding what coins to sell or buy we will see if any coins we currently have in our targets, then we will see if they need to drop or go higher to match. Essentially if we go one by one, we will hit all our target calculations without doing calculation of orders before hand. These seems like the most efficient way to me, and our calculations should be more accurate, less prone to failed orders. Essentially with "smart routing" we can find two pairs easily by matching base/quotes to the heads or tails of the original symbol, active coins as well. all exchanges give coins a high volume quote so it can be traded efficiently, and most coins without high volume quotes, usually mean they are about to be dropped off the listing.

cbh4ou commented 1 year ago

Currently working on a prototype, uses smart routes, then uses amount set for that target conversion for the trade including the fee. We cant be exact to the cent, so if we have an order fail, we simply open a new one until we hit our target. If we are selling all of our holdings then we know to match the amount exactly minus the fee. Probably should also add the fee to the cost limit, pesky situations we can figure out during a analytical dry run

cbh4ou commented 1 year ago

[[{'direction': 'buy', 'symbol': 'ETH/USD', 'weight' : 12.345}], [{'direction': 'buy', 'symbol': 'AVAX/USD'}], [{'direction': 'buy', 'symbol': 'ONE/USD'}], [{'direction': 'buy', 'symbol': 'BTC/USD'}], [{'direction': 'buy', 'symbol': 'ADA/USD'}], [{'direction': 'buy', 'symbol': 'OP/USD'}], [{'direction': 'buy', 'symbol': 'USDT/USD'}], [{'direction': 'sell', 'symbol': 'OCEAN/USDT'}], [{'direction': 'sell', 'symbol': 'ALGO/USDT'}]]

Here is an example of trade routes, we buy from biggest holding into smallest holding until we meet all allocations. Due to dust we want always be able to meet allocations. Amount not tradable means this is dust, and for this account dust is 3.5%, which is hefty, all values are checked against limits before building trade routes.

starting - {'USD': -0.7218157035388936, 'OCEAN': -0.006815723663332051, 'ALGO': -0.006116939448024413, 'ZEN': 0.01999500172946382, 'USDT': 0.05519468863083177, 'OP': 0.06566367085441682, 'ADA': 0.06998497514847545, 'BTC': 0.09945719687299413, 'ONE': 0.09999916552040947, 'AVAX': 0.13997371088527413, 'ETH': 0.21999159551732025} Ending Weights - Amount not tradable: 0.03551163850893573 {'ZEN': 0.01999500172946382, 'USDT': 0.015516636779471972, 'OP': 0, 'ADA': 0, 'BTC': 0, 'ONE': 0, 'AVAX': 0, 'ETH': 0} {'USD': 0, 'OCEAN': 0, 'ALGO': 0}

cbh4ou commented 1 year ago

Trade routes always get to our destination, else we return false and it gets excluded from being traded and its allocation taken from what can be used. Mostly means its been delisted or has been delisted from the exchange. From there we can do order execution.