Skip to content

Commit

Permalink
client/mm: Refactor bot balance tracking
Browse files Browse the repository at this point in the history
- This diff updates the balance tracking for market making bots. Previously,
there was a fragile diff based accounting technique. Now, on each bot
action, including trades, withdrawals, and deposits, a pending action is
stored. This pending action is updated until it is complete, at which time
it is removed, and the "base" balance of the bot is updated. The bot
balances are calculated by adding the base balances of the bot to the
effects of all pending actions.

- The `wrappedCore` and `wrappedCEX` types are removed, and their functionalities
are combined into a `unifiedExchangeAdaptor`. This is useful because
pending deposits and pending withdrawals have balance effects on both
CEX and DEX balances. Each `unifiedExchangeAdaptor` listens to a core
notification stream, and the `MarketMaker` type no longer needs to. In
a future refactor, the bots themselves will no longer listen to the
core notification functionality, and all common functionalities can be
moved to the `unifiedExchangeAdaptor`.

- Previously, the fee assets of tokens were not taken into account, but
now they are.

- The Binance library now uses a different endpoint, `/api/v3/balances`,
to get balances. This is supported by the Binance testnet api, so
testbinance is no longer required for balances.
  • Loading branch information
martonp committed Dec 28, 2023
1 parent 0952aac commit 2410dbe
Show file tree
Hide file tree
Showing 18 changed files with 6,051 additions and 6,352 deletions.
758 changes: 695 additions & 63 deletions client/cmd/testbinance/main.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions client/mm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ type BotConfig struct {
QuoteBalanceType BalanceType `json:"quoteBalanceType"`
QuoteBalance uint64 `json:"quoteBalance"`

BaseFeeAssetBalanceType BalanceType `json:"baseFeeAssetBalanceType"`
BaseFeeAssetBalance uint64 `json:"baseFeeAssetBalance"`
QuoteFeeAssetBalanceType BalanceType `json:"quoteFeeAssetBalanceType"`
QuoteFeeAssetBalance uint64 `json:"quoteFeeAssetBalance"`

// Only applicable for arb bots.
CEXCfg *BotCEXCfg `json:"cexCfg"`

Expand Down
Loading

0 comments on commit 2410dbe

Please sign in to comment.