mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-13 02:23:51 +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)
|
// 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()
|
c := trade.PositionChange()
|
||||||
|
|
||||||
// sync covered position
|
// sync covered position
|
||||||
|
@ -133,15 +133,12 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize(
|
||||||
// buy trade -> positive delta ->
|
// buy trade -> positive delta ->
|
||||||
// 1) short position -> reduce short position
|
// 1) short position -> reduce short position
|
||||||
// 2) short position -> increase short position
|
// 2) short position -> increase short position
|
||||||
if trade.Exchange == s.hedgeSession.ExchangeName {
|
|
||||||
// TODO: make this atomic
|
// TODO: make this atomic
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
s.CoveredPosition = s.CoveredPosition.Add(c)
|
s.CoveredPosition = s.CoveredPosition.Add(c)
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
}
|
})
|
||||||
}
|
|
||||||
s.MakerOrderExecutor.TradeCollector().OnTrade(coveredFunc)
|
|
||||||
s.HedgeOrderExecutor.TradeCollector().OnTrade(coveredFunc)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user