Skip to content
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
3 changes: 3 additions & 0 deletions CryptoClients.Net/Clients/Rest/ExchangeRestClient.Balance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedBalance[]>> GetBalancesAsync(string exchange, GetBalancesRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetBalancesIntAsync(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedBalance[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedBalance[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedBookTicker>> GetBookTickerAsync(string exchange, GetBookTickerRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetBookTickersInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedBookTicker>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedBookTicker>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedFundingRate[]>> GetFundingRateHistoryAsync(string exchange, GetFundingRateHistoryRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetFundingRateHistoryInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedFundingRate[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedFundingRate[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
12 changes: 12 additions & 0 deletions CryptoClients.Net/Clients/Rest/ExchangeRestClient.FuturesOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public async Task<ExchangeWebResult<SharedId>> PlaceFuturesOrderAsync(string exc
public async Task<ExchangeWebResult<SharedFuturesOrder[]>> GetFuturesOpenOrdersAsync(string exchange, GetOpenOrdersRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetFuturesOpenOrdersInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedFuturesOrder[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedFuturesOrder[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down Expand Up @@ -70,6 +73,9 @@ private IEnumerable<Task<ExchangeWebResult<SharedFuturesOrder[]>>> GetFuturesOpe
public async Task<ExchangeWebResult<SharedFuturesOrder[]>> GetFuturesClosedOrdersAsync(string exchange, GetClosedOrdersRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetFuturesClosedOrdersInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedFuturesOrder[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedFuturesOrder[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down Expand Up @@ -103,6 +109,9 @@ private IEnumerable<Task<ExchangeWebResult<SharedFuturesOrder[]>>> GetFuturesClo
public async Task<ExchangeWebResult<SharedUserTrade[]>> GetFuturesUserTradesAsync(string exchange, GetUserTradesRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetFuturesUserTradesInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedUserTrade[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedUserTrade[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down Expand Up @@ -192,6 +201,9 @@ public async Task<ExchangeWebResult<SharedId>> ClosePositionAsync(string exchang
public async Task<ExchangeWebResult<SharedPosition[]>> GetPositionsAsync(string exchange, GetPositionsRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetPositionsInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedPosition[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedPosition[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
74 changes: 74 additions & 0 deletions CryptoClients.Net/Clients/Rest/ExchangeRestClient.FuturesSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,86 @@ public partial class ExchangeRestClient
/// <inheritdoc />
public IFuturesSymbolRestClient? GetFuturesSymbolClient(TradingMode api, string exchange) => _sharedClients.OfType<IFuturesSymbolRestClient>().SingleOrDefault(s => s.SupportedTradingModes.Contains(api) && s.Exchange == exchange);

/// <inheritdoc />
public async Task<ExchangeResult<SharedSymbol[]>> GetFuturesSymbolsForBaseAssetAsync(string exchange, string baseAsset)
{
var clients = GetFuturesSymbolClients().Where(x => x.Exchange == exchange).ToArray();
if (clients.Length == 0)
return new ExchangeResult<SharedSymbol[]>(exchange, ArgumentError.Invalid(nameof(exchange), "Exchange client not found"));

var supportsTask = clients.Select(x => x.GetFuturesSymbolsForBaseAssetAsync(baseAsset)).ToArray();
await Task.WhenAll(supportsTask).ConfigureAwait(false);
var failedResult = supportsTask.FirstOrDefault(x => !x.Result.Success);
if (failedResult != null)
return new ExchangeResult<SharedSymbol[]>(exchange, failedResult.Result.Error!);

return new ExchangeResult<SharedSymbol[]>(exchange, supportsTask.SelectMany(x => x.Result.Data).ToArray());
}

/// <inheritdoc />
public async Task<Dictionary<string, SharedSymbol[]>> GetFuturesSymbolsForBaseAssetAsync(string baseAsset)
{
var clients = GetFuturesSymbolClients();
var supportsTask = clients.Select(x => x.GetFuturesSymbolsForBaseAssetAsync(baseAsset)).ToArray();
await Task.WhenAll(supportsTask).ConfigureAwait(false);

return supportsTask
.Where(x => x.Result.Success)
.GroupBy(x => x.Result.Exchange)
.ToDictionary(x => x.Key, x => x.SelectMany(x => x.Result.Data)
.ToArray());
}

/// <inheritdoc />
public async Task<string[]> GetExchangesSupportingFuturesSymbolAsync(SharedSymbol symbol)
{
var clients = GetFuturesSymbolClients();
var supportsTask = clients.Select(x => x.SupportsFuturesSymbolAsync(symbol)).ToArray();
await Task.WhenAll(supportsTask).ConfigureAwait(false);

return supportsTask.Where(x => x.Result.Data).Select(x => x.Result.Exchange).Distinct().ToArray();
}

/// <inheritdoc />
public async Task<string[]> GetExchangesSupportingFuturesSymbolAsync(string symbolName)
{
var clients = GetFuturesSymbolClients();
var supportsTask = clients.Select(x => x.SupportsFuturesSymbolAsync(symbolName)).ToArray();
await Task.WhenAll(supportsTask).ConfigureAwait(false);

return supportsTask.Where(x => x.Result.Data).Select(x => x.Result.Exchange).Distinct().ToArray();
}

/// <inheritdoc />
public async Task<ExchangeResult<bool>> SupportsFuturesSymbolAsync(string exchange, SharedSymbol symbol)
{
var client = GetFuturesSymbolClients().SingleOrDefault(x => x.Exchange == exchange);
if (client == null)
return new ExchangeResult<bool>(exchange, ArgumentError.Invalid(nameof(exchange), "Exchange client not found"));

return await client.SupportsFuturesSymbolAsync(symbol).ConfigureAwait(false);
}

/// <inheritdoc />
public async Task<ExchangeResult<bool>> SupportsFuturesSymbolAsync(string exchange, string symbolName)
{
var client = GetFuturesSymbolClients().SingleOrDefault(x => x.Exchange == exchange);
if (client == null)
return new ExchangeResult<bool>(exchange, ArgumentError.Invalid(nameof(exchange), "Exchange client not found"));

return await client.SupportsFuturesSymbolAsync(symbolName).ConfigureAwait(false);

}

#region Get Futures Symbols

/// <inheritdoc />
public async Task<ExchangeWebResult<SharedFuturesSymbol[]>> GetFuturesSymbolsAsync(string exchange, GetSymbolsRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetFuturesSymbolsInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedFuturesSymbol[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedFuturesSymbol[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedFuturesTicker[]>> GetFuturesTickersAsync(string exchange, GetTickersRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetFuturesTickersInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedFuturesTicker[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedFuturesTicker[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down Expand Up @@ -57,6 +60,9 @@ private IEnumerable<Task<ExchangeWebResult<SharedFuturesTicker[]>>> GetFuturesTi
public async Task<ExchangeWebResult<SharedFuturesTicker>> GetFuturesTickerAsync(string exchange, GetTickerRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetFuturesTickerInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedFuturesTicker>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedFuturesTicker>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedFuturesKline[]>> GetIndexPriceKlinesAsync(string exchange, GetKlinesRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetIndexPriceKlinesIntAsync(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedFuturesKline[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedFuturesKline[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
3 changes: 3 additions & 0 deletions CryptoClients.Net/Clients/Rest/ExchangeRestClient.Kline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedKline[]>> GetKlinesAsync(string exchange, GetKlinesRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetKlinesIntAsync(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedKline[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedKline[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<string>> StartListenKeyAsync(string exchange, StartListenKeyRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(StartListenKeysInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<string>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<string>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedFuturesKline[]>> GetMarkPriceKlinesAsync(string exchange, GetKlinesRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetMarkPriceKlinesIntAsync(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedFuturesKline[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedFuturesKline[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedOpenInterest>> GetOpenInterestAsync(string exchange, GetOpenInterestRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetOpenInterestInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedOpenInterest>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedOpenInterest>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedOrderBook>> GetOrderBookAsync(string exchange, GetOrderBookRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetOrderBookInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedOrderBook>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedOrderBook>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedPositionHistory[]>> GetPositionHistoryAsync(string exchange, GetPositionHistoryRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetPositionHistoryInt(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedPositionHistory[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedPositionHistory[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public partial class ExchangeRestClient
public async Task<ExchangeWebResult<SharedTrade[]>> GetRecentTradesAsync(string exchange, GetRecentTradesRequest request, CancellationToken ct = default)
{
var result = await Task.WhenAll(GetRecentTradesIntAsync(request, new[] { exchange }, ct)).ConfigureAwait(false);
if (result.Length > 1)
return new ExchangeWebResult<SharedTrade[]>(exchange, new InvalidOperationError($"Multiple API's available for {exchange}, specify the `TradingMode` parameter on the request to choose one"));

return result.SingleOrDefault() ?? new ExchangeWebResult<SharedTrade[]>(exchange, new InvalidOperationError($"Request not supported for {exchange}"));
}

Expand Down
Loading