From 0b922a929eb972d8f4df3f88a39454527a06b5c8 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 16 Mar 2023 18:01:56 +0800 Subject: [PATCH] grid2: pull out backoff cancel all to cancelAllOrdersUntilSuccessful --- pkg/strategy/grid2/strategy.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/strategy/grid2/strategy.go b/pkg/strategy/grid2/strategy.go index e4e9a0026..89d267b60 100644 --- a/pkg/strategy/grid2/strategy.go +++ b/pkg/strategy/grid2/strategy.go @@ -922,12 +922,7 @@ func (s *Strategy) cancelAll(ctx context.Context) error { s.logger.Infof("found %d open orders left, using cancel all orders api", len(openOrders)) s.logger.Infof("using cancal all orders api for canceling grid orders...") - op := func() error { - _, cancelErr := service.CancelAllOrders(ctx) - return cancelErr - } - - if err := backoff.Retry(op, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 101)); err != nil { + if err := cancelAllOrdersUntilSuccessful(ctx, service); err != nil { s.logger.WithError(err).Errorf("CancelAllOrders api call error") werr = multierr.Append(werr, err) } @@ -2321,6 +2316,15 @@ func generalBackoff(ctx context.Context, op backoff.Operation) (err error) { return err } +func cancelAllOrdersUntilSuccessful(ctx context.Context, service advancedOrderCancelApi) error { + var op = func() (err2 error) { + _, err2 = service.CancelAllOrders(ctx) + return err2 + } + + return generalBackoff(ctx, op) +} + func cancelOrdersUntilSuccessful(ctx context.Context, ex types.Exchange, orders ...types.Order) error { var op = func() (err2 error) { err2 = ex.CancelOrders(ctx, orders...)