mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-11 08:22:53 +00:00
Shared asset and symbol types
Added SpotSymbolCatalog to Shared ISpotSymbolRestClient interface Added FuturesSymbolCatalog to Shared IFuturesSymbolRestClient interface Added BaseAssetType, BaseAssetSubType, QuoteAssetType and QuoteAssetSubType to GetSymbolsRequest model Added DisplayName to SharedSpotSymbol and SharedFuturesSymbol models Added BaseAssetType, BaseAssetSubType, QuoteAssetType and QuoteAssetSubType to SharedSpotSymbol and SharedFuturesSymbol models Added IsStableCoin, IsCommodity and IsEquity helper methods to LibraryHelpers
This commit is contained in:
@@ -33,7 +33,7 @@ namespace CryptoExchange.Net
|
|||||||
if (keyedCache != null && DateTime.UtcNow - keyedCache.UpdateTime < TimeSpan.FromMinutes(60))
|
if (keyedCache != null && DateTime.UtcNow - keyedCache.UpdateTime < TimeSpan.FromMinutes(60))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
exchangeInfo.Set(key, new ExchangeInfo(DateTime.UtcNow, updateData.ToDictionary(x => x.Name, x => x.SharedSymbol)));
|
exchangeInfo.Set(key, new ExchangeInfo(DateTime.UtcNow, updateData.ToDictionary(x => x.Name, x => x)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -118,6 +118,22 @@ namespace CryptoExchange.Net
|
|||||||
return exchangeInfo.ParseSymbol(key, symbolName);
|
return exchangeInfo.ParseSymbol(key, symbolName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a symbol catalog for a specific exchange(topic) and environment. Only available if <see cref="UpdateSymbolInfo(string, string, string?, SharedSpotSymbol[])"/> has been called previously.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exchange">Exchange name</param>
|
||||||
|
/// <param name="topicId">Id for the provided data</param>
|
||||||
|
/// <param name="environmentName">Trade environment</param>
|
||||||
|
/// <param name="key">Additional data set identification key</param>
|
||||||
|
public static SharedSymbolCatalog? GetSymbolCatalog(string exchange, string topicId, string environmentName, string? key)
|
||||||
|
{
|
||||||
|
var id = topicId + environmentName;
|
||||||
|
if (!_symbolInfos.TryGetValue(id, out var exchangeInfo))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return exchangeInfo.GetSymbolCatalog(exchange, key);
|
||||||
|
}
|
||||||
|
|
||||||
class ExchangeKeyedCache
|
class ExchangeKeyedCache
|
||||||
{
|
{
|
||||||
private ExchangeInfo? _noKeyCache;
|
private ExchangeInfo? _noKeyCache;
|
||||||
@@ -163,7 +179,7 @@ namespace CryptoExchange.Net
|
|||||||
|
|
||||||
public SharedSymbol? ParseSymbol(string? key, string symbolName)
|
public SharedSymbol? ParseSymbol(string? key, string symbolName)
|
||||||
{
|
{
|
||||||
SharedSymbol? symbolInfo = null;
|
SharedSpotSymbol? symbolInfo = null;
|
||||||
if (key == null)
|
if (key == null)
|
||||||
{
|
{
|
||||||
if (_noKeyCache != null)
|
if (_noKeyCache != null)
|
||||||
@@ -173,7 +189,7 @@ namespace CryptoExchange.Net
|
|||||||
|
|
||||||
return new SharedSymbol(symbolInfo.TradingMode, symbolInfo.BaseAsset, symbolInfo.QuoteAsset, symbolName)
|
return new SharedSymbol(symbolInfo.TradingMode, symbolInfo.BaseAsset, symbolInfo.QuoteAsset, symbolName)
|
||||||
{
|
{
|
||||||
DeliverTime = symbolInfo.DeliverTime
|
DeliverTime = (symbolInfo as SharedFuturesSymbol)?.DeliveryTime
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +199,7 @@ namespace CryptoExchange.Net
|
|||||||
{
|
{
|
||||||
return new SharedSymbol(symbolInfo.TradingMode, symbolInfo.BaseAsset, symbolInfo.QuoteAsset, symbolName)
|
return new SharedSymbol(symbolInfo.TradingMode, symbolInfo.BaseAsset, symbolInfo.QuoteAsset, symbolName)
|
||||||
{
|
{
|
||||||
DeliverTime = symbolInfo.DeliverTime
|
DeliverTime = (symbolInfo as SharedFuturesSymbol)?.DeliveryTime
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,7 +215,7 @@ namespace CryptoExchange.Net
|
|||||||
{
|
{
|
||||||
return new SharedSymbol(symbolInfo.TradingMode, symbolInfo.BaseAsset, symbolInfo.QuoteAsset, symbolName)
|
return new SharedSymbol(symbolInfo.TradingMode, symbolInfo.BaseAsset, symbolInfo.QuoteAsset, symbolName)
|
||||||
{
|
{
|
||||||
DeliverTime = symbolInfo.DeliverTime
|
DeliverTime = (symbolInfo as SharedFuturesSymbol)?.DeliveryTime
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +281,7 @@ namespace CryptoExchange.Net
|
|||||||
{
|
{
|
||||||
return _noKeyCache.Symbols
|
return _noKeyCache.Symbols
|
||||||
.Where(x => x.Value.BaseAsset.Equals(baseAsset, StringComparison.InvariantCultureIgnoreCase))
|
.Where(x => x.Value.BaseAsset.Equals(baseAsset, StringComparison.InvariantCultureIgnoreCase))
|
||||||
.Select(x => x.Value)
|
.Select(x => x.Value.SharedSymbol)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +290,7 @@ namespace CryptoExchange.Net
|
|||||||
{
|
{
|
||||||
result.AddRange(cache.Symbols
|
result.AddRange(cache.Symbols
|
||||||
.Where(x => x.Value.BaseAsset.Equals(baseAsset, StringComparison.InvariantCultureIgnoreCase))
|
.Where(x => x.Value.BaseAsset.Equals(baseAsset, StringComparison.InvariantCultureIgnoreCase))
|
||||||
.Select(x => x.Value));
|
.Select(x => x.Value.SharedSymbol));
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
@@ -286,18 +302,63 @@ namespace CryptoExchange.Net
|
|||||||
|
|
||||||
return exchangeInfo.Symbols
|
return exchangeInfo.Symbols
|
||||||
.Where(x => x.Value.BaseAsset.Equals(baseAsset, StringComparison.InvariantCultureIgnoreCase))
|
.Where(x => x.Value.BaseAsset.Equals(baseAsset, StringComparison.InvariantCultureIgnoreCase))
|
||||||
.Select(x => x.Value)
|
.Select(x => x.Value.SharedSymbol)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal SharedSymbolCatalog? GetSymbolCatalog(string exchange, string? key)
|
||||||
|
{
|
||||||
|
IEnumerable<SharedSpotSymbol> cachedSymbols;
|
||||||
|
if (key == null)
|
||||||
|
{
|
||||||
|
if (_noKeyCache != null)
|
||||||
|
cachedSymbols = _noKeyCache.Symbols.Values;
|
||||||
|
else
|
||||||
|
cachedSymbols = _keyedCache.Values.SelectMany(x => x.Symbols.Values);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!_keyedCache.TryGetValue(key, out var exchangeInfo) || exchangeInfo == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
cachedSymbols = exchangeInfo.Symbols.Values;
|
||||||
|
}
|
||||||
|
|
||||||
|
var assets = new Dictionary<string, SharedAssetInfo>();
|
||||||
|
var symbols = new Dictionary<string, SharedSpotSymbol>();
|
||||||
|
foreach (var symbol in cachedSymbols)
|
||||||
|
{
|
||||||
|
if (!assets.TryGetValue(symbol.BaseAsset, out var baseAssetInfo))
|
||||||
|
{
|
||||||
|
baseAssetInfo = new SharedAssetInfo(symbol.BaseAsset, symbol.BaseAssetType, symbol.BaseAssetSubType);
|
||||||
|
assets.Add(symbol.BaseAsset, baseAssetInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!assets.TryGetValue(symbol.QuoteAsset, out var quoteAssetInfo))
|
||||||
|
{
|
||||||
|
quoteAssetInfo = new SharedAssetInfo(symbol.QuoteAsset, symbol.QuoteAssetType, symbol.QuoteAssetSubType);
|
||||||
|
assets.Add(symbol.QuoteAsset, quoteAssetInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
symbols.Add(symbol.Name, symbol);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new SharedSymbolCatalog
|
||||||
|
{
|
||||||
|
Exchange = exchange,
|
||||||
|
Assets = assets,
|
||||||
|
Symbols = symbols
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ExchangeInfo
|
class ExchangeInfo
|
||||||
{
|
{
|
||||||
public DateTime UpdateTime { get; set; }
|
public DateTime UpdateTime { get; set; }
|
||||||
public Dictionary<string, SharedSymbol> Symbols { get; set; }
|
public Dictionary<string, SharedSpotSymbol> Symbols { get; set; }
|
||||||
|
|
||||||
public ExchangeInfo(DateTime updateTime, Dictionary<string, SharedSymbol> symbols)
|
public ExchangeInfo(DateTime updateTime, Dictionary<string, SharedSpotSymbol> symbols)
|
||||||
{
|
{
|
||||||
UpdateTime = updateTime;
|
UpdateTime = updateTime;
|
||||||
Symbols = symbols;
|
Symbols = symbols;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using CryptoExchange.Net.Objects.Options;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO.Pipelines;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
|
||||||
@@ -14,6 +16,61 @@ namespace CryptoExchange.Net
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class LibraryHelpers
|
public static class LibraryHelpers
|
||||||
{
|
{
|
||||||
|
private static readonly HashSet<string> _stableCoins = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
// USD
|
||||||
|
"USDT", "USDC", "DAI", "FDUSD", "USDE", "TUSD", "USDP", "PYUSD", "GUSD",
|
||||||
|
"USDD", "LUSD", "USDJ", "SUSD", "ZUSD", "BUSD", "USTC", "USDX", "USDK",
|
||||||
|
"CUSD", "USD1", "USD0", "XUSD", "BFUSD", "USDS", "RLUSD", "OUSD", "USDH",
|
||||||
|
"APXUSD", "USDQ", "USDPT", "FIDD", "AUSD",
|
||||||
|
// EUR
|
||||||
|
"EURS", "EURC", "EURI", "EURT", "AGEUR", "CEUR", "AEUR", "EURQ", "EUROP",
|
||||||
|
// Other
|
||||||
|
"CNYT", // CNY
|
||||||
|
"CREAL", "BRL1", // BRL
|
||||||
|
"XSGD", // SGD
|
||||||
|
"GYEN", // JPY
|
||||||
|
"KGST", // KGS
|
||||||
|
"QCAD", // CAD
|
||||||
|
"TGBP", // GBP
|
||||||
|
"AUDX", // AUD
|
||||||
|
"MXNB", // MXN
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly HashSet<string> _commodities = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
// Metals
|
||||||
|
"XAU", "XAUT", "XAG", "XPT", "XPD", "COPPER", "PAXG", "XNI", "XCU", "XAL", "GOLD", "SILVER",
|
||||||
|
// Energy
|
||||||
|
"BZ", "NATGAS", "NGAS", "CL", "XTI", "UKOIL", "USOIL", "BRENTOIL"
|
||||||
|
};
|
||||||
|
|
||||||
|
private static readonly HashSet<string> _stocks = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||||
|
{
|
||||||
|
// Top stocks, will need to update periodically
|
||||||
|
"AAAU", "AADR", "AAPL", "ACWI", "ACWX", "AGG", "AMD", "AMLP", "AMZN", "ARKF",
|
||||||
|
"ARKG", "ARKK", "ARKQ", "ARKW", "AVGO", "BA", "BABA", "BND", "BNDX", "BOTZ",
|
||||||
|
"CIBR", "COIN", "DIA", "DIVB", "DVY", "EEM", "EFA", "EFAV", "ESGU", "EWG",
|
||||||
|
"EWJ", "EWT", "EWU", "EWW", "EWY", "EWZ", "FDN", "FEZ", "GLDM", "GOOGL",
|
||||||
|
"HDV", "HOOD", "HYG", "IAU", "IBB", "ICLN", "IEFA", "IEMG", "IGSB", "IJH",
|
||||||
|
"IJR", "INTC", "ITOT", "IUSB", "IUSG", "IUSV", "IWM", "IWO", "IWR", "IYR",
|
||||||
|
"JETS", "JPM", "LIT", "MCHI", "META", "MGK", "MSTR", "MTUM", "MU", "NET",
|
||||||
|
"NFLX", "NOBL", "NVDA", "OIH", "ORCL", "PAVE", "PBW", "PLTR", "QQQ", "QQQM",
|
||||||
|
"SCHB", "SCHD", "SCHF", "SCHG", "SCHH", "SCHV", "SCHX", "SKHY", "SPCX", "SPCXD",
|
||||||
|
"SPLG", "SPY", "SPYG", "SPYV", "SQQQ", "TSLA", "TSM", "TQQQ", "USMV", "VBR",
|
||||||
|
"VCIT", "VCSH", "VEA", "VEU", "VGIT", "VGK", "VGT", "VHT", "VIG", "VNQ",
|
||||||
|
"VOO", "VOT", "VTI", "VTV", "VUG", "VXUS", "XBI", "XLC", "XLE", "XLF",
|
||||||
|
"XLI", "XLK", "XLP", "XLU", "XLV", "XLY", "CSCO", "UBER", "MRVL", "RKLB",
|
||||||
|
"COHR", "SOXL", "HD", "DIS", "CBRS", "V", "BRKB", "FLNC", "LLY", "COST",
|
||||||
|
"ARM", "BMNR", "NBIS", "ASML", "AAOI", "GLW", "SHLD", "BE", "QNTX", "IBM",
|
||||||
|
"AMAT", "NOK", "ASTS", "BBX", "SLX", "SKHYNIX", "SAMSUNG", "HYUNDAI", "NVO",
|
||||||
|
"IREN", "ONDS", "CRM" , "VRT", "ZEST", "BTW", "HPE", "AXTI", "BX", "CRWD",
|
||||||
|
"CRDO", "NOW", "ZM", "DKNG", "RIVN", "URNM", "EBAY", "ADBE", "UVXY", "RDW",
|
||||||
|
"CIEN","PANW", "WIN", "PAYP", "HIMS", "CRWV", "QCOM", "LITE", "DRAM", "ANTHROPIC",
|
||||||
|
"OPENAI", "USAR", "BILL", "SNDK", "NASDAQ100", "SPX500", "BSB", "CRCL", "STRC",
|
||||||
|
"MSFT", "WDC"
|
||||||
|
};
|
||||||
|
|
||||||
private static ILogger? _staticLogger;
|
private static ILogger? _staticLogger;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Static logger
|
/// Static logger
|
||||||
@@ -105,6 +162,67 @@ namespace CryptoExchange.Net
|
|||||||
return _defaultClientReferences.TryGetValue(key, out var id) ? id : throw new KeyNotFoundException($"{exchange} not found in configuration");
|
return _defaultClientReferences.TryGetValue(key, out var id) ? id : throw new KeyNotFoundException($"{exchange} not found in configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check whether an asset is a known stablecoin. Note that this is not definitive, only large known stocks are checked
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset">Asset name</param>
|
||||||
|
/// <param name="additionalStableCoins">Additional stablecoin names for the specific exchange</param>
|
||||||
|
public static bool IsStableCoin(string asset, params HashSet<string> additionalStableCoins)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(asset))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return _stableCoins.Contains(asset) || (additionalStableCoins != null && additionalStableCoins.Contains(asset, StringComparer.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check whether an asset is a known commodity. Note that this is not definitive, only large known stocks are checked
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset">Asset name</param>
|
||||||
|
/// <param name="additionalCommodities">Additional commodity names for the specific exchange</param>
|
||||||
|
public static bool IsCommodity(string asset, params HashSet<string> additionalCommodities)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(asset))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return _commodities.Contains(asset) || (additionalCommodities != null && additionalCommodities.Contains(asset, StringComparer.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check whether an asset is a known stock. Note that this is not definitive, only large known stocks are checked
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset">Asset name</param>
|
||||||
|
/// <param name="additionalStocks">Additional stock names for the specific exchange</param>
|
||||||
|
public static bool IsEquity(string asset, params HashSet<string> additionalStocks)
|
||||||
|
=> IsEquity(asset, [], additionalStocks);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check whether an asset is a known stock.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="asset">Asset name</param>
|
||||||
|
/// <param name="potentialSuffixes">Suffixes to check, for example when `X` is a potential suffix both `TSLA` and `TSLAX` will be checked</param>
|
||||||
|
/// <param name="additionalStocks">Additional stock names for the specific exchange</param>
|
||||||
|
public static bool IsEquity(string asset, string[] potentialSuffixes, params HashSet<string> additionalStocks)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(asset))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (_stocks.Contains(asset) || (additionalStocks != null && additionalStocks.Contains(asset, StringComparer.OrdinalIgnoreCase)))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
foreach (var suffix in potentialSuffixes)
|
||||||
|
{
|
||||||
|
if (!asset.EndsWith(suffix))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var suffixAsset = asset.Substring(0, asset.Length - suffix.Length);
|
||||||
|
if (_stocks.Contains(suffixAsset) || (additionalStocks != null && additionalStocks.Contains(suffixAsset, StringComparer.OrdinalIgnoreCase)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new HttpMessageHandler instance
|
/// Create a new HttpMessageHandler instance
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace CryptoExchange.Net.SharedApis
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Asset type
|
||||||
|
/// </summary>
|
||||||
|
public enum SharedAssetType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Unknown or unspecified asset type
|
||||||
|
/// </summary>
|
||||||
|
Unspecified,
|
||||||
|
/// <summary>
|
||||||
|
/// Cryptocurrency asset type
|
||||||
|
/// </summary>
|
||||||
|
Crypto,
|
||||||
|
/// <summary>
|
||||||
|
/// Fiat currency asset type
|
||||||
|
/// </summary>
|
||||||
|
Fiat,
|
||||||
|
/// <summary>
|
||||||
|
/// Traditional finance asset type
|
||||||
|
/// </summary>
|
||||||
|
TradFi
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asset sub type
|
||||||
|
/// </summary>
|
||||||
|
public enum SharedAssetSubType
|
||||||
|
{
|
||||||
|
// --- Crypto sub types ---
|
||||||
|
/// <summary>
|
||||||
|
/// Stable coin, can be for different fiat currencies
|
||||||
|
/// </summary>
|
||||||
|
StableCoin,
|
||||||
|
|
||||||
|
// --- TradFi sub types ---
|
||||||
|
/// <summary>
|
||||||
|
/// Equity, can be stocks, ETFs, or indices
|
||||||
|
/// </summary>
|
||||||
|
Equity,
|
||||||
|
/// <summary>
|
||||||
|
/// Commodity, can be oil, gas, metals, etc.
|
||||||
|
/// </summary>
|
||||||
|
Commodity
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,11 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IFuturesSymbolRestClient : ISharedClient
|
public interface IFuturesSymbolRestClient : ISharedClient
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get the futures symbol catalog. Only available if <see cref="GetFuturesSymbolsAsync(GetSymbolsRequest, CancellationToken)"/> has been called previously.
|
||||||
|
/// </summary>
|
||||||
|
SharedSymbolCatalog? FuturesSymbolCatalog { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Futures symbol request options.<br />
|
/// Futures symbol request options.<br />
|
||||||
/// Use <see cref="EndpointOptions.RequiredExchangeParameters"/> and <see cref="EndpointOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br />
|
/// Use <see cref="EndpointOptions.RequiredExchangeParameters"/> and <see cref="EndpointOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br />
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ISpotSymbolRestClient : ISharedClient
|
public interface ISpotSymbolRestClient : ISharedClient
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get the spot symbol catalog. Only available if <see cref="GetSpotSymbolsAsync(GetSymbolsRequest, CancellationToken)"/> has been called previously.
|
||||||
|
/// </summary>
|
||||||
|
SharedSymbolCatalog? SpotSymbolCatalog { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Spot symbols request options.<br />
|
/// Spot symbols request options.<br />
|
||||||
/// Use <see cref="EndpointOptions.RequiredExchangeParameters"/> and <see cref="EndpointOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br />
|
/// Use <see cref="EndpointOptions.RequiredExchangeParameters"/> and <see cref="EndpointOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using CryptoExchange.Net.Objects;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -15,5 +16,43 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
public GetFuturesSymbolsOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IFuturesSymbolRestClient.GetFuturesSymbolsAsync))
|
public GetFuturesSymbolsOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IFuturesSymbolRestClient.GetFuturesSymbolsAsync))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Error? ValidateRequest(GetSymbolsRequest request, IFuturesSymbolRestClient client)
|
||||||
|
{
|
||||||
|
if (request.BaseAssetType != null && request.BaseAssetSubType != null)
|
||||||
|
{
|
||||||
|
var error = ValidateAssetTypeCombination(request.BaseAssetType.Value, request.BaseAssetSubType.Value);
|
||||||
|
if (error != null)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.QuoteAssetType != null && request.QuoteAssetSubType != null)
|
||||||
|
{
|
||||||
|
var error = ValidateAssetTypeCombination(request.QuoteAssetType.Value, request.QuoteAssetSubType.Value);
|
||||||
|
if (error != null)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.ValidateRequest(request, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Error? ValidateAssetTypeCombination(SharedAssetType type, SharedAssetSubType subType)
|
||||||
|
{
|
||||||
|
if (type == SharedAssetType.Crypto
|
||||||
|
&& (subType == SharedAssetSubType.Commodity
|
||||||
|
|| (subType == SharedAssetSubType.Equity)))
|
||||||
|
{
|
||||||
|
return ArgumentError.Invalid(nameof(GetSymbolsRequest.BaseAssetSubType), $"Invalid combination of asset type filters: {type} and {subType}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == SharedAssetType.TradFi && subType == SharedAssetSubType.StableCoin)
|
||||||
|
return ArgumentError.Invalid(nameof(GetSymbolsRequest.BaseAssetSubType), $"Invalid combination of asset type filters: {type} and {subType}");
|
||||||
|
|
||||||
|
if (type == SharedAssetType.Fiat)
|
||||||
|
return ArgumentError.Invalid(nameof(GetSymbolsRequest.BaseAssetSubType), $"Invalid combination of asset type filters: {type} and {subType}");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using CryptoExchange.Net.Objects;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -15,5 +16,44 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
public GetSpotSymbolsOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(ISpotSymbolRestClient.GetSpotSymbolsAsync))
|
public GetSpotSymbolsOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(ISpotSymbolRestClient.GetSpotSymbolsAsync))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Error? ValidateRequest(GetSymbolsRequest request, ISpotSymbolRestClient client)
|
||||||
|
{
|
||||||
|
if (request.BaseAssetType != null && request.BaseAssetSubType != null)
|
||||||
|
{
|
||||||
|
var error = ValidateAssetTypeCombination(request.BaseAssetType.Value, request.BaseAssetSubType.Value);
|
||||||
|
if (error != null)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.QuoteAssetType != null && request.QuoteAssetSubType != null)
|
||||||
|
{
|
||||||
|
var error = ValidateAssetTypeCombination(request.QuoteAssetType.Value, request.QuoteAssetSubType.Value);
|
||||||
|
if (error != null)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base.ValidateRequest(request, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Error? ValidateAssetTypeCombination(SharedAssetType type, SharedAssetSubType subType)
|
||||||
|
{
|
||||||
|
if (type == SharedAssetType.Crypto
|
||||||
|
&& (subType == SharedAssetSubType.Commodity
|
||||||
|
|| (subType == SharedAssetSubType.Equity)))
|
||||||
|
{
|
||||||
|
return ArgumentError.Invalid(nameof(GetSymbolsRequest.BaseAssetSubType), $"Invalid combination of asset type filters: {type} and {subType}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == SharedAssetType.TradFi && subType == SharedAssetSubType.StableCoin)
|
||||||
|
return ArgumentError.Invalid(nameof(GetSymbolsRequest.BaseAssetSubType), $"Invalid combination of asset type filters: {type} and {subType}");
|
||||||
|
|
||||||
|
if (type == SharedAssetType.Fiat)
|
||||||
|
return ArgumentError.Invalid(nameof(GetSymbolsRequest.BaseAssetSubType), $"Invalid combination of asset type filters: {type} and {subType}");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,44 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public record GetSymbolsRequest : SharedRequest
|
public record GetSymbolsRequest : SharedRequest
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base asset type filter
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetType? BaseAssetType { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Base asset subtype filter
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetSubType? BaseAssetSubType { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Quote asset type filter
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetType? QuoteAssetType { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Quote asset subtype filter
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetSubType? QuoteAssetSubType { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tradingMode">Trading mode filter</param>
|
/// <param name="tradingMode">Trading mode filter</param>
|
||||||
|
/// <param name="baseAssetType">Filter by base asset type</param>
|
||||||
|
/// <param name="baseAssetSubType">Filter by base asset subtype</param>
|
||||||
|
/// <param name="quoteAssetType">Filter by quote asset type</param>
|
||||||
|
/// <param name="quoteAssetSubType">Filter by quote asset subtype</param>
|
||||||
/// <param name="exchangeParameters">Exchange specific parameters</param>
|
/// <param name="exchangeParameters">Exchange specific parameters</param>
|
||||||
public GetSymbolsRequest(TradingMode? tradingMode = null, ExchangeParameters? exchangeParameters = null) : base(tradingMode, exchangeParameters)
|
public GetSymbolsRequest(
|
||||||
|
TradingMode? tradingMode = null,
|
||||||
|
SharedAssetType? baseAssetType = null,
|
||||||
|
SharedAssetSubType? baseAssetSubType = null,
|
||||||
|
SharedAssetType? quoteAssetType = null,
|
||||||
|
SharedAssetSubType? quoteAssetSubType = null,
|
||||||
|
ExchangeParameters? exchangeParameters = null) : base(tradingMode, exchangeParameters)
|
||||||
{
|
{
|
||||||
|
BaseAssetType = baseAssetType;
|
||||||
|
BaseAssetSubType = baseAssetSubType;
|
||||||
|
QuoteAssetType = quoteAssetType;
|
||||||
|
QuoteAssetSubType = quoteAssetSubType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace CryptoExchange.Net.SharedApis
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Symbol and asset catalog for a shared client
|
||||||
|
/// </summary>
|
||||||
|
public class SharedSymbolCatalog
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Exchange name
|
||||||
|
/// </summary>
|
||||||
|
public string Exchange { get; set; } = string.Empty;
|
||||||
|
/// <summary>
|
||||||
|
/// Assets supported
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyDictionary<string, SharedAssetInfo> Assets { get; set; } = new Dictionary<string, SharedAssetInfo>();
|
||||||
|
/// <summary>
|
||||||
|
/// Symbols supported
|
||||||
|
/// </summary>
|
||||||
|
public IReadOnlyDictionary<string, SharedSpotSymbol> Symbols { get; set; } = new Dictionary<string, SharedSpotSymbol>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asset info
|
||||||
|
/// </summary>
|
||||||
|
[DebuggerDisplay("{DebugView,nq}")]
|
||||||
|
public class SharedAssetInfo
|
||||||
|
{
|
||||||
|
private string DebugView => $"{Name} - {Type}{(SubType == null ? "": $" {SubType}")}";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Asset name
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Asset type
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetType Type { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Asset sub type
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetSubType? SubType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ctor
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetInfo(string name, SharedAssetType type, SharedAssetSubType? subType)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Type = type;
|
||||||
|
SubType = subType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
[DebuggerDisplay("{DebugView,nq}")]
|
[DebuggerDisplay("{DebugView,nq}")]
|
||||||
public record SharedFuturesSymbol : SharedSpotSymbol
|
public record SharedFuturesSymbol : SharedSpotSymbol
|
||||||
{
|
{
|
||||||
private string DebugView => $"{TradingMode} {Name}{(DeliveryTime != null ? $" Delivery: {DeliveryTime:yyyy-MM-dd}": "")}";
|
private string DebugView => $"{TradingMode} {(DisplayName ?? Name)} - {BaseAssetType}{(BaseAssetSubType == null ? "" : " " + BaseAssetSubType)}{(DeliveryTime != null ? $" Delivery: {DeliveryTime:yyyy-MM-dd}": "")}";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The size of a single contract
|
/// The size of a single contract
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
using System.Diagnostics;
|
using System;
|
||||||
|
using System.Data;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace CryptoExchange.Net.SharedApis
|
namespace CryptoExchange.Net.SharedApis
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Symbol info
|
/// Symbol info
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DebuggerDisplay("{TradingMode} {Name,nq}")]
|
[DebuggerDisplay("{DebugView,nq}")]
|
||||||
public record SharedSpotSymbol
|
public record SharedSpotSymbol
|
||||||
{
|
{
|
||||||
|
private string DebugView => $"{TradingMode} {(DisplayName ?? Name)} - {BaseAssetType} {BaseAssetSubType}";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The trading mode of the symbol
|
/// The trading mode of the symbol
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -25,6 +29,10 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// The display name of the symbol
|
||||||
|
/// </summary>
|
||||||
|
public string? DisplayName { get; set; }
|
||||||
|
/// <summary>
|
||||||
/// Minimal quantity of an order in the base asset
|
/// Minimal quantity of an order in the base asset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public decimal? MinTradeQuantity { get; set; }
|
public decimal? MinTradeQuantity { get; set; }
|
||||||
@@ -60,6 +68,22 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
/// Whether the symbol is currently available for trading
|
/// Whether the symbol is currently available for trading
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Trading { get; set; }
|
public bool Trading { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Base asset type
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetType BaseAssetType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Base asset sub type
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetSubType? BaseAssetSubType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Quote asset type
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetType QuoteAssetType { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Quote asset sub type
|
||||||
|
/// </summary>
|
||||||
|
public SharedAssetSubType? QuoteAssetSubType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ctor
|
/// ctor
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using CryptoExchange.Net.Objects;
|
using CryptoExchange.Net.Objects;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace CryptoExchange.Net.SharedApis
|
namespace CryptoExchange.Net.SharedApis
|
||||||
{
|
{
|
||||||
@@ -176,5 +177,21 @@ namespace CryptoExchange.Net.SharedApis
|
|||||||
|
|
||||||
return result.ToArray();
|
return result.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static T[] ApplySymbolFilter<T>(T[] symbols, GetSymbolsRequest request) where T : SharedSpotSymbol
|
||||||
|
{
|
||||||
|
IEnumerable<T> resultData = symbols;
|
||||||
|
if (request.TradingMode != null)
|
||||||
|
resultData = resultData.Where(x => x.TradingMode == request.TradingMode);
|
||||||
|
if (request.BaseAssetType != null)
|
||||||
|
resultData = resultData.Where(x => x.BaseAssetType == request.BaseAssetType);
|
||||||
|
if (request.QuoteAssetType != null)
|
||||||
|
resultData = resultData.Where(x => x.QuoteAssetType == request.QuoteAssetType);
|
||||||
|
if (request.BaseAssetSubType != null)
|
||||||
|
resultData = resultData.Where(x => x.BaseAssetSubType == request.BaseAssetSubType);
|
||||||
|
if (request.QuoteAssetSubType != null)
|
||||||
|
resultData = resultData.Where(x => x.QuoteAssetSubType == request.QuoteAssetSubType);
|
||||||
|
return resultData.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user