Skip to content

Commit

Permalink
Adaptor and bots -> dex.Connector
Browse files Browse the repository at this point in the history
  • Loading branch information
martonp committed May 9, 2024
1 parent a5a1537 commit 787758e
Show file tree
Hide file tree
Showing 22 changed files with 1,203 additions and 548 deletions.
2 changes: 1 addition & 1 deletion client/cmd/dexc-desktop/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func mainCore() error {
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(appCtx, clientCore, cfg.MMConfig.EventLogDBPath, cfg.BotConfigPath, logMaker.Logger("MM"))
marketMaker, err = mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexc-desktop/app_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func mainCore() error {
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(appCtx, clientCore, cfg.MMConfig.EventLogDBPath, cfg.MMConfig.BotConfigPath, logMaker.Logger("MM"))
marketMaker, err = mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.MMConfig.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/cmd/dexc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func runCore(cfg *app.Config) error {
if cfg.Experimental {
// TODO: on shutdown, stop market making and wait for trades to be
// canceled.
marketMaker, err = mm.NewMarketMaker(appCtx, clientCore, cfg.MMConfig.EventLogDBPath, cfg.MMConfig.BotConfigPath, logMaker.Logger("MM"))
marketMaker, err = mm.NewMarketMaker(clientCore, cfg.MMConfig.EventLogDBPath, cfg.MMConfig.BotConfigPath, logMaker.Logger("MM"))
if err != nil {
return fmt.Errorf("error creating market maker: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions client/mm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ type BotBalanceAllocation struct {
CEX map[uint32]uint64 `json:"cex"`
}

// BotBalanceDiffs is the amount of funds to add or remove from a bot's
// BotInventoryDiffs is the amount of funds to add or remove from a bot's
// allocation.
type BotBalanceDiffs struct {
type BotInventoryDiffs struct {
DEX map[uint32]int64 `json:"dex"`
CEX map[uint32]int64 `json:"cex"`
}

// balanceDiffsToAllocations converts a BotBalanceDiffs to a
// balanceDiffsToAllocations converts a BotInventoryDiffs to a
// BotBalanceAllocation by removing all negative diffs.
func balanceDiffsToAllocation(diffs *BotBalanceDiffs) *BotBalanceAllocation {
func balanceDiffsToAllocation(diffs *BotInventoryDiffs) *BotBalanceAllocation {
allocations := &BotBalanceAllocation{
DEX: make(map[uint32]uint64, len(diffs.DEX)),
CEX: make(map[uint32]uint64, len(diffs.CEX)),
Expand Down
23 changes: 8 additions & 15 deletions client/mm/event_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ type WithdrawalEvent struct {
CEXDebit uint64 `json:"cexDebit"`
}

// UpdateConfigEvent represents a change in the bot's configuration
// and/or inventory.
type UpdateConfigEvent struct {
// NewCfg may be nil if only the inventory was updated.
NewCfg *BotConfig `json:"newCfg,omitempty"`
InventoryMods map[uint32]int64 `json:"inventoryMods"`
}

// MarketMakingEvent represents an action that a market making bot takes.
type MarketMakingEvent struct {
ID uint64 `json:"id"`
Expand All @@ -68,11 +60,12 @@ type MarketMakingEvent struct {
Pending bool `json:"pending"`

// Only one of the following will be populated.
DEXOrderEvent *DEXOrderEvent `json:"dexOrderEvent,omitempty"`
CEXOrderEvent *CEXOrderEvent `json:"cexOrderEvent,omitempty"`
DepositEvent *DepositEvent `json:"depositEvent,omitempty"`
WithdrawalEvent *WithdrawalEvent `json:"withdrawalEvent,omitempty"`
UpdateConfig *UpdateConfigEvent `json:"updateConfig,omitempty"`
DEXOrderEvent *DEXOrderEvent `json:"dexOrderEvent,omitempty"`
CEXOrderEvent *CEXOrderEvent `json:"cexOrderEvent,omitempty"`
DepositEvent *DepositEvent `json:"depositEvent,omitempty"`
WithdrawalEvent *WithdrawalEvent `json:"withdrawalEvent,omitempty"`
UpdateConfig *BotConfig `json:"updateConfig,omitempty"`
UpdateInventory *map[uint32]int64 `json:"updateInventory,omitempty"`
}

// MarketMakingRun identifies a market making run.
Expand Down Expand Up @@ -227,8 +220,8 @@ func (db *boltEventLogDB) updateEvent(update *eventUpdate) {
return err
}

if update.e.UpdateConfig != nil && update.e.UpdateConfig.NewCfg != nil {
if err := db.storeCfgUpdate(runBucket, update.e.UpdateConfig.NewCfg, update.e.TimeStamp); err != nil {
if update.e.UpdateConfig != nil {
if err := db.storeCfgUpdate(runBucket, update.e.UpdateConfig, update.e.TimeStamp); err != nil {
return err
}
}
Expand Down
12 changes: 3 additions & 9 deletions client/mm/event_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,9 @@ func TestEventLogDB(t *testing.T) {
inventoryMods[42] = 1e6
inventoryMods[60] = -2e6
updateCfgEvent := &MarketMakingEvent{
ID: 3,
TimeStamp: startTime + 2,
UpdateConfig: &UpdateConfigEvent{
NewCfg: updatedCfg,
InventoryMods: map[uint32]int64{
42: 1e6,
60: -2e6,
},
},
ID: 3,
TimeStamp: startTime + 2,
UpdateConfig: updatedCfg,
}
db.storeEvent(startTime, mkt, updateCfgEvent, currBalanceState())

Expand Down

0 comments on commit 787758e

Please sign in to comment.