mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-10-17 00:20:55 +00:00
Updated Shared symbol requests/subscriptions to allow multiple symbols in one call if supported
This commit is contained in:
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user