mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
exchange/retry: add QueryOrderUntilCancelled
This commit is contained in:
parent
c2c1eca4c9
commit
96f6f9e0d0
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user