From 0044c1bfb9f7efc8279818eabcaed339dfdf0957 Mon Sep 17 00:00:00 2001 From: Victor Lee Date: Sat, 12 Feb 2022 14:49:44 -0800 Subject: [PATCH] standardize exception types - use NotImplementedException, InvalidOperationException, NotSupportedException, ArgumentException, ArgumentNullException when appropriate - opens up room in the future to create more specific exceptions derived from above exceptions --- src/ExchangeSharp/API/Common/BaseAPI.cs | 2 +- .../API/Exchanges/Aquanow/ExchangeAquanowAPI.cs | 4 ++-- .../API/Exchanges/BL3P/ExchangeBL3PAPI.cs | 4 ++-- .../Exchanges/BinanceGroup/BinanceGroupCommon.cs | 4 ++-- .../API/Exchanges/BitBank/ExchangeBitBankAPI.cs | 8 ++++---- .../Exchanges/Bitfinex/ExchangeBitfinexAPI.cs | 2 +- .../Exchanges/Bitstamp/ExchangeBitstampAPI.cs | 2 +- .../API/Exchanges/Bittrex/ExchangeBittrexAPI.cs | 2 +- .../API/Exchanges/Bybit/ExchangeBybitAPI.cs | 2 +- .../Exchanges/Coinbase/ExchangeCoinbaseAPI.cs | 5 ++++- .../Exchanges/Coinmate/ExchangeCoinmateAPI.cs | 4 ++-- .../Exchanges/Digifinex/ExchangeDigifinexAPI.cs | 2 +- .../API/Exchanges/FTX/FTXGroupCommon.cs | 2 +- .../API/Exchanges/GateIo/ExchangeGateIoAPI.cs | 16 ++++++++-------- .../API/Exchanges/Hitbtc/ExchangeHitbtcAPI.cs | 2 +- .../API/Exchanges/Kraken/ExchangeKrakenAPI.cs | 5 ++--- .../API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs | 11 ++++------- .../API/Exchanges/LBank/ExchangeLBankAPI.cs | 4 ++-- .../Exchanges/Livecoin/ExchangeLivecoinAPI.cs | 4 ++-- .../API/Exchanges/NDAX/ExchangeNDAXAPI.cs | 4 ++-- .../API/Exchanges/OKGroup/OKGroupCommon.cs | 4 ++-- .../Exchanges/Poloniex/ExchangePoloniexAPI.cs | 2 +- .../API/Exchanges/Yobit/ExchangeYobitAPI.cs | 4 ++-- .../API/Exchanges/_Base/ExchangeAPI.cs | 8 ++++---- 24 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/ExchangeSharp/API/Common/BaseAPI.cs b/src/ExchangeSharp/API/Common/BaseAPI.cs index f1112367..58e3e4c6 100644 --- a/src/ExchangeSharp/API/Common/BaseAPI.cs +++ b/src/ExchangeSharp/API/Common/BaseAPI.cs @@ -418,7 +418,7 @@ public async Task GenerateNonceAsync() break; default: - throw new InvalidOperationException("Invalid nonce style: " + NonceStyle); + throw new NotImplementedException("Invalid nonce style: " + NonceStyle); } // check for duplicate nonce diff --git a/src/ExchangeSharp/API/Exchanges/Aquanow/ExchangeAquanowAPI.cs b/src/ExchangeSharp/API/Exchanges/Aquanow/ExchangeAquanowAPI.cs index ee3571a9..ebf39afe 100644 --- a/src/ExchangeSharp/API/Exchanges/Aquanow/ExchangeAquanowAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Aquanow/ExchangeAquanowAPI.cs @@ -105,7 +105,7 @@ protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dicti // DONE protected override async Task OnPlaceOrderAsync(ExchangeOrderRequest order) { - if (order.IsPostOnly != null) throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); + if (order.IsPostOnly != null) throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); // In Aquanow market order, when buying crypto the amount of crypto that is bought is the receiveQuantity // and when selling the amount of crypto that is sold is the deliverQuantity string amountParameter = order.IsBuy ? "receiveQuantity" : "deliverQuantity"; @@ -201,7 +201,7 @@ protected override async Task OnGetOrderDetailsAsync(string { return null; } - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); var payload = await GetNoncePayloadAsync(); JToken result = await MakeJsonRequestAsync($"/trades/v1/order?orderId={orderId}", null, payload, "GET"); bool isBuy = result["tradeSide"].ToStringInvariant() == "buy" ? true : false; diff --git a/src/ExchangeSharp/API/Exchanges/BL3P/ExchangeBL3PAPI.cs b/src/ExchangeSharp/API/Exchanges/BL3P/ExchangeBL3PAPI.cs index ea54efd1..33f41a1a 100644 --- a/src/ExchangeSharp/API/Exchanges/BL3P/ExchangeBL3PAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/BL3P/ExchangeBL3PAPI.cs @@ -233,7 +233,7 @@ private string GetSignKey(IHttpWebRequest request, string formData) protected override async Task OnPlaceOrderAsync(ExchangeOrderRequest order) { - if (order.IsPostOnly != null) throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); + if (order.IsPostOnly != null) throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); var roundedAmount = order.RoundAmount(); var amountInt = converterToEight.FromDecimal(roundedAmount); @@ -314,7 +314,7 @@ protected override async Task OnGetOrderDetailsAsync(string { if (string.IsNullOrWhiteSpace(marketSymbol)) throw new ArgumentException("Value cannot be null or whitespace.", nameof(marketSymbol)); - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); var data = new Dictionary { diff --git a/src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs b/src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs index b3b6bfa9..f87dbcdc 100644 --- a/src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs +++ b/src/ExchangeSharp/API/Exchanges/BinanceGroup/BinanceGroupCommon.cs @@ -554,7 +554,7 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd else if (order.IsPostOnly == true) { if (order.OrderType == OrderType.Limit) payload["type"] = "LIMIT_MAKER"; // LIMIT_MAKER are LIMIT orders that will be rejected if they would immediately match and trade as a taker. - else throw new NotImplementedException("PostOnly with non limit orders are not currently supported on Binance. Please submit a PR if you are interested in this feature"); + else throw new NotSupportedException("PostOnly with non limit orders are not currently supported on Binance. Please submit a PR if you are interested in this feature"); } else payload["type"] = order.OrderType.ToStringUpperInvariant(); @@ -587,7 +587,7 @@ protected override async Task OnGetOrderDetailsAsync(string Dictionary payload = await GetNoncePayloadAsync(); if (string.IsNullOrWhiteSpace(marketSymbol)) { - throw new InvalidOperationException("Binance single order details request requires symbol"); + throw new ArgumentNullException("Binance single order details request requires symbol"); } payload["symbol"] = marketSymbol!; diff --git a/src/ExchangeSharp/API/Exchanges/BitBank/ExchangeBitBankAPI.cs b/src/ExchangeSharp/API/Exchanges/BitBank/ExchangeBitBankAPI.cs index bd0091c6..d6fb2da1 100644 --- a/src/ExchangeSharp/API/Exchanges/BitBank/ExchangeBitBankAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/BitBank/ExchangeBitBankAPI.cs @@ -128,7 +128,7 @@ protected override Task OnGetHistoricalTradesAsync(Func OnPlaceOrderAsync(ExchangeOrderRequest order) { if (order.OrderType == OrderType.Stop) - throw new InvalidOperationException("Bitbank does not support stop order"); + throw new NotSupportedException("Bitbank does not support stop order"); Dictionary payload = await GetNoncePayloadAsync(); if (order.IsPostOnly != null) payload["post_only"] = order.IsPostOnly; @@ -154,11 +154,11 @@ protected override async Task OnCancelOrderAsync(string orderId, string marketSy protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); var payload = await GetNoncePayloadAsync(); payload.Add("order_id", orderId); - if (marketSymbol == null) - throw new InvalidOperationException($"BitBank API requires marketSymbol for {nameof(GetOrderDetailsAsync)}"); + if (string.IsNullOrWhiteSpace(marketSymbol)) + throw new ArgumentNullException($"BitBank API requires marketSymbol for {nameof(GetOrderDetailsAsync)}"); payload.Add("pair", marketSymbol); JToken token = await MakeJsonRequestAsync("/user/spot/order", baseUrl: BaseUrlPrivate, payload: payload); return ParseOrder(token); diff --git a/src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs b/src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs index f81d6444..ecf97b4a 100644 --- a/src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bitfinex/ExchangeBitfinexAPI.cs @@ -504,7 +504,7 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); if (string.IsNullOrWhiteSpace(orderId)) { return null; diff --git a/src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs b/src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs index 13ebd3a8..b5d38a6f 100644 --- a/src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bitstamp/ExchangeBitstampAPI.cs @@ -195,7 +195,7 @@ private static Dictionary ExtractDictionary(JObject responseObj protected override async Task OnPlaceOrderAsync(ExchangeOrderRequest order) { - if (order.IsPostOnly != null) throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); + if (order.IsPostOnly != null) throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); string action = order.IsBuy ? "buy" : "sell"; string market = order.OrderType == OrderType.Market ? "/market" : ""; string url = $"/{action}{market}/{order.MarketSymbol}/"; diff --git a/src/ExchangeSharp/API/Exchanges/Bittrex/ExchangeBittrexAPI.cs b/src/ExchangeSharp/API/Exchanges/Bittrex/ExchangeBittrexAPI.cs index 9475254f..b0ae8179 100644 --- a/src/ExchangeSharp/API/Exchanges/Bittrex/ExchangeBittrexAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bittrex/ExchangeBittrexAPI.cs @@ -415,7 +415,7 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); if (string.IsNullOrWhiteSpace(orderId)) { return null; diff --git a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitAPI.cs b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitAPI.cs index d8bb36db..64cc0787 100644 --- a/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitAPI.cs @@ -819,7 +819,7 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd public async Task OnAmendOrderAsync(ExchangeOrderRequest order) { - if (order.IsPostOnly != null) throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); + if (order.IsPostOnly != null) throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); var payload = new Dictionary(); payload["symbol"] = order.MarketSymbol; if(order.OrderId != null) diff --git a/src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs b/src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs index 4844a7f4..98b6a51b 100644 --- a/src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Coinbase/ExchangeCoinbaseAPI.cs @@ -741,7 +741,10 @@ protected override async Task OnGetOrderDetailsAsync(string { // Orders may be queried using either the exchange assigned id or the client assigned client_oid. When using client_oid it must be preceded by the client: namespace. JToken obj = await MakeJsonRequestAsync("/orders/" + (isClientOrderId ? "client:" : "") + orderId, null, await GetNoncePayloadAsync(), "GET"); - return ParseOrder(obj); + var order = ParseOrder(obj); + if (!order.MarketSymbol.Equals(marketSymbol, StringComparison.InvariantCultureIgnoreCase)) + throw new DataMisalignedException($"Order {orderId} found, but symbols {order.MarketSymbol} and {marketSymbol} don't match"); + else return order; } protected override async Task> OnGetOpenOrderDetailsAsync(string marketSymbol = null) diff --git a/src/ExchangeSharp/API/Exchanges/Coinmate/ExchangeCoinmateAPI.cs b/src/ExchangeSharp/API/Exchanges/Coinmate/ExchangeCoinmateAPI.cs index e7fe4591..5189842d 100644 --- a/src/ExchangeSharp/API/Exchanges/Coinmate/ExchangeCoinmateAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Coinmate/ExchangeCoinmateAPI.cs @@ -165,7 +165,7 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd if (order.OrderType != OrderType.Limit && order.OrderType != OrderType.Stop) { - throw new NotImplementedException("This type of order is currently not supported."); + throw new NotSupportedException("This type of order is currently not supported."); } payload["amount"] = order.Amount; @@ -182,7 +182,7 @@ protected override async Task OnPlaceOrderAsync(ExchangeOrd { if (!long.TryParse(order.ClientOrderId, out var clientOrderId)) { - throw new InvalidOperationException("ClientId must be numerical for Coinmate"); + throw new ArgumentException("ClientId must be numerical for Coinmate"); } payload["clientOrderId"] = clientOrderId; diff --git a/src/ExchangeSharp/API/Exchanges/Digifinex/ExchangeDigifinexAPI.cs b/src/ExchangeSharp/API/Exchanges/Digifinex/ExchangeDigifinexAPI.cs index 2f3ecedf..b76e915d 100644 --- a/src/ExchangeSharp/API/Exchanges/Digifinex/ExchangeDigifinexAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Digifinex/ExchangeDigifinexAPI.cs @@ -366,7 +366,7 @@ protected override async Task> OnGetCompletedOr protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); Dictionary payload = await GetNoncePayloadAsync(); JToken token = await MakeJsonRequestAsync($"/spot/order?order_id={orderId}", payload: payload); var x = token["data"]; diff --git a/src/ExchangeSharp/API/Exchanges/FTX/FTXGroupCommon.cs b/src/ExchangeSharp/API/Exchanges/FTX/FTXGroupCommon.cs index b76be1f8..2a0abdc8 100644 --- a/src/ExchangeSharp/API/Exchanges/FTX/FTXGroupCommon.cs +++ b/src/ExchangeSharp/API/Exchanges/FTX/FTXGroupCommon.cs @@ -291,7 +291,7 @@ protected async override Task OnGetOrderBookAsync(string mark /// protected async override Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { // https://docs.ftx.com/#get-order-status and https://docs.ftx.com/#get-order-status-by-client-id - if (!string.IsNullOrEmpty(marketSymbol)) throw new NotImplementedException("Searching by marketSymbol is either not implemented by or supported by this exchange. Please submit a PR if you are interested in this feature"); + if (!string.IsNullOrEmpty(marketSymbol)) throw new NotSupportedException("Searching by marketSymbol is either not implemented by or supported by this exchange. Please submit a PR if you are interested in this feature"); var url = "/orders/"; if (isClientOrderId) diff --git a/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs b/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs index d6b45aac..eca00387 100644 --- a/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs @@ -293,7 +293,7 @@ protected override async Task> OnGetAmountsAvailable protected override async Task OnPlaceOrderAsync(ExchangeOrderRequest order) { if (order.OrderType != OrderType.Limit) - throw new InvalidOperationException("Gate.io API supports only limit orders"); + throw new NotSupportedException("Gate.io API supports only limit orders"); var payload = await GetNoncePayloadAsync(); AddOrderToPayload(order, payload); @@ -380,11 +380,11 @@ private static ExchangeAPIOrderResult ParseExchangeAPIOrderResult(string status, protected override async Task OnGetOrderDetailsAsync(string orderId, string symbol = null, bool isClientOrderId = false) { - if (string.IsNullOrEmpty(symbol)) + if (string.IsNullOrWhiteSpace(symbol)) { - throw new InvalidOperationException("MarketSymbol is required for querying order details with Gate.io API"); + throw new ArgumentNullException("MarketSymbol is required for querying order details with Gate.io API"); } - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); var payload = await GetNoncePayloadAsync(); var responseToken = await MakeJsonRequestAsync($"/spot/orders/{orderId}?currency_pair={symbol}", payload: payload); @@ -394,9 +394,9 @@ protected override async Task OnGetOrderDetailsAsync(string protected override async Task> OnGetOpenOrderDetailsAsync(string symbol = null) { - if (string.IsNullOrEmpty(symbol)) + if (string.IsNullOrWhiteSpace(symbol)) { - throw new InvalidOperationException("MarketSymbol is required for querying open orders with Gate.io API"); + throw new ArgumentNullException("MarketSymbol is required for querying open orders with Gate.io API"); } var payload = await GetNoncePayloadAsync(); @@ -423,9 +423,9 @@ protected override async Task> OnGetCompletedOr protected override async Task OnCancelOrderAsync(string orderId, string symbol = null, bool isClientOrderId = false) { - if (string.IsNullOrEmpty(symbol)) + if (string.IsNullOrWhiteSpace(symbol)) { - throw new InvalidOperationException("MarketSymbol is required for cancelling order with Gate.io API"); + throw new ArgumentNullException("MarketSymbol is required for cancelling order with Gate.io API"); } if (isClientOrderId) throw new NotSupportedException("Cancelling by client order ID is not supported in ExchangeSharp. Please submit a PR if you are interested in this feature"); diff --git a/src/ExchangeSharp/API/Exchanges/Hitbtc/ExchangeHitbtcAPI.cs b/src/ExchangeSharp/API/Exchanges/Hitbtc/ExchangeHitbtcAPI.cs index 06ddf541..660165a3 100644 --- a/src/ExchangeSharp/API/Exchanges/Hitbtc/ExchangeHitbtcAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Hitbtc/ExchangeHitbtcAPI.cs @@ -259,7 +259,7 @@ protected override async Task> OnGetAmountsAvailable /// protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); JToken obj = await MakeJsonRequestAsync("/history/order/" + orderId + "/trades", null, await GetNoncePayloadAsync()); if (obj != null && obj.HasValues) return ParseCompletedOrder(obj); return null; diff --git a/src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs b/src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs index bda98db3..bd6098b1 100644 --- a/src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs @@ -715,11 +715,10 @@ protected override async Task OnGetOrderDetailsAsync(string { return null; } - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); object nonce = await GenerateNonceAsync(); Dictionary payload = new Dictionary(StringComparer.OrdinalIgnoreCase) - { { "txid", orderId }, { "nonce", nonce } - }; + { { "txid", orderId }, { "nonce", nonce } }; JToken result = await MakeJsonRequestAsync("/0/private/QueryOrders", null, payload); ExchangeOrderResult orderResult = new ExchangeOrderResult { OrderId = orderId }; if (result == null || result[orderId] == null) diff --git a/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs b/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs index 30cc10c0..5e42bea4 100644 --- a/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs @@ -381,13 +381,10 @@ protected override async Task> OnGetOpenOrderDe protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { var payload = await GetNoncePayloadAsync(); - if (isClientOrderId) - payload["clientOid"] = Guid.NewGuid(); - else - payload["clientOid"] = Guid.NewGuid(); - - JToken token = await MakeJsonRequestAsync("/orders?&" + CryptoUtility.GetFormForPayload(payload, false), null, payload); - var isActive = token["id"].ToObject(); + JToken token = await MakeJsonRequestAsync( + $"/orders{(isClientOrderId ? "/client-order" : null)}/{orderId}" + + CryptoUtility.GetFormForPayload(payload, false), null, payload); + var isActive = token["isActive"].ToObject(); if (isActive) return ParseOpenOrder(token); else return ParseCompletedOrder(token); diff --git a/src/ExchangeSharp/API/Exchanges/LBank/ExchangeLBankAPI.cs b/src/ExchangeSharp/API/Exchanges/LBank/ExchangeLBankAPI.cs index cb43bd7d..8a609fbd 100644 --- a/src/ExchangeSharp/API/Exchanges/LBank/ExchangeLBankAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/LBank/ExchangeLBankAPI.cs @@ -297,7 +297,7 @@ protected override async Task> OnGetAmountsAsync() //PlaceOrder 9 protected override async Task OnPlaceOrderAsync(ExchangeOrderRequest order) { - if (order.IsPostOnly != null) throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); + if (order.IsPostOnly != null) throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); Dictionary payload = new Dictionary { { "amount", order.Amount }, @@ -361,7 +361,7 @@ protected override async Task OnCancelOrderAsync(string orderId, string symbol = //GetOrderDetails 13 protected override async Task OnGetOrderDetailsAsync(string orderId, string symbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); Dictionary payload = new Dictionary { { "api_key", PublicApiKey.ToUnsecureString() }, diff --git a/src/ExchangeSharp/API/Exchanges/Livecoin/ExchangeLivecoinAPI.cs b/src/ExchangeSharp/API/Exchanges/Livecoin/ExchangeLivecoinAPI.cs index b176dec1..350bc281 100644 --- a/src/ExchangeSharp/API/Exchanges/Livecoin/ExchangeLivecoinAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Livecoin/ExchangeLivecoinAPI.cs @@ -221,7 +221,7 @@ protected override async Task> OnGetAmountsAvailable protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); JToken token = await MakeJsonRequestAsync("/exchange/order?orderId=" + orderId, null, await GetNoncePayloadAsync()); return ParseOrder(token); } @@ -265,7 +265,7 @@ protected override async Task> OnGetOpenOrderDe protected override async Task OnPlaceOrderAsync(ExchangeOrderRequest order) { - if (order.IsPostOnly != null) throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); + if (order.IsPostOnly != null) throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); var payload = await GetNoncePayloadAsync(); string orderType = "/exchange/"; if (order.OrderType == OrderType.Market) diff --git a/src/ExchangeSharp/API/Exchanges/NDAX/ExchangeNDAXAPI.cs b/src/ExchangeSharp/API/Exchanges/NDAX/ExchangeNDAXAPI.cs index 5c2f1288..e416b1ee 100644 --- a/src/ExchangeSharp/API/Exchanges/NDAX/ExchangeNDAXAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/NDAX/ExchangeNDAXAPI.cs @@ -151,7 +151,7 @@ protected override async Task> OnGetAmountsAvailable protected override async Task OnPlaceOrderAsync(ExchangeOrderRequest order) { - if (order.IsPostOnly != null) throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); + if (order.IsPostOnly != null) throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); var orderType = 0; var side = order.IsBuy? 0: 1; switch (order.OrderType) @@ -200,7 +200,7 @@ protected override async Task OnPlaceOrdersAsync(params E protected override async Task OnGetOrderDetailsAsync(string orderId, string symbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); await EnsureInstrumentIdsAvailable(); var result = await MakeJsonRequestAsync("GetOrderStatus", null, new Dictionary() diff --git a/src/ExchangeSharp/API/Exchanges/OKGroup/OKGroupCommon.cs b/src/ExchangeSharp/API/Exchanges/OKGroup/OKGroupCommon.cs index e7bb51f1..086217ce 100644 --- a/src/ExchangeSharp/API/Exchanges/OKGroup/OKGroupCommon.cs +++ b/src/ExchangeSharp/API/Exchanges/OKGroup/OKGroupCommon.cs @@ -466,9 +466,9 @@ protected override async Task OnGetOrderDetailsAsync(string { List orders = new List(); Dictionary payload = await GetNoncePayloadAsync(); - if (marketSymbol.Length == 0) + if (string.IsNullOrWhiteSpace(marketSymbol)) { - throw new InvalidOperationException("Okex single order details request requires symbol"); + throw new ArgumentNullException("OKgroup single order details request requires symbol"); } payload["symbol"] = marketSymbol; diff --git a/src/ExchangeSharp/API/Exchanges/Poloniex/ExchangePoloniexAPI.cs b/src/ExchangeSharp/API/Exchanges/Poloniex/ExchangePoloniexAPI.cs index c0c9e9fe..faef1eb1 100644 --- a/src/ExchangeSharp/API/Exchanges/Poloniex/ExchangePoloniexAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Poloniex/ExchangePoloniexAPI.cs @@ -850,7 +850,7 @@ protected override async Task> OnGetOpenOrderDe protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); JToken resultArray = await MakePrivateAPIRequestAsync("returnOrderTrades", new object[] { "orderNumber", orderId }); string tickerSymbol = resultArray[0]["currencyPair"].ToStringInvariant(); List orders = new List(); diff --git a/src/ExchangeSharp/API/Exchanges/Yobit/ExchangeYobitAPI.cs b/src/ExchangeSharp/API/Exchanges/Yobit/ExchangeYobitAPI.cs index 51e24433..65a820fc 100644 --- a/src/ExchangeSharp/API/Exchanges/Yobit/ExchangeYobitAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/Yobit/ExchangeYobitAPI.cs @@ -204,7 +204,7 @@ protected override async Task> OnGetAmountsAvailable protected override async Task OnGetOrderDetailsAsync(string orderId, string marketSymbol = null, bool isClientOrderId = false) { - if (isClientOrderId) throw new NotImplementedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); + if (isClientOrderId) throw new NotSupportedException("Querying by client order ID is not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature"); var payload = await GetNoncePayloadAsync(); payload.Add("method", "getInfo"); payload.Add("order_id", orderId); @@ -250,7 +250,7 @@ protected override async Task> OnGetOpenOrderDe protected override async Task OnPlaceOrderAsync(ExchangeOrderRequest order) { - if (order.IsPostOnly != null) throw new NotImplementedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); + if (order.IsPostOnly != null) throw new NotSupportedException("Post Only orders are not supported by this exchange or not implemented in ExchangeSharp. Please submit a PR if you are interested in this feature."); var payload = await GetNoncePayloadAsync(); payload.Add("method", "Trade"); payload.Add("pair", order.MarketSymbol); diff --git a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs index 7c830ee2..85f9d69e 100644 --- a/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs +++ b/src/ExchangeSharp/API/Exchanges/_Base/ExchangeAPI.cs @@ -246,7 +246,7 @@ protected async Task ClampOrderPrice(string marketSymbol, decimal outpu { ExchangeMarket? market = await GetExchangeMarketFromCacheAsync(marketSymbol); if (market.MinPrice == null || market.MaxPrice == null || market.PriceStepSize == null) - throw new NotImplementedException($"Exchange must return {nameof(market.MinPrice)} and {nameof(market.MaxPrice)} in order for {nameof(ClampOrderPrice)}() to work"); + throw new NotSupportedException($"Exchange must return {nameof(market.MinPrice)} and {nameof(market.MaxPrice)} in order for {nameof(ClampOrderPrice)}() to work"); else return market == null ? outputPrice : CryptoUtility.ClampDecimal(market.MinPrice.Value, market.MaxPrice.Value, market.PriceStepSize, outputPrice); } @@ -260,7 +260,7 @@ protected async Task ClampOrderQuantity(string marketSymbol, decimal ou { ExchangeMarket? market = await GetExchangeMarketFromCacheAsync(marketSymbol); if (market.MinPrice == null || market.MaxPrice == null || market.PriceStepSize == null) - throw new NotImplementedException($"Exchange must return {nameof(market.MinPrice)} and {nameof(market.MaxPrice)} in order for {nameof(ClampOrderQuantity)}() to work"); + throw new NotSupportedException($"Exchange must return {nameof(market.MinPrice)} and {nameof(market.MaxPrice)} in order for {nameof(ClampOrderQuantity)}() to work"); else return market == null ? outputQuantity : CryptoUtility.ClampDecimal(market.MinTradeSize.Value, market.MaxTradeSize.Value, market.QuantityStepSize, outputQuantity); } @@ -303,12 +303,12 @@ protected async Task ExchangeMarketSymbolToGlobalMarketSymbolWithSeparat /// /// Market symbol /// Base and quote currency - protected virtual(string baseCurrency, string quoteCurrency)OnSplitMarketSymbolToCurrencies(string marketSymbol) + protected virtual (string baseCurrency, string quoteCurrency) OnSplitMarketSymbolToCurrencies(string marketSymbol) { var pieces = marketSymbol.Split(MarketSymbolSeparator[0]); if (pieces.Length < 2) { - throw new InvalidOperationException($"Splitting {Name} symbol '{marketSymbol}' with symbol separator '{MarketSymbolSeparator}' must result in at least 2 pieces."); + throw new ArgumentException($"Splitting {Name} symbol '{marketSymbol}' with symbol separator '{MarketSymbolSeparator}' must result in at least 2 pieces."); } string baseCurrency = MarketSymbolIsReversed ? pieces[1] : pieces[0]; string quoteCurrency = MarketSymbolIsReversed ? pieces[0] : pieces[1];