Skip to content

Commit

Permalink
tradingutil: return anyErr if anyErr is not nil
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Feb 23, 2024
1 parent 3b8a3be commit 0b0bc7e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/util/tradingutil/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func UniversalCancelAllOrders(ctx context.Context, exchange types.Exchange, open
return errors.New("to cancel all orders, openOrders can not be empty")
}

var anyErr error
if service, ok := exchange.(CancelAllOrdersBySymbolService); ok {
var symbols = CollectOrderSymbols(openOrders)
var anyErr error
for _, symbol := range symbols {
_, err := service.CancelOrdersBySymbol(ctx, symbol)
if err != nil {
Expand All @@ -58,7 +58,6 @@ func UniversalCancelAllOrders(ctx context.Context, exchange types.Exchange, open

if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok {
var groupIds = CollectOrderGroupIds(openOrders)
var anyErr error
for _, groupId := range groupIds {
if _, err := service.CancelOrdersByGroupID(ctx, groupId); err != nil {
anyErr = err
Expand All @@ -70,7 +69,11 @@ func UniversalCancelAllOrders(ctx context.Context, exchange types.Exchange, open
}
}

return fmt.Errorf("unable to cancel all orders: %+v", openOrders)
if anyErr != nil {
return anyErr
}

return fmt.Errorf("unable to cancel all orders, openOrders:%+v", openOrders)
}

func CollectOrderGroupIds(orders []types.Order) (groupIds []uint32) {
Expand Down

0 comments on commit 0b0bc7e

Please sign in to comment.