diff --git a/CryptoExchange.Net/ExchangeSymbolCache.cs b/CryptoExchange.Net/ExchangeSymbolCache.cs index 2b237d4..da00729 100644 --- a/CryptoExchange.Net/ExchangeSymbolCache.cs +++ b/CryptoExchange.Net/ExchangeSymbolCache.cs @@ -32,6 +32,66 @@ namespace CryptoExchange.Net _symbolInfos[topicId] = new ExchangeInfo(DateTime.UtcNow, updateData.ToDictionary(x => x.Name, x => x.SharedSymbol)); } + /// + /// Whether the specific topic has been cached + /// + /// Id + public static bool HasCached(string topicId) + { + if (!_symbolInfos.TryGetValue(topicId, out var exchangeInfo)) + return false; + + return exchangeInfo.Symbols.Count > 0; + } + + /// + /// Whether a specific exchange(topic) support the provided symbol + /// + /// Id for the provided data + /// The symbol name + public static bool SupportsSymbol(string topicId, string symbolName) + { + if (!_symbolInfos.TryGetValue(topicId, out var exchangeInfo)) + return false; + + if (!exchangeInfo.Symbols.TryGetValue(symbolName, out var symbolInfo)) + return false; + + return true; + } + + /// + /// Whether a specific exchange(topic) support the provided symbol + /// + /// Id for the provided data + /// The symbol info + public static bool SupportsSymbol(string topicId, SharedSymbol symbol) + { + if (!_symbolInfos.TryGetValue(topicId, out var exchangeInfo)) + return false; + + return exchangeInfo.Symbols.Any(x => + x.Value.TradingMode == symbol.TradingMode + && x.Value.BaseAsset == symbol.BaseAsset + && x.Value.QuoteAsset == symbol.QuoteAsset); + } + + /// + /// Get all symbols for a specific base asset + /// + /// Id for the provided data + /// Base asset name + public static SharedSymbol[] GetSymbolsForBaseAsset(string topicId, string baseAsset) + { + if (!_symbolInfos.TryGetValue(topicId, out var exchangeInfo)) + return []; + + return exchangeInfo.Symbols + .Where(x => x.Value.BaseAsset.Equals(baseAsset, StringComparison.InvariantCultureIgnoreCase)) + .Select(x => x.Value) + .ToArray(); + } + /// /// Parse a symbol name to a SharedSymbol /// diff --git a/CryptoExchange.Net/SharedApis/Interfaces/Rest/Futures/IFuturesSymbolRestClient.cs b/CryptoExchange.Net/SharedApis/Interfaces/Rest/Futures/IFuturesSymbolRestClient.cs index 81b27db..fa7e977 100644 --- a/CryptoExchange.Net/SharedApis/Interfaces/Rest/Futures/IFuturesSymbolRestClient.cs +++ b/CryptoExchange.Net/SharedApis/Interfaces/Rest/Futures/IFuturesSymbolRestClient.cs @@ -12,6 +12,25 @@ namespace CryptoExchange.Net.SharedApis /// Futures symbol request options /// EndpointOptions GetFuturesSymbolsOptions { get; } + + /// + /// Get all futures symbols for a specific base asset + /// + /// Asset, for example `ETH` + Task> GetFuturesSymbolsForBaseAssetAsync(string baseAsset); + + /// + /// Gets whether the client supports a futures symbol + /// + /// The symbol + Task> SupportsFuturesSymbolAsync(SharedSymbol symbol); + + /// + /// Gets whether the client supports a futures symbol + /// + /// The symbol name + Task> SupportsFuturesSymbolAsync(string symbolName); + /// /// Get info on all futures symbols supported on the exchange /// diff --git a/CryptoExchange.Net/SharedApis/Interfaces/Rest/Spot/ISpotSymbolRestClient.cs b/CryptoExchange.Net/SharedApis/Interfaces/Rest/Spot/ISpotSymbolRestClient.cs index 78cb0f4..71f80a5 100644 --- a/CryptoExchange.Net/SharedApis/Interfaces/Rest/Spot/ISpotSymbolRestClient.cs +++ b/CryptoExchange.Net/SharedApis/Interfaces/Rest/Spot/ISpotSymbolRestClient.cs @@ -1,4 +1,5 @@ -using System.Threading; +using CryptoExchange.Net.Objects; +using System.Threading; using System.Threading.Tasks; namespace CryptoExchange.Net.SharedApis @@ -13,6 +14,24 @@ namespace CryptoExchange.Net.SharedApis /// EndpointOptions GetSpotSymbolsOptions { get; } + /// + /// Get all spot symbols for a specific base asset + /// + /// Asset, for example `ETH` + Task> GetSpotSymbolsForBaseAssetAsync(string baseAsset); + + /// + /// Gets whether the client supports a spot symbol + /// + /// The symbol + Task> SupportsSpotSymbolAsync(SharedSymbol symbol); + + /// + /// Gets whether the client supports a spot symbol + /// + /// The symbol name + Task> SupportsSpotSymbolAsync(string symbolName); + /// /// Get info on all available spot symbols on the exchange /// diff --git a/CryptoExchange.Net/SharedApis/Models/ExchangeResult.cs b/CryptoExchange.Net/SharedApis/Models/ExchangeResult.cs index be09d54..8532966 100644 --- a/CryptoExchange.Net/SharedApis/Models/ExchangeResult.cs +++ b/CryptoExchange.Net/SharedApis/Models/ExchangeResult.cs @@ -38,6 +38,17 @@ namespace CryptoExchange.Net.SharedApis Exchange = exchange; } + /// + /// ctor + /// + public ExchangeResult( + string exchange, + T result) : + base(result, null, null) + { + Exchange = exchange; + } + /// public override string ToString() => $"{Exchange} - " + base.ToString(); }