mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-08-31 12:42:00 +00:00
Updated Shared symbol requests/subscriptions to allow multiple symbols in one call if supported
This commit is contained in:
parent
ad599badb2
commit
2f82e2015b
@ -23,14 +23,14 @@ namespace CryptoExchange.Net
|
||||
{
|
||||
if(!_symbolInfos.TryGetValue(topicId, out var exchangeInfo))
|
||||
{
|
||||
exchangeInfo = new ExchangeInfo(DateTime.UtcNow, updateData.ToDictionary(x => x.Name, x => new SharedSymbol(x.TradingMode, x.BaseAsset.ToUpperInvariant(), x.QuoteAsset.ToUpperInvariant(), (x as SharedFuturesSymbol)?.DeliveryTime) { SymbolName = x.Name }));
|
||||
exchangeInfo = new ExchangeInfo(DateTime.UtcNow, updateData.ToDictionary(x => x.Name, x => x.SharedSymbol));
|
||||
_symbolInfos.TryAdd(topicId, exchangeInfo);
|
||||
}
|
||||
|
||||
if (DateTime.UtcNow - exchangeInfo.UpdateTime < TimeSpan.FromMinutes(60))
|
||||
return;
|
||||
|
||||
_symbolInfos[topicId] = new ExchangeInfo(DateTime.UtcNow, updateData.ToDictionary(x => x.Name, x => new SharedSymbol(x.TradingMode, x.BaseAsset.ToUpperInvariant(), x.QuoteAsset.ToUpperInvariant(), (x as SharedFuturesSymbol)?.DeliveryTime) { SymbolName = x.Name }));
|
||||
_symbolInfos[topicId] = new ExchangeInfo(DateTime.UtcNow, updateData.ToDictionary(x => x.Name, x => x.SharedSymbol));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -109,6 +109,15 @@ namespace CryptoExchange.Net.SharedApis
|
||||
/// </summary>
|
||||
public List<ParameterDescription> RequiredOptionalParameters { get; set; } = new List<ParameterDescription>();
|
||||
|
||||
/// <summary>
|
||||
/// Whether this accepts multiple symbols (Only applicable to request requiring symbol parameters)
|
||||
/// </summary>
|
||||
public bool SupportsMultipleSymbols { get; set; } = false;
|
||||
/// <summary>
|
||||
/// The max number of symbols which can be passed in a call (Only applicable to request requiring symbol parameters)
|
||||
/// </summary>
|
||||
public int? MaxSymbolCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
@ -141,6 +150,19 @@ namespace CryptoExchange.Net.SharedApis
|
||||
|
||||
}
|
||||
|
||||
if (request is SharedSymbolRequest symbolsRequest)
|
||||
{
|
||||
if (symbolsRequest.Symbols != null)
|
||||
{
|
||||
if (!SupportsMultipleSymbols)
|
||||
return new ArgumentError($"Only a single symbol parameter is allowed, multiple symbols are not supported");
|
||||
|
||||
if (symbolsRequest.Symbols.Length > MaxSymbolCount)
|
||||
return new ArgumentError($"Max number of symbols is {MaxSymbolCount} but {symbolsRequest.Symbols.Length} were passed");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ValidateRequest(exchange, request.ExchangeParameters, tradingMode, supportedTradingModes);
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,27 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Symbol request
|
||||
/// </summary>
|
||||
public record SharedSymbolRequest : SharedRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Trading mode
|
||||
/// </summary>
|
||||
public TradingMode TradingMode { get; }
|
||||
/// <summary>
|
||||
/// The symbol
|
||||
/// </summary>
|
||||
public SharedSymbol Symbol { get; set; }
|
||||
public SharedSymbol? Symbol { get; set; }
|
||||
/// <summary>
|
||||
/// Symbols
|
||||
/// </summary>
|
||||
public SharedSymbol[]? Symbols { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
@ -16,6 +29,22 @@
|
||||
public SharedSymbolRequest(SharedSymbol symbol, ExchangeParameters? exchangeParameters = null) : base(exchangeParameters)
|
||||
{
|
||||
Symbol = symbol;
|
||||
TradingMode = symbol.TradingMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
public SharedSymbolRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) : base(exchangeParameters)
|
||||
{
|
||||
if (!symbols.Any())
|
||||
throw new ArgumentException("Empty symbol list");
|
||||
|
||||
if (symbols.GroupBy(x => x.TradingMode).Count() > 1)
|
||||
throw new ArgumentException("All symbols in the symbol list should have the same trading mode");
|
||||
|
||||
Symbols = symbols.ToArray();
|
||||
TradingMode = Symbols.First().TradingMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to subscribe to book ticker updates
|
||||
@ -13,5 +15,22 @@
|
||||
public SubscribeBookTickerRequest(SharedSymbol symbol, ExchangeParameters? exchangeParameters = null) : base(symbol, exchangeParameters)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
/// <param name="exchangeParameters">Exchange specific parameters</param>
|
||||
public SubscribeBookTickerRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) : base(symbols, exchangeParameters)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
public SubscribeBookTickerRequest(params SharedSymbol[] symbols) : base(symbols, null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to subscribe to kline/candlestick updates
|
||||
@ -20,5 +22,26 @@
|
||||
{
|
||||
Interval = interval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
/// <param name="interval">Kline interval</param>
|
||||
/// <param name="exchangeParameters">Exchange specific parameters</param>
|
||||
public SubscribeKlineRequest(IEnumerable<SharedSymbol> symbols, SharedKlineInterval interval, ExchangeParameters? exchangeParameters = null) : base(symbols, exchangeParameters)
|
||||
{
|
||||
Interval = interval;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="interval">Kline interval</param>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
public SubscribeKlineRequest(SharedKlineInterval interval, params SharedSymbol[] symbols) : base(symbols, null)
|
||||
{
|
||||
Interval = interval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to subscribe to order book snapshot updates
|
||||
@ -20,5 +22,22 @@
|
||||
{
|
||||
Limit = limit;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
/// <param name="exchangeParameters">Exchange specific parameters</param>
|
||||
public SubscribeOrderBookRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) : base(symbols, exchangeParameters)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
public SubscribeOrderBookRequest(params SharedSymbol[] symbols) : base(symbols, null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to subscribe to ticker updates
|
||||
@ -13,5 +16,22 @@
|
||||
public SubscribeTickerRequest(SharedSymbol symbol, ExchangeParameters? exchangeParameters = null) : base(symbol, exchangeParameters)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
/// <param name="exchangeParameters">Exchange specific parameters</param>
|
||||
public SubscribeTickerRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) : base(symbols, exchangeParameters)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
public SubscribeTickerRequest(params SharedSymbol[] symbols) : base(symbols, null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace CryptoExchange.Net.SharedApis
|
||||
{
|
||||
/// <summary>
|
||||
/// Request to subscribe to trade updates
|
||||
@ -13,5 +15,22 @@
|
||||
public SubscribeTradeRequest(SharedSymbol symbol, ExchangeParameters? exchangeParameters = null) : base(symbol, exchangeParameters)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
/// <param name="exchangeParameters">Exchange specific parameters</param>
|
||||
public SubscribeTradeRequest(IEnumerable<SharedSymbol> symbols, ExchangeParameters? exchangeParameters = null) : base(symbols, exchangeParameters)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ctor
|
||||
/// </summary>
|
||||
/// <param name="symbols">The symbols to subscribe to</param>
|
||||
public SubscribeTradeRequest(params SharedSymbol[] symbols) : base(symbols, null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,5 +30,8 @@ namespace CryptoExchange.Net.SharedApis
|
||||
public SharedFuturesSymbol(TradingMode symbolType, string baseAsset, string quoteAsset, string symbol, bool trading) : base(baseAsset, quoteAsset, symbol, trading, symbolType)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override SharedSymbol SharedSymbol => new SharedSymbol(TradingMode, BaseAsset.ToUpperInvariant(), QuoteAsset.ToUpperInvariant(), DeliveryTime) { SymbolName = Name };
|
||||
}
|
||||
}
|
||||
|
@ -69,5 +69,11 @@
|
||||
Name = symbol;
|
||||
Trading = trading;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The SharedSymbol of this symbol
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual SharedSymbol SharedSymbol => new SharedSymbol(TradingMode, BaseAsset.ToUpperInvariant(), QuoteAsset.ToUpperInvariant()) { SymbolName = Name };
|
||||
}
|
||||
}
|
||||
|
@ -864,7 +864,7 @@ namespace CryptoExchange.Net.Sockets
|
||||
{
|
||||
if (ApiClient.MessageSendSizeLimit != null && data.Length > ApiClient.MessageSendSizeLimit.Value)
|
||||
{
|
||||
var info = $"Message to send exceeds the max server message size ({ApiClient.MessageSendSizeLimit.Value} bytes). Split the request into batches to keep below this limit";
|
||||
var info = $"Message to send exceeds the max server message size ({data.Length} vs {ApiClient.MessageSendSizeLimit.Value} bytes). Split the request into batches to keep below this limit";
|
||||
_logger.LogWarning("[Sckt {SocketId}] [Req {RequestId}] {Info}", SocketId, requestId, info);
|
||||
return new CallResult(new InvalidOperationError(info));
|
||||
}
|
||||
@ -899,7 +899,7 @@ namespace CryptoExchange.Net.Sockets
|
||||
{
|
||||
if (ApiClient.MessageSendSizeLimit != null && data.Length > ApiClient.MessageSendSizeLimit.Value)
|
||||
{
|
||||
var info = $"Message to send exceeds the max server message size ({ApiClient.MessageSendSizeLimit.Value} bytes). Split the request into batches to keep below this limit";
|
||||
var info = $"Message to send exceeds the max server message size ({data.Length} vs {ApiClient.MessageSendSizeLimit.Value} bytes). Split the request into batches to keep below this limit";
|
||||
_logger.LogWarning("[Sckt {SocketId}] [Req {RequestId}] {Info}", SocketId, requestId, info);
|
||||
return new CallResult(new InvalidOperationError(info));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user