Skip to content

Commit

Permalink
client/mm: Arb Market Maker (#2530)
Browse files Browse the repository at this point in the history
* client/mm: Arb Market Maker

This adds a market making strategy that is kind of a combination
between the basic market maker and the simple arbitrage strategies.
Based on a CEX order book, it places orders on the DEX order book, and
when there is a match on the DEX, the opposite order on the DEX is
immediately executed for a profit.
  • Loading branch information
martonp authored Nov 15, 2023
1 parent 7d11d2c commit cb851d1
Show file tree
Hide file tree
Showing 7 changed files with 1,670 additions and 31 deletions.
13 changes: 3 additions & 10 deletions client/mm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import (
"fmt"
)

// MarketMakingWithCEXConfig is the configuration for a market
// maker that places orders on both sides of the order book, but
// only if there is profitable counter-trade on the CEX
// order book.
type MarketMakingWithCEXConfig struct {
}

type BalanceType uint8

const (
Expand Down Expand Up @@ -49,9 +42,9 @@ type BotConfig struct {
QuoteBalance uint64 `json:"quoteBalance"`

// Only one of the following configs should be set
BasicMMConfig *BasicMarketMakingConfig `json:"basicMarketMakingConfig,omitempty"`
SimpleArbConfig *SimpleArbConfig `json:"simpleArbConfig,omitempty"`
MMWithCEXConfig *MarketMakingWithCEXConfig `json:"marketMakingWithCEXConfig,omitempty"`
BasicMMConfig *BasicMarketMakingConfig `json:"basicMarketMakingConfig,omitempty"`
SimpleArbConfig *SimpleArbConfig `json:"simpleArbConfig,omitempty"`
ArbMarketMakerConfig *ArbMarketMakerConfig `json:"arbMarketMakerConfig,omitempty"`

Disabled bool `json:"disabled"`
}
Expand Down
2 changes: 1 addition & 1 deletion client/mm/libxc/binance.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func (bnc *binance) requestInto(req *http.Request, thing interface{}) error {
return nil
}
// TODO: use buffered reader
reader := io.LimitReader(resp.Body, 1<<20)
reader := io.LimitReader(resp.Body, 1<<22)
r, err := io.ReadAll(reader)
if err != nil {
return err
Expand Down
16 changes: 14 additions & 2 deletions client/mm/mm.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,14 +980,26 @@ func (m *MarketMaker) Run(ctx context.Context, pw []byte, alternateConfigPath *s
wg.Add(1)
go func(cfg *BotConfig) {
defer wg.Done()
logger := m.log.SubLogger(fmt.Sprintf("Arbitrage-%s-%d-%d", cfg.Host, cfg.BaseAsset, cfg.QuoteAsset))
logger := m.log.SubLogger(fmt.Sprintf("SimpleArbitrage-%s-%d-%d", cfg.Host, cfg.BaseAsset, cfg.QuoteAsset))
cex, err := getConnectedCEX(cfg.SimpleArbConfig.CEXName)
if err != nil {
logger.Errorf("failed to connect to CEX: %v", err)
logger.Errorf("Failed to connect to CEX: %v", err)
return
}
RunSimpleArbBot(m.ctx, cfg, m.core, cex, logger)
}(cfg)
case cfg.ArbMarketMakerConfig != nil:
wg.Add(1)
go func(cfg *BotConfig) {
defer wg.Done()
logger := m.log.SubLogger(fmt.Sprintf("ArbMarketMaker-%s-%d-%d", cfg.Host, cfg.BaseAsset, cfg.QuoteAsset))
cex, err := getConnectedCEX(cfg.ArbMarketMakerConfig.CEXName)
if err != nil {
logger.Errorf("Failed to connect to CEX: %v", err)
return
}
RunArbMarketMaker(m.ctx, cfg, m.core, cex, logger)
}(cfg)
default:
m.log.Errorf("No bot config provided. Skipping %s-%d-%d", cfg.Host, cfg.BaseAsset, cfg.QuoteAsset)
}
Expand Down
Loading

0 comments on commit cb851d1

Please sign in to comment.