From a3c16a41176efa2606bdbd0042af528968041298 Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 20 Jul 2023 12:44:57 +0800 Subject: [PATCH] bbgo: use backoff for graceful cancel --- pkg/bbgo/order_executor_general.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/bbgo/order_executor_general.go b/pkg/bbgo/order_executor_general.go index 6c95b6495..2e6601b3b 100644 --- a/pkg/bbgo/order_executor_general.go +++ b/pkg/bbgo/order_executor_general.go @@ -15,6 +15,7 @@ import ( "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" "github.com/c9s/bbgo/pkg/util" + "github.com/c9s/bbgo/pkg/util/backoff" ) var ErrExceededSubmitOrderRetryLimit = errors.New("exceeded submit order retry limit") @@ -429,15 +430,10 @@ func (e *GeneralOrderExecutor) GracefulCancelActiveOrderBook(ctx context.Context return nil } - if err := activeOrders.GracefulCancel(ctx, e.session.Exchange); err != nil { - // Retry once - if err = activeOrders.GracefulCancel(ctx, e.session.Exchange); err != nil { - return errors.Wrap(err, "graceful cancel error") - } - } + defer e.tradeCollector.Process() - e.tradeCollector.Process() - return nil + op := func() error { return activeOrders.GracefulCancel(ctx, e.session.Exchange) } + return backoff.RetryGeneral(ctx, op) } // GracefulCancel cancels all active maker orders if orders are not given, otherwise cancel all the given orders