mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1314 from c9s/feature/grid2/use-retry-until-successful
This commit is contained in:
commit
f2cb458c7b
|
@ -57,6 +57,16 @@ func QueryOpenOrdersUntilSuccessful(ctx context.Context, ex types.Exchange, symb
|
|||
return openOrders, err
|
||||
}
|
||||
|
||||
func QueryOrderUntilSuccessful(ctx context.Context, query types.ExchangeOrderQueryService, opts types.OrderQuery) (order *types.Order, err error) {
|
||||
var op = func() (err2 error) {
|
||||
order, err2 = query.QueryOrder(ctx, opts)
|
||||
return err2
|
||||
}
|
||||
|
||||
err = GeneralBackoff(ctx, op)
|
||||
return order, err
|
||||
}
|
||||
|
||||
func CancelAllOrdersUntilSuccessful(ctx context.Context, service advancedOrderCancelService) error {
|
||||
var op = func() (err2 error) {
|
||||
_, err2 = service.CancelAllOrders(ctx)
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/bbgo"
|
||||
"github.com/c9s/bbgo/pkg/exchange/retry"
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/types"
|
||||
)
|
||||
|
@ -290,12 +291,13 @@ func (s *Strategy) queryTradesToUpdateTwinOrdersMap(ctx context.Context, queryTr
|
|||
// already queries, skip
|
||||
continue
|
||||
}
|
||||
order, err := queryOrderService.QueryOrder(ctx, types.OrderQuery{
|
||||
order, err := retry.QueryOrderUntilSuccessful(ctx, queryOrderService, types.OrderQuery{
|
||||
Symbol: trade.Symbol,
|
||||
OrderID: strconv.FormatUint(trade.OrderID, 10),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to query order by trade")
|
||||
return errors.Wrapf(err, "failed to query order by trade (trade id: %d, order id: %d)", trade.ID, trade.OrderID)
|
||||
}
|
||||
|
||||
s.debugLog(order.String())
|
||||
|
|
|
@ -2159,14 +2159,9 @@ func (s *Strategy) recoverActiveOrders(ctx context.Context, session *bbgo.Exchan
|
|||
for _, o := range activeOrders {
|
||||
s.logger.Infof("updating %d order...", o.OrderID)
|
||||
|
||||
var updatedOrder *types.Order
|
||||
err := retry.GeneralBackoff(ctx, func() error {
|
||||
var err error
|
||||
updatedOrder, err = s.orderQueryService.QueryOrder(ctx, types.OrderQuery{
|
||||
Symbol: o.Symbol,
|
||||
OrderID: strconv.FormatUint(o.OrderID, 10),
|
||||
})
|
||||
return err
|
||||
updatedOrder, err := retry.QueryOrderUntilSuccessful(ctx, s.orderQueryService, types.OrderQuery{
|
||||
Symbol: o.Symbol,
|
||||
OrderID: strconv.FormatUint(o.OrderID, 10),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue
Block a user