Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

standardize exception types #735

Merged
merged 1 commit into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ExchangeSharp/API/Common/BaseAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public async Task<object> GenerateNonceAsync()
break;

default:
throw new InvalidOperationException("Invalid nonce style: " + NonceStyle);
throw new NotImplementedException("Invalid nonce style: " + NonceStyle);
}

// check for duplicate nonce
Expand Down
4 changes: 2 additions & 2 deletions src/ExchangeSharp/API/Exchanges/Aquanow/ExchangeAquanowAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected override async Task ProcessRequestAsync(IHttpWebRequest request, Dicti
// DONE
protected override async Task<ExchangeOrderResult> 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";
Expand Down Expand Up @@ -201,7 +201,7 @@ protected override async Task<ExchangeOrderResult> 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<JToken>($"/trades/v1/order?orderId={orderId}", null, payload, "GET");
bool isBuy = result["tradeSide"].ToStringInvariant() == "buy" ? true : false;
Expand Down
4 changes: 2 additions & 2 deletions src/ExchangeSharp/API/Exchanges/BL3P/ExchangeBL3PAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ private string GetSignKey(IHttpWebRequest request, string formData)

protected override async Task<ExchangeOrderResult> 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);

Expand Down Expand Up @@ -314,7 +314,7 @@ protected override async Task<ExchangeOrderResult> 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<string, object>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ protected override async Task<ExchangeOrderResult> 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();
Expand Down Expand Up @@ -587,7 +587,7 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string
Dictionary<string, object> 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!;

Expand Down
8 changes: 4 additions & 4 deletions src/ExchangeSharp/API/Exchanges/BitBank/ExchangeBitBankAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected override Task OnGetHistoricalTradesAsync(Func<IEnumerable<ExchangeTrad
protected override async Task<ExchangeOrderResult> 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<string, object> payload = await GetNoncePayloadAsync();
if (order.IsPostOnly != null)
payload["post_only"] = order.IsPostOnly;
Expand All @@ -154,11 +154,11 @@ protected override async Task OnCancelOrderAsync(string orderId, string marketSy

protected override async Task<ExchangeOrderResult> 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<JToken>("/user/spot/order", baseUrl: BaseUrlPrivate, payload: payload);
return ParseOrder(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd

protected override async Task<ExchangeOrderResult> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private static Dictionary<string, decimal> ExtractDictionary(JObject responseObj

protected override async Task<ExchangeOrderResult> 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}/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd

protected override async Task<ExchangeOrderResult> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/ExchangeSharp/API/Exchanges/Bybit/ExchangeBybitAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ protected override async Task<ExchangeOrderResult> OnPlaceOrderAsync(ExchangeOrd

public async Task<ExchangeOrderResult> 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<string, object>();
payload["symbol"] = order.MarketSymbol;
if(order.OrderId != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,10 @@ protected override async Task<ExchangeOrderResult> 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<JToken>("/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<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDetailsAsync(string marketSymbol = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected override async Task<ExchangeOrderResult> 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;
Expand All @@ -182,7 +182,7 @@ protected override async Task<ExchangeOrderResult> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetCompletedOr

protected override async Task<ExchangeOrderResult> 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<string, object> payload = await GetNoncePayloadAsync();
JToken token = await MakeJsonRequestAsync<JToken>($"/spot/order?order_id={orderId}", payload: payload);
var x = token["data"];
Expand Down
2 changes: 1 addition & 1 deletion src/ExchangeSharp/API/Exchanges/FTX/FTXGroupCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ protected async override Task<ExchangeOrderBook> OnGetOrderBookAsync(string mark
/// <inheritdoc />
protected async override Task<ExchangeOrderResult> 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)
Expand Down
16 changes: 8 additions & 8 deletions src/ExchangeSharp/API/Exchanges/GateIo/ExchangeGateIoAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable
protected override async Task<ExchangeOrderResult> 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);
Expand Down Expand Up @@ -380,11 +380,11 @@ private static ExchangeAPIOrderResult ParseExchangeAPIOrderResult(string status,

protected override async Task<ExchangeOrderResult> 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<JToken>($"/spot/orders/{orderId}?currency_pair={symbol}", payload: payload);
Expand All @@ -394,9 +394,9 @@ protected override async Task<ExchangeOrderResult> OnGetOrderDetailsAsync(string

protected override async Task<IEnumerable<ExchangeOrderResult>> 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();
Expand All @@ -423,9 +423,9 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> 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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAvailable
/// <returns></returns>
protected override async Task<ExchangeOrderResult> 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<JToken>("/history/order/" + orderId + "/trades", null, await GetNoncePayloadAsync());
if (obj != null && obj.HasValues) return ParseCompletedOrder(obj);
return null;
Expand Down
5 changes: 2 additions & 3 deletions src/ExchangeSharp/API/Exchanges/Kraken/ExchangeKrakenAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,10 @@ protected override async Task<ExchangeOrderResult> 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<string, object> payload = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase)
{ { "txid", orderId }, { "nonce", nonce }
};
{ { "txid", orderId }, { "nonce", nonce } };
JToken result = await MakeJsonRequestAsync<JToken>("/0/private/QueryOrders", null, payload);
ExchangeOrderResult orderResult = new ExchangeOrderResult { OrderId = orderId };
if (result == null || result[orderId] == null)
Expand Down
11 changes: 4 additions & 7 deletions src/ExchangeSharp/API/Exchanges/KuCoin/ExchangeKuCoinAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,10 @@ protected override async Task<IEnumerable<ExchangeOrderResult>> OnGetOpenOrderDe
protected override async Task<ExchangeOrderResult> 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<JToken>("/orders?&" + CryptoUtility.GetFormForPayload(payload, false), null, payload);
var isActive = token["id"].ToObject<bool>();
JToken token = await MakeJsonRequestAsync<JToken>(
$"/orders{(isClientOrderId ? "/client-order" : null)}/{orderId}"
+ CryptoUtility.GetFormForPayload(payload, false), null, payload);
var isActive = token["isActive"].ToObject<bool>();
if (isActive)
return ParseOpenOrder(token);
else return ParseCompletedOrder(token);
Expand Down
4 changes: 2 additions & 2 deletions src/ExchangeSharp/API/Exchanges/LBank/ExchangeLBankAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ protected override async Task<Dictionary<string, decimal>> OnGetAmountsAsync()
//PlaceOrder 9
protected override async Task<ExchangeOrderResult> 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<string, object> payload = new Dictionary<string, object>
{
{ "amount", order.Amount },
Expand Down Expand Up @@ -361,7 +361,7 @@ protected override async Task OnCancelOrderAsync(string orderId, string symbol =
//GetOrderDetails 13
protected override async Task<ExchangeOrderResult> 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<string, object> payload = new Dictionary<string, object>
{
{ "api_key", PublicApiKey.ToUnsecureString() },
Expand Down
Loading