Skip to content

Commit

Permalink
client/mm: Arb Market Maker
Browse files Browse the repository at this point in the history
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 committed Sep 20, 2023
1 parent 6a04997 commit 974ef4e
Show file tree
Hide file tree
Showing 6 changed files with 1,640 additions and 27 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 @@ -43,9 +36,9 @@ type BotConfig struct {
QuoteBalance uint64 `json:"quoteBalance"`

// Only one of the following configs should be set
MMCfg *MarketMakingConfig `json:"marketMakingConfig,omitempty"`
MMWithCEXCfg *MarketMakingWithCEXConfig `json:"marketMakingWithCEXConfig,omitempty"`
ArbCfg *SimpleArbConfig `json:"arbConfig,omitempty"`
MMCfg *MarketMakingConfig `json:"marketMakingConfig,omitempty"`
ArbMarketMakerCfg *ArbMarketMakerConfig `json:"arbMarketMakerConfig,omitempty"`
SimpleArbCfg *SimpleArbConfig `json:"simpleArbConfig,omitempty"`

Disabled bool `json:"disabled"`
}
Expand Down
20 changes: 16 additions & 4 deletions client/mm/mm.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,18 +838,30 @@ func (m *MarketMaker) Run(ctx context.Context, botCfgs []*BotConfig, cexCfgs []*
}
RunBasicMarketMaker(m.ctx, cfg, m.wrappedCoreForBot(mktID), oracle, baseFiatRate, quoteFiatRate, logger)
}(cfg)
case cfg.ArbCfg != nil:
case cfg.SimpleArbCfg != nil:
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))
cex, err := getConnectedCEX(cfg.ArbCfg.CEXName)
logger := m.log.SubLogger(fmt.Sprintf("SimpleArbitrage-%s-%d-%d", cfg.Host, cfg.BaseAsset, cfg.QuoteAsset))
cex, err := getConnectedCEX(cfg.SimpleArbCfg.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.ArbMarketMakerCfg != 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.ArbMarketMakerCfg.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 974ef4e

Please sign in to comment.