From b595119896cea8e87e97ca347d5ba898ca2c3924 Mon Sep 17 00:00:00 2001 From: Victor Lee Date: Fri, 22 Nov 2024 10:31:08 -0800 Subject: [PATCH] check for order cancellation failure (#855) --- .../API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs b/src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs index 857c74a3..f18757be 100644 --- a/src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs @@ -460,7 +460,7 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd } catch (Exception ex) // All fails come back with an exception. { - Logger.Error(ex, "Failed to place coinbase error"); + Logger.Error(ex, "Failed to place coinbase order"); var token = JToken.Parse(ex.Message); return new ExchangeOrderResult(){ Result = ExchangeAPIOrderResult.Rejected, @@ -479,9 +479,14 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd protected override async Task OnCancelOrderAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - Dictionary payload = new Dictionary() {{ "order_ids", new [] { orderId } } }; - await MakeJsonRequestAsync("/orders/batch_cancel", payload: payload, requestMethod: "POST"); - } + Dictionary payload = new Dictionary() {{ "order_ids", new [] { orderId } } }; + var responseJObj = await MakeJsonRequestAsync("/orders/batch_cancel", payload: payload, requestMethod: "POST"); + if (responseJObj["results"][0].Value("success") != true) + { + Logger.Error("Failed to cancel coinbase order. {0}", responseJObj["results"][0].Value("failure_reason")); + throw new APIException("Failed to cancel coinbase order. " + responseJObj["results"][0].Value("failure_reason")); + } + } protected override Task OnWithdrawAsync(ExchangeWithdrawalRequest withdrawalRequest) {