dcrdex
dcrdex copied to clipboard
mm: Individually Start Bots / Live Updates
This diff adds the ability to start/stop bots individually and also to perform live updates to bot settings and the amount of funds controlled by bots.
All balance fields are removed from the BotConfig. These are now specified when a bot is started.
To perform updates to a running bot, an “update manager” consisting of three channels is passed to both the unifiedExchangeAdaptor
and the bot First, the adaptor signals that it wants do an update. The bot pauses all operations, and signals to the adaptor that it is paused. Then, the bot and the adaptor both update their configurations. When the adaptor is finished, it signals to the bot that it can proceed.
To perform a balance update, we need to know the exact amount that is available in the wallets and on the CEX that is not currently reserved by a running bot. To do this, we first check the available amounts according to the wallet/cex, then we sync the state of all pending trades, deposits, and withdrawals, and then we recheck the available amounts. If the first check is the same as the last, we know nothing has changed and we have the correct amounts, so we can proceed. In order for this to work properly, the WalletTransaction
function of wallets must return Confirmed == true
if and only if the any incoming funds from that transaction are part of the available balance.
The priceOracle is also refactored. Instead of having a “synced” priceOracle used for markets on which a bot is running, and an “unsynced” one for any other markets, there is now only one priceOracle. startAutoSyncingMarket
and stopAutoSyncingMarket
are called whenever bots are started / stopped.
A testing program is added that tracks the available balances in wallets/cexes that are unused by any bots. This amount should not change unless the user start, stops, or updates a bot. If there are any unexpected changes, this means there is a bug in the balance tracking.
*This is still in draft as the UI and profit calculations need to be updated based on this work. The new RPC functions can be used to test.