diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index 5a9a06cb6..6044e37d9 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -349,6 +349,9 @@ func (s *Strategy) processFilledOrder(o types.Order) { s.logger.Infof("GENERATED GRID PROFIT: %+v", profit) s.GridProfitStats.AddProfit(profit) + bbgo.Notify(profit) + bbgo.Notify(s.GridProfitStats) + case types.SideTypeBuy: newSide = types.SideTypeSell if !s.ProfitSpread.IsZero() { @@ -652,6 +655,13 @@ func (s *Strategy) newTriggerPriceHandler(ctx context.Context, session *bbgo.Exc }) } +func (s *Strategy) newOrderUpdateHandler(ctx context.Context, session *bbgo.ExchangeSession) func(o types.Order) { + return func(o types.Order) { + s.handleOrderFilled(o) + bbgo.Sync(ctx, s) + } +} + func (s *Strategy) newStopLossPriceHandler(ctx context.Context, session *bbgo.ExchangeSession) types.KLineCallback { return types.KLineWith(s.Symbol, types.Interval1m, func(k types.KLine) { if s.StopLossPrice.Compare(k.Low) < 0 { @@ -1034,10 +1044,7 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. orderExecutor.TradeCollector().OnPositionUpdate(func(position *types.Position) { bbgo.Sync(ctx, s) }) - orderExecutor.ActiveMakerOrders().OnFilled(func(o types.Order) { - s.handleOrderFilled(o) - bbgo.Sync(context.Background(), s) - }) + orderExecutor.ActiveMakerOrders().OnFilled(s.newOrderUpdateHandler(ctx, session)) s.orderExecutor = orderExecutor