exchange/retry: add QueryOrderUntilCancelled

This commit is contained in:
c9s 2023-11-30 17:09:25 +08:00
parent c2c1eca4c9
commit 96f6f9e0d0
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

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