Skip to content

Commit

Permalink
Removed pre-send symbol validation
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Apr 3, 2024
1 parent 6764165 commit 0bf9510
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 64 deletions.
16 changes: 0 additions & 16 deletions CoinEx.Net.UnitTests/CoinExClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,6 @@ public void SigningString_Should_GiveCorrectSignResult(string input, string outp
Assert.That(sign == output);
}

[TestCase("BTCUSDT", true)]
[TestCase("NANOUSDTA", true)]
[TestCase("NANOBTC", true)]
[TestCase("ETHBTC", true)]
[TestCase("BEETC", true)]
[TestCase("BETC", false)]
[TestCase("BTC-USDT", false)]
[TestCase("BTC-USD", false)]
public void CheckValidCoinExSymbol(string symbol, bool isValid)
{
if (isValid)
Assert.DoesNotThrow(symbol.ValidateCoinExSymbol);
else
Assert.Throws(typeof(ArgumentException), symbol.ValidateCoinExSymbol);
}

[Test]
public void CheckRestInterfaces()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public async Task<WebCallResult<Dictionary<string, CoinExAssetConfig>>> GetAsset
/// <inheritdoc />
public async Task<WebCallResult<CoinExSymbolState>> GetTickerAsync(string symbol, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
var parameters = new Dictionary<string, object>
{
{ "market", symbol }
Expand All @@ -85,7 +84,6 @@ public async Task<WebCallResult<CoinExSymbolStatesList>> GetTickersAsync(Cancell
/// <inheritdoc />
public async Task<WebCallResult<CoinExOrderBook>> GetOrderBookAsync(string symbol, int mergeDepth, int? limit = null, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
mergeDepth.ValidateIntBetween(nameof(mergeDepth), 0, 8);
limit?.ValidateIntValues(nameof(limit), 5, 10, 20);

Expand All @@ -102,8 +100,6 @@ public async Task<WebCallResult<CoinExOrderBook>> GetOrderBookAsync(string symbo
/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<CoinExSymbolTrade>>> GetTradeHistoryAsync(string symbol, long? fromId = null, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();

var parameters = new Dictionary<string, object>
{
{ "market", symbol }
Expand Down Expand Up @@ -132,7 +128,6 @@ public async Task<WebCallResult<Dictionary<string, CoinExSymbol>>> GetSymbolInfo
/// <inheritdoc />
public async Task<WebCallResult<IEnumerable<CoinExKline>>> GetKlinesAsync(string symbol, KlineInterval interval, int? limit = null, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
limit?.ValidateIntBetween(nameof(limit), 1, 1000);
var parameters = new Dictionary<string, object>
{
Expand Down
10 changes: 0 additions & 10 deletions CoinEx.Net/Clients/SpotApi/CoinExRestClientSpotApiTrading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public async Task<WebCallResult<CoinExOrder>> PlaceOrderAsync(
string? sourceId = null,
CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();

var endpoint = "";
if (type == OrderType.Limit)
endpoint = PlaceLimitOrderEndpoint;
Expand Down Expand Up @@ -99,7 +97,6 @@ public async Task<WebCallResult<CoinExOrder>> PlaceOrderAsync(
/// <inheritdoc />
public async Task<WebCallResult<CoinExPagedResult<CoinExOrder>>> GetOpenOrdersAsync(string? symbol = null, int? page = null, int? limit = null, CancellationToken ct = default)
{
symbol?.ValidateCoinExSymbol();
limit?.ValidateIntBetween(nameof(limit), 1, 100);
var parameters = new Dictionary<string, object>
{
Expand All @@ -115,7 +112,6 @@ public async Task<WebCallResult<CoinExPagedResult<CoinExOrder>>> GetOpenOrdersAs
/// <inheritdoc />
public async Task<WebCallResult<CoinExPagedResult<CoinExOrder>>> GetOpenStopOrdersAsync(string symbol, int? page = null, int? limit = null, CancellationToken ct = default)
{
symbol?.ValidateCoinExSymbol();
limit?.ValidateIntBetween(nameof(limit), 1, 100);
var parameters = new Dictionary<string, object>
{
Expand All @@ -129,7 +125,6 @@ public async Task<WebCallResult<CoinExPagedResult<CoinExOrder>>> GetOpenStopOrde
/// <inheritdoc />
public async Task<WebCallResult<CoinExPagedResult<CoinExOrder>>> GetClosedOrdersAsync(string symbol, int? page = null, int? limit = null, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
limit?.ValidateIntBetween(nameof(limit), 1, 100);
var parameters = new Dictionary<string, object>
{
Expand All @@ -144,7 +139,6 @@ public async Task<WebCallResult<CoinExPagedResult<CoinExOrder>>> GetClosedOrders
/// <inheritdoc />
public async Task<WebCallResult<CoinExOrder>> GetOrderAsync(string symbol, long orderId, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
var parameters = new Dictionary<string, object>
{
{ "market", symbol },
Expand All @@ -171,7 +165,6 @@ public async Task<WebCallResult<CoinExPagedResult<CoinExOrderTrade>>> GetOrderTr
/// <inheritdoc />
public async Task<WebCallResult<CoinExPagedResult<CoinExOrderTradeExtended>>> GetUserTradesAsync(string symbol, int? page = null, int? limit = null, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
limit?.ValidateIntBetween(nameof(limit), 1, 100);
var parameters = new Dictionary<string, object>
{
Expand All @@ -186,7 +179,6 @@ public async Task<WebCallResult<CoinExPagedResult<CoinExOrderTradeExtended>>> Ge
/// <inheritdoc />
public async Task<WebCallResult<CoinExOrder>> CancelOrderAsync(string symbol, long orderId, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
var parameters = new Dictionary<string, object>
{
{ "market", symbol },
Expand All @@ -202,7 +194,6 @@ public async Task<WebCallResult<CoinExOrder>> CancelOrderAsync(string symbol, lo
/// <inheritdoc />
public async Task<WebCallResult> CancelAllOrdersAsync(string symbol, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
var parameters = new Dictionary<string, object>
{
{ "market", symbol },
Expand All @@ -214,7 +205,6 @@ public async Task<WebCallResult> CancelAllOrdersAsync(string symbol, Cancellatio
/// <inheritdoc />
public async Task<WebCallResult> CancelAllStopOrdersAsync(string symbol, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
var parameters = new Dictionary<string, object>
{
{ "market", symbol },
Expand Down
13 changes: 0 additions & 13 deletions CoinEx.Net/Clients/SpotApi/CoinExSocketClientSpotApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,13 @@ public async Task<CallResult<DateTime>> GetServerTimeAsync()
/// <inheritdoc />
public async Task<CallResult<CoinExSocketSymbolState>> GetTickerAsync(string symbol, int cyclePeriod)
{
symbol.ValidateCoinExSymbol();
var query = await QueryAsync(new CoinExQuery<CoinExSocketSymbolState>("state.query", new object[] { symbol, cyclePeriod })).ConfigureAwait(false);
return query.As<CoinExSocketSymbolState>(query.Data?.Result);
}

/// <inheritdoc />
public async Task<CallResult<CoinExSocketOrderBook>> GetOrderBookAsync(string symbol, int limit, int mergeDepth)
{
symbol.ValidateCoinExSymbol();
mergeDepth.ValidateIntBetween(nameof(mergeDepth), 0, 8);
limit.ValidateIntValues(nameof(limit), 5, 10, 20);

Expand All @@ -131,17 +129,13 @@ public async Task<CallResult<CoinExSocketOrderBook>> GetOrderBookAsync(string sy
/// <inheritdoc />
public async Task<CallResult<IEnumerable<CoinExSocketSymbolTrade>>> GetTradeHistoryAsync(string symbol, int? limit = null, int? fromId = null)
{
symbol.ValidateCoinExSymbol();

var query = await QueryAsync(new CoinExQuery<IEnumerable<CoinExSocketSymbolTrade>>("deals.query", new object[] { symbol, limit ?? 10, fromId ?? 0 }, false)).ConfigureAwait(false);
return query.As<IEnumerable<CoinExSocketSymbolTrade>>(query.Data?.Result);
}

/// <inheritdoc />
public async Task<CallResult<IEnumerable<CoinExKline>>> GetKlinesAsync(string symbol, KlineInterval interval)
{
symbol.ValidateCoinExSymbol();

var startTime = DateTimeConverter.ConvertToSeconds(DateTime.UtcNow.AddDays(-1));
var endTime = DateTimeConverter.ConvertToSeconds(DateTime.UtcNow);
var query = await QueryAsync(new CoinExQuery<IEnumerable<CoinExKline>>("kline.query", new object[] { symbol, startTime, endTime, interval.ToSeconds() }, false)).ConfigureAwait(false);
Expand All @@ -158,17 +152,13 @@ public async Task<CallResult<Dictionary<string, CoinExBalance>>> GetBalancesAsyn
/// <inheritdoc />
public async Task<CallResult<CoinExSocketPagedResult<CoinExSocketOrder>>> GetOpenOrdersAsync(string symbol, OrderSide? side = null, int? offset = null, int? limit = null)
{
symbol.ValidateCoinExSymbol();

var query = await QueryAsync(new CoinExQuery<CoinExSocketPagedResult<CoinExSocketOrder>>("order.query", new object[] { symbol, int.Parse(JsonConvert.SerializeObject(side ?? OrderSide.Either, new OrderSideIntConverter(false))), offset ?? 0, limit ?? 10 }, true)).ConfigureAwait(false);
return query.As<CoinExSocketPagedResult<CoinExSocketOrder>>(query.Data?.Result);
}

/// <inheritdoc />
public async Task<CallResult<UpdateSubscription>> SubscribeToTickerUpdatesAsync(string symbol, Action<DataEvent<CoinExSocketSymbolState>> onMessage, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();

var subscription = new CoinExStateSubscription(_logger, symbol, new object[] { symbol }, x => onMessage(x.As(x.Data.Single())));
return await SubscribeAsync(subscription, ct).ConfigureAwait(false);
}
Expand All @@ -183,7 +173,6 @@ public async Task<CallResult<UpdateSubscription>> SubscribeToAllTickerUpdatesAsy
/// <inheritdoc />
public async Task<CallResult<UpdateSubscription>> SubscribeToOrderBookUpdatesAsync(string symbol, int limit, int mergeDepth, Action<DataEvent<CoinExSocketOrderBook>> onMessage, bool diffUpdates, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();
mergeDepth.ValidateIntBetween(nameof(mergeDepth), 0, 8);
limit.ValidateIntValues(nameof(limit), 5, 10, 20);

Expand All @@ -194,8 +183,6 @@ public async Task<CallResult<UpdateSubscription>> SubscribeToOrderBookUpdatesAsy
/// <inheritdoc />
public async Task<CallResult<UpdateSubscription>> SubscribeToTradeUpdatesAsync(string symbol, Action<DataEvent<IEnumerable<CoinExSocketSymbolTrade>>> onMessage, CancellationToken ct = default)
{
symbol.ValidateCoinExSymbol();

var subscription = new CoinExDealsSubscription(_logger, symbol, new object[] { symbol }, onMessage);
return await SubscribeAsync(subscription, ct).ConfigureAwait(false);
}
Expand Down
6 changes: 0 additions & 6 deletions CoinEx.Net/CoinEx.Net.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions CoinEx.Net/ExtensionMethods/CoinExExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,5 @@ namespace CoinEx.Net.ExtensionMethods
/// </summary>
public static class CoinExExtensionMethods
{
/// <summary>
/// Validate the string is a valid CoinEx symbol.
/// </summary>
/// <param name="symbolString">string to validate</param>
public static void ValidateCoinExSymbol(this string symbolString)
{
if (string.IsNullOrEmpty(symbolString))
throw new ArgumentException("Symbol is not provided");

if (!Regex.IsMatch(symbolString, "^([0-9A-Z]{5,})$"))
throw new ArgumentException($"{symbolString} is not a valid CoinEx symbol. Should be [BaseAsset][QuoteAsset], e.g. ETHBTC");
}
}
}
2 changes: 0 additions & 2 deletions CoinEx.Net/SymbolOrderBooks/CoinExSpotSymbolOrderBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public CoinExSpotSymbolOrderBook(string symbol,
optionsDelegate(options);
Initialize(options);

symbol.ValidateCoinExSymbol();

_strictLevels = false;
_sequencesAreConsecutive = false;
_initialDataTimeout = options?.InitialDataTimeout ?? TimeSpan.FromSeconds(30);
Expand Down

0 comments on commit 0bf9510

Please sign in to comment.