Skip to content

Commit

Permalink
Merge pull request #1555 from c9s/edwin/bbgo/fix-order
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s authored Mar 5, 2024
2 parents 9c85a5c + 751f82b commit 43cf40c
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pkg/bbgo/activeorderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -260,8 +256,11 @@ func (b *ActiveOrderBook) GracefulCancel(ctx context.Context, ex types.Exchange,
}
}

// update order slice for the next try
orders = leftOrders
// 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))
Expand Down

0 comments on commit 43cf40c

Please sign in to comment.