Skip to content

Commit b595119

Browse files
authored
check for order cancellation failure (#855)
1 parent 67c7301 commit b595119

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
460460
}
461461
catch (Exception ex) // All fails come back with an exception.
462462
{
463-
Logger.Error(ex, "Failed to place coinbase error");
463+
Logger.Error(ex, "Failed to place coinbase order");
464464
var token = JToken.Parse(ex.Message);
465465
return new ExchangeOrderResult(){
466466
Result = ExchangeAPIOrderResult.Rejected,
@@ -479,9 +479,14 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd
479479

480480
protected override async Task OnCancelOrderAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false)
481481
{
482-
Dictionary<string, object> payload = new Dictionary<string, object>() {{ "order_ids", new [] { orderId } } };
483-
await MakeJsonRequestAsync<JArray>("/orders/batch_cancel", payload: payload, requestMethod: "POST");
484-
}
482+
Dictionary<string, object> payload = new Dictionary<string, object>() {{ "order_ids", new [] { orderId } } };
483+
var responseJObj = await MakeJsonRequestAsync<JObject>("/orders/batch_cancel", payload: payload, requestMethod: "POST");
484+
if (responseJObj["results"][0].Value<bool>("success") != true)
485+
{
486+
Logger.Error("Failed to cancel coinbase order. {0}", responseJObj["results"][0].Value<string>("failure_reason"));
487+
throw new APIException("Failed to cancel coinbase order. " + responseJObj["results"][0].Value<string>("failure_reason"));
488+
}
489+
}
485490

486491
protected override Task<ExchangeWithdrawalResponse> OnWithdrawAsync(ExchangeWithdrawalRequest withdrawalRequest)
487492
{

0 commit comments

Comments
 (0)