From 329b8a40d9c004b30c7d6024c0655ed01dc430c9 Mon Sep 17 00:00:00 2001 From: c9s Date: Wed, 25 Sep 2024 13:36:31 +0800 Subject: [PATCH] xdepthmaker: adjust covered position when order is canceled --- pkg/strategy/xdepthmaker/strategy.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/strategy/xdepthmaker/strategy.go b/pkg/strategy/xdepthmaker/strategy.go index d959a5c93..6f2f3fe85 100644 --- a/pkg/strategy/xdepthmaker/strategy.go +++ b/pkg/strategy/xdepthmaker/strategy.go @@ -148,6 +148,16 @@ func (s *CrossExchangeMarketMakingStrategy) Initialize( // 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) { c := trade.PositionChange()