Skip to content

Commit 43cf40c

Browse files
authored
Merge pull request #1555 from c9s/edwin/bbgo/fix-order
2 parents 9c85a5c + 751f82b commit 43cf40c

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pkg/bbgo/activeorderbook.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,14 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
234234
log.Warnf("[ActiveOrderBook] using open orders API to verify the active orders...")
235235

236236
var symbolOrdersMap = categorizeOrderBySymbol(orders)
237-
237+
var errOccurred bool
238238
var leftOrders types.OrderSlice
239-
for symbol := range symbolOrdersMap {
240-
symbolOrders, ok := symbolOrdersMap[symbol]
241-
if !ok {
242-
continue
243-
}
244-
239+
for symbol, symbolOrders := range symbolOrdersMap {
245240
openOrders, err := ex.QueryOpenOrders(ctx, symbol)
246241
if err != nil {
242+
errOccurred = true
247243
log.WithError(err).Errorf("can not query %s open orders", symbol)
248-
continue
244+
break
249245
}
250246

251247
openOrderMap := types.NewOrderMap(openOrders...)
@@ -260,8 +256,11 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
260256
}
261257
}
262258

263-
// update order slice for the next try
264-
orders = leftOrders
259+
// if an error occurs, we cannot update the orders because it will result in an empty order slice.
260+
if !errOccurred {
261+
// update order slice for the next try
262+
orders = leftOrders
263+
}
265264
}
266265

267266
log.Debugf("[ActiveOrderBook] all %s orders are cancelled successfully in %s", b.Symbol, time.Since(startTime))

0 commit comments

Comments
 (0)