tradingutil: return anyErr if anyErr is not nil

This commit is contained in:
c9s 2024-02-23 18:33:30 +08:00
parent 3b8a3bed5f
commit 0b0bc7e179
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -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") return errors.New("to cancel all orders, openOrders can not be empty")
} }
var anyErr error
if service, ok := exchange.(CancelAllOrdersBySymbolService); ok { if service, ok := exchange.(CancelAllOrdersBySymbolService); ok {
var symbols = CollectOrderSymbols(openOrders) var symbols = CollectOrderSymbols(openOrders)
var anyErr error
for _, symbol := range symbols { for _, symbol := range symbols {
_, err := service.CancelOrdersBySymbol(ctx, symbol) _, err := service.CancelOrdersBySymbol(ctx, symbol)
if err != nil { if err != nil {
@ -58,7 +58,6 @@ func UniversalCancelAllOrders(ctx context.Context, exchange types.Exchange, open
if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok { if service, ok := exchange.(CancelAllOrdersByGroupIDService); ok {
var groupIds = CollectOrderGroupIds(openOrders) var groupIds = CollectOrderGroupIds(openOrders)
var anyErr error
for _, groupId := range groupIds { for _, groupId := range groupIds {
if _, err := service.CancelOrdersByGroupID(ctx, groupId); err != nil { if _, err := service.CancelOrdersByGroupID(ctx, groupId); err != nil {
anyErr = err anyErr = err
@ -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) { func CollectOrderGroupIds(orders []types.Order) (groupIds []uint32) {