Skip to content

Commit

Permalink
client/mm: Move shared logic from bots to unifiedExchangeAdaptor
Browse files Browse the repository at this point in the history
This diff moves as much shared logic from bot implementations to the
unifiedExchangeAdaptor as possible.

- All fiat rate and order fee tracking is moved to the
  unifiedExchangeAdaptor.
- The MultiTrade function of the unifiedExchangeAdaptor now takes all
  of the placements that a bot would make, if they had not placed any
  trades yet, and if they had unlimited balance. All of the logic that
  used to be in the basic market maker and mm+arb strategies involving
  determining which trades need to be cancelled/replaced and how many
  trades the bot has balance for is now handled in the MultiTrade
  function.
- The rebalancing functionalities in simple arb and arb+mm are now
  handled by the PrepareRebalance and FreeUpFunds functions.
- An OrderFeesInUnits function is added that calculates the total
  order fees in either the base or quote units. This greatly
  simplifies the basic market maker’s logic that determines the break
  even half-spread. The simple arb and arb+mm bots also use this
  function to take into account order fees, which they did not do
  previously.
- The base/quote wallet settings were repeated in each of the bot
  strategy settings, and the auto-rebalance config was repeated in
  both the simple arb and arb+mm. These are moved to the top level
  config / the bot CEX config, respectively.
  • Loading branch information
martonp committed Feb 20, 2024
1 parent aed1270 commit 5f9422e
Show file tree
Hide file tree
Showing 18 changed files with 4,195 additions and 5,952 deletions.
43 changes: 24 additions & 19 deletions client/mm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,28 @@ type CEXConfig struct {
APISecret string `json:"apiSecret"`
}

// BotCEXCfg specifies the CEX that a bot uses and the initial balances
// that should be allocated to the bot on that CEX.
// AutoRebalanceConfig determines how the bot will automatically rebalance its
// assets between the CEX and DEX. If the base or quote asset dips below the
// minimum amount, a transfer will take place, but only if both balances can be
// brought above the minimum amount and the transfer amount would be above the
// minimum transfer amount.
type AutoRebalanceConfig struct {
MinBaseAmt uint64 `json:"minBaseAmt"`
MinBaseTransfer uint64 `json:"minBaseTransfer"`
MinQuoteAmt uint64 `json:"minQuoteAmt"`
MinQuoteTransfer uint64 `json:"minQuoteTransfer"`
}

// BotCEXCfg specifies the CEX that a bot uses, the initial balances
// that should be allocated to the bot on that CEX, and the configuration
// for automatically rebalancing between the CEX and DEX.
type BotCEXCfg struct {
Name string `json:"name"`
BaseBalanceType BalanceType `json:"baseBalanceType"`
BaseBalance uint64 `json:"baseBalance"`
QuoteBalanceType BalanceType `json:"quoteBalanceType"`
QuoteBalance uint64 `json:"quoteBalance"`
Name string `json:"name"`
BaseBalanceType BalanceType `json:"baseBalanceType"`
BaseBalance uint64 `json:"baseBalance"`
QuoteBalanceType BalanceType `json:"quoteBalanceType"`
QuoteBalance uint64 `json:"quoteBalance"`
AutoRebalance *AutoRebalanceConfig `json:"autoRebalance"`
}

// BotConfig is the configuration for a market making bot.
Expand All @@ -66,6 +80,9 @@ type BotConfig struct {
QuoteFeeAssetBalanceType BalanceType `json:"quoteFeeAssetBalanceType"`
QuoteFeeAssetBalance uint64 `json:"quoteFeeAssetBalance"`

BaseWalletOptions map[string]string `json:"baseWalletOptions"`
QuoteWalletOptions map[string]string `json:"quoteWalletOptions"`

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

Expand All @@ -91,15 +108,3 @@ func (c *BotConfig) requiresCEX() bool {
func dexMarketID(host string, base, quote uint32) string {
return fmt.Sprintf("%s-%d-%d", host, base, quote)
}

// AutoRebalanceConfig determines how the bot will automatically rebalance its
// assets between the CEX and DEX. If the base or quote asset dips below the
// minimum amount, a transfer will take place, but only if both balances can be
// brought above the minimum amount and the transfer amount would be above the
// minimum transfer amount.
type AutoRebalanceConfig struct {
MinBaseAmt uint64 `json:"minBaseAmt"`
MinBaseTransfer uint64 `json:"minBaseTransfer"`
MinQuoteAmt uint64 `json:"minQuoteAmt"`
MinQuoteTransfer uint64 `json:"minQuoteTransfer"`
}
Loading

0 comments on commit 5f9422e

Please sign in to comment.