mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
xdepthmaker: simplify covered handler registration
This commit is contained in:
parent
58321e8aa5
commit
3ba1621590
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user