Skip to content

Commit

Permalink
Merge pull request #1641 from c9s/kbearXD/dca2/univeral-cancel-orders…
Browse files Browse the repository at this point in the history
…-flag

FEATURE: [dca2] new flag UniversalCancelAllOrdersWhenClose to decide …
  • Loading branch information
kbearXD authored May 23, 2024
2 parents 5f1ece2 + be67427 commit d4848f4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/strategy/dca2/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d4848f4

Please sign in to comment.