Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: [dca2] new flag UniversalCancelAllOrdersWhenClose to decide … #1641

Merged
merged 1 commit into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading