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

Implement more linear trade route solution before and during trade execution #2

Open cbh4ou opened 1 year ago

cbh4ou commented 1 year ago

Currently implemented are multiple permutations of trades routes, simplest would be to look for the primary stablecoin, BTC, or ETH quotes as they are most prevalent. Simply put, if a coin has an allocation of 50%, and the target portfolio is 25%, we want to sell down to 25% maybe into USDT. Now, what if we have BTC at an allocation of 15%, and target is 20%. Assume that all other coins met their target already and now have a new 0 -> 20% of USDT allocation

We would create two orders, one to sell into USDT and one to buy BTC assuming it has USDT quote. You will find ETH/BTC always have USDT quote pairs on most exchanges. May help to keep a hardcoded reference of an exchanges favorite stablecoin

cbh4ou commented 1 year ago

This will fix the issue where the balancer just gives up on a coin and gives it a relatively low allocation, and speed up the order execution.

  1. Find best route (lowest fee trade, if we sell/buy will it aid another allocation?, is it even available)
  2. Check balances, and iteratively execute orders until they go through (if market) we can also keep limit orders, but ideally I hope we can get limit orders to close <5 mins to complete any portfolio.
  3. Exchanges will delist coins during rebalance process, so something to catch these trade errors, and report back. Maybe include a hedge currency to go into if the coin is unable to be purchased.
cbh4ou commented 1 year ago

Useful CCXT function(s): calculate_fee