grid2: pull out backoff cancel all to cancelAllOrdersUntilSuccessful

This commit is contained in:
c9s 2023-03-16 18:01:56 +08:00
parent 57e3f46c5c
commit 0b922a929e
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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...)