From be674278b2a0f56bfa83e473f42ee37c66b120bf Mon Sep 17 00:00:00 2001 From: kbearXD Date: Wed, 22 May 2024 18:20:18 +0800 Subject: [PATCH] FEATURE: [dca2] new flag UniversalCancelAllOrdersWhenClose to decide if cancel all orders when closing --- pkg/strategy/dca2/strategy.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/strategy/dca2/strategy.go b/pkg/strategy/dca2/strategy.go index cc403057b..02a029887 100644 --- a/pkg/strategy/dca2/strategy.go +++ b/pkg/strategy/dca2/strategy.go @@ -76,8 +76,8 @@ type Strategy struct { // KeepOrdersWhenShutdown option is used for keeping the grid orders when shutting down bbgo KeepOrdersWhenShutdown bool `json:"keepOrdersWhenShutdown"` - // UseCancelAllOrdersApiWhenClose uses a different API to cancel all the orders on the market when closing a grid - UseCancelAllOrdersApiWhenClose bool `json:"useCancelAllOrdersApiWhenClose"` + // UniversalCancelAllOrdersWhenClose close all orders even though the orders don't belong to this strategy + UniversalCancelAllOrdersWhenClose bool `json:"universalCancelAllOrdersWhenClose"` // log logger *logrus.Entry @@ -372,9 +372,15 @@ func (s *Strategy) Close(ctx context.Context) error { defer s.EmitClosed() - err := s.OrderExecutor.GracefulCancel(ctx) + var err error + if s.UniversalCancelAllOrdersWhenClose { + err = tradingutil.UniversalCancelAllOrders(ctx, s.ExchangeSession.Exchange, nil) + } else { + err = s.OrderExecutor.GracefulCancel(ctx) + } + if err != nil { - s.logger.WithError(err).Errorf("there are errors when cancelling orders at close") + s.logger.WithError(err).Errorf("there are errors when cancelling orders when closing (UniversalCancelAllOrdersWhenClose = %t)", s.UniversalCancelAllOrdersWhenClose) } bbgo.Sync(ctx, s)