Skip to content

Commit

Permalink
mm: Account for mult split buffer when making MultiTrade
Browse files Browse the repository at this point in the history
The market making code did not account for the multi split buffer when
determining the orders to place. This caused the btc and dcr wallets to
error when the bot had insufficient funds.
  • Loading branch information
martonp committed Jan 23, 2025
1 parent 333e9f6 commit b704049
Show file tree
Hide file tree
Showing 3 changed files with 422 additions and 1 deletion.
18 changes: 18 additions & 0 deletions client/mm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mm
import (
"encoding/json"
"fmt"
"strconv"
)

// MarketMakingConfig is the overall configuration of the market maker.
Expand Down Expand Up @@ -127,6 +128,23 @@ func (c *BotConfig) requiresCEX() bool {
return c.SimpleArbConfig != nil || c.ArbMarketMakerConfig != nil
}

// multiSplitBuffer returns the additional buffer to add to the order size
// when doing a multi-split. This only applies to the quote asset.
func (c *BotConfig) multiSplitBuffer() float64 {
if c.QuoteWalletOptions == nil {
return 0
}
multiSplitBuffer, ok := c.QuoteWalletOptions["multisplitbuffer"]
if !ok {
return 0
}
multiSplitBufferFloat, err := strconv.ParseFloat(multiSplitBuffer, 64)
if err != nil {
return 0
}
return multiSplitBufferFloat
}

// maxPlacements returns the max amount of placements this bot will place on
// either side of the market in an epoch.
func (c *BotConfig) maxPlacements() (buy, sell uint32) {
Expand Down
7 changes: 6 additions & 1 deletion client/mm/exchange_adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,14 +1218,19 @@ func (u *unifiedExchangeAdaptor) multiTrade(

rateCausesSelfMatch := u.rateCausesSelfMatchFunc(sell)

multiSplitBuffer := u.botCfg().multiSplitBuffer()

fundingReq := func(rate, lots, counterTradeRate uint64) (dexReq map[uint32]uint64, cexReq uint64) {
qty := u.lotSize * lots
swapFees := fees.Swap * lots
if !sell {
qty = calc.BaseToQuote(rate, qty)
qty = uint64(math.Round(float64(qty) * (100 + multiSplitBuffer) / 100))
swapFees = uint64(math.Round(float64(swapFees) * (100 + multiSplitBuffer) / 100))
}
dexReq = make(map[uint32]uint64)
dexReq[fromID] += qty
dexReq[fromFeeID] += fees.Swap * lots
dexReq[fromFeeID] += swapFees
if u.isAccountLocker(fromID) {
dexReq[fromFeeID] += fees.Refund * lots
}
Expand Down
Loading

0 comments on commit b704049

Please sign in to comment.