pkg/bbgo: use origin order if error occurred

This commit is contained in:
edwin 2024-03-05 09:39:10 +08:00
parent a392d8d579
commit 751f82bc56

View File

@ -234,18 +234,14 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
log.Warnf("[ActiveOrderBook] using open orders API to verify the active orders...")
var symbolOrdersMap = categorizeOrderBySymbol(orders)
var errOccurred bool
var leftOrders types.OrderSlice
for symbol := range symbolOrdersMap {
symbolOrders, ok := symbolOrdersMap[symbol]
if !ok {
continue
}
for symbol, symbolOrders := range symbolOrdersMap {
openOrders, err := ex.QueryOpenOrders(ctx, symbol)
if err != nil {
errOccurred = true
log.WithError(err).Errorf("can not query %s open orders", symbol)
continue
break
}
openOrderMap := types.NewOrderMap(openOrders...)
@ -260,9 +256,12 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
}
}
// if an error occurs, we cannot update the orders because it will result in an empty order slice.
if !errOccurred {
// update order slice for the next try
orders = leftOrders
}
}
log.Debugf("[ActiveOrderBook] all %s orders are cancelled successfully in %s", b.Symbol, time.Since(startTime))
return nil