Skip to content

Commit

Permalink
xdepthmaker: simplify covered handler registration
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Dec 20, 2023
1 parent 58321e8 commit 3ba1621
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkg/strategy/xdepthmaker/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize(
// bbgo.Sync(ctx, s)
})

coveredFunc := func(trade types.Trade, profit, netProfit fixedpoint.Value) {
s.HedgeOrderExecutor.TradeCollector().OnTrade(func(trade types.Trade, profit, netProfit fixedpoint.Value) {
c := trade.PositionChange()

// sync covered position
Expand All @@ -133,15 +133,12 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize(
// buy trade -> positive delta ->
// 1) short position -> reduce short position
// 2) short position -> increase short position
if trade.Exchange == s.hedgeSession.ExchangeName {
// TODO: make this atomic
s.mu.Lock()
s.CoveredPosition = s.CoveredPosition.Add(c)
s.mu.Unlock()
}
}
s.MakerOrderExecutor.TradeCollector().OnTrade(coveredFunc)
s.HedgeOrderExecutor.TradeCollector().OnTrade(coveredFunc)

// TODO: make this atomic
s.mu.Lock()
s.CoveredPosition = s.CoveredPosition.Add(c)
s.mu.Unlock()
})
return nil
}

Expand Down

0 comments on commit 3ba1621

Please sign in to comment.