xdepthmaker: adjust covered position when order is canceled

This commit is contained in:
c9s 2024-09-25 13:36:31 +08:00
parent 60d5126b61
commit 329b8a40d9
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -148,6 +148,16 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize(
// bbgo.Sync(ctx, s) // bbgo.Sync(ctx, s)
}) })
s.HedgeOrderExecutor.ActiveMakerOrders().OnCanceled(func(o types.Order) {
remaining := o.Quantity.Sub(o.ExecutedQuantity)
switch o.Side {
case types.SideTypeSell:
remaining = remaining.Neg()
}
s.CoveredPosition.Sub(remaining)
})
s.HedgeOrderExecutor.TradeCollector().OnTrade(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()