Skip to content

Commit 65e9bef

Browse files
authored
added checks during cancel Order (#683)
- check to make sure the correct order is being cancelled on Binance and Coinbase - pass through OrderRejectReason in Binance UserDataStream
1 parent 3a0acb2 commit 65e9bef

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,14 @@ protected override async Task OnCancelOrderAsync(string orderId, string? marketS
724724
Dictionary<string, object> payload = await GetNoncePayloadAsync();
725725
if (string.IsNullOrWhiteSpace(marketSymbol))
726726
{
727-
throw new InvalidOperationException("Binance cancel order request requires symbol");
727+
throw new ArgumentNullException("Binance cancel order request requires symbol");
728728
}
729729
payload["symbol"] = marketSymbol!;
730730
payload["orderId"] = orderId;
731-
_ = await MakeJsonRequestAsync<JToken>("/order", BaseUrlApi, payload, "DELETE");
731+
var token = await MakeJsonRequestAsync<JToken>("/order", BaseUrlApi, payload, "DELETE");
732+
var cancelledOrder = ParseOrder(token);
733+
if (cancelledOrder.OrderId != orderId)
734+
throw new APIException($"Cancelled {cancelledOrder.OrderId} when trying to cancel {orderId}");
732735
}
733736

734737
/// <summary>A withdrawal request. Fee is automatically subtracted from the amount.</summary>

src/ExchangeSharp/API/Exchanges/BinanceGroup/Models/UserDataStream.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public ExchangeOrderResult ExchangeOrderResult
8787
ClientOrderId = ClientOrderId,
8888
Result = status,
8989
ResultCode = CurrentOrderStatus,
90-
Message = null, // can use for something in the future if needed
90+
Message = OrderRejectReason, // can use for multiple things in the future if needed
9191
Amount = CumulativeFilledQuantity,
9292
Price = OrderPrice,
9393
AveragePrice = CumulativeQuoteAssetTransactedQuantity / CumulativeFilledQuantity, // Average price can be found by doing Z divided by z.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,9 @@ private async Task MakeFillRequest(DateTime? afterDate, string productId, List<E
786786

787787
protected override async Task OnCancelOrderAsync(string orderId, string marketSymbol = null)
788788
{
789-
await MakeJsonRequestAsync<JArray>("orders/" + orderId, null, await GetNoncePayloadAsync(), "DELETE");
789+
var jToken = await MakeJsonRequestAsync<JToken>("orders/" + orderId, null, await GetNoncePayloadAsync(), "DELETE");
790+
if (jToken.ToStringInvariant() != orderId)
791+
throw new APIException($"Cancelled {jToken.ToStringInvariant()} when trying to cancel {orderId}");
790792
}
791793
}
792794

0 commit comments

Comments
 (0)