Merge pull request #1314 from c9s/feature/grid2/use-retry-until-successful

This commit is contained in:
c9s 2023-09-19 14:55:20 +08:00 committed by GitHub
commit f2cb458c7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 10 deletions

View File

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

View File

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

View File

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