From 2d45b5cb761164289b76f8ef108377343e36bb19 Mon Sep 17 00:00:00 2001 From: kbearXD Date: Thu, 11 Apr 2024 11:40:19 +0800 Subject: [PATCH] FIX: fix dca2 panic problem --- pkg/strategy/dca2/active_order_recover.go | 9 +++++---- pkg/strategy/dca2/strategy.go | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/strategy/dca2/active_order_recover.go b/pkg/strategy/dca2/active_order_recover.go index 9c27b6acb..1c7f814b7 100644 --- a/pkg/strategy/dca2/active_order_recover.go +++ b/pkg/strategy/dca2/active_order_recover.go @@ -52,10 +52,11 @@ func (s *Strategy) recoverActiveOrders(ctx context.Context) error { } opts := common.SyncActiveOrdersOpts{ - Logger: s.logger, - Exchange: s.ExchangeSession.Exchange, - ActiveOrderBook: activeOrders, - OpenOrders: openOrders, + Logger: s.logger, + Exchange: s.ExchangeSession.Exchange, + OrderQueryService: s.orderQueryService, + ActiveOrderBook: activeOrders, + OpenOrders: openOrders, } return common.SyncActiveOrders(ctx, opts) diff --git a/pkg/strategy/dca2/strategy.go b/pkg/strategy/dca2/strategy.go index d8ed33350..348cddb6c 100644 --- a/pkg/strategy/dca2/strategy.go +++ b/pkg/strategy/dca2/strategy.go @@ -94,6 +94,7 @@ type Strategy struct { nextStateC chan State state State roundCollector *RoundCollector + orderQueryService types.ExchangeOrderQueryService takeProfitPrice fixedpoint.Value startTimeOfNextRound time.Time nextRoundPaused bool @@ -193,6 +194,13 @@ func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo. s.OrderGroupID = util.FNV32(instanceID) % math.MaxInt32 } + // orderQueryService + if service, ok := s.ExchangeSession.Exchange.(types.ExchangeOrderQueryService); ok { + s.orderQueryService = service + } else { + return fmt.Errorf("exchange %s doesn't support ExchangeOrderQueryService", s.ExchangeSession.ExchangeName) + } + // round collector s.roundCollector = NewRoundCollector(s.logger, s.Symbol, s.OrderGroupID, s.ExchangeSession.Exchange) if s.roundCollector == nil {