diff --git a/pkg/exchange/retry/order.go b/pkg/exchange/retry/order.go index 66a690a54..f06f682c3 100644 --- a/pkg/exchange/retry/order.go +++ b/pkg/exchange/retry/order.go @@ -3,6 +3,7 @@ package retry import ( "context" "errors" + "fmt" "strconv" "github.com/cenkalti/backoff/v4" @@ -16,6 +17,34 @@ type advancedOrderCancelService interface { CancelOrdersByGroupID(ctx context.Context, groupID uint32) ([]types.Order, error) } +func QueryOrderUntilCanceled( + ctx context.Context, queryOrderService types.ExchangeOrderQueryService, symbol string, orderId uint64, +) (o *types.Order, err error) { + var op = func() (err2 error) { + o, err2 = queryOrderService.QueryOrder(ctx, types.OrderQuery{ + Symbol: symbol, + OrderID: strconv.FormatUint(orderId, 10), + }) + + if err2 != nil { + return err2 + } + + if o == nil { + return fmt.Errorf("order #%d response is nil", orderId) + } + + if o.Status == types.OrderStatusCanceled || o.Status == types.OrderStatusFilled { + return nil + } + + return fmt.Errorf("order #%d is not canceled yet: %s", o.OrderID, o.Status) + } + + err = GeneralBackoff(ctx, op) + return o, err +} + func QueryOrderUntilFilled( ctx context.Context, queryOrderService types.ExchangeOrderQueryService, symbol string, orderId uint64, ) (o *types.Order, err error) {