mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2026-04-13 00:22:22 +00:00
Updated WebSocket message routing improving performance for scenarios with multiple different subscriptions and topics Added AddCommaSeparated helper for Enum value arrays to ParameterCollection Improved EnumConverter performance and removed string allocation for happy path Fixed CreateParamString extension method for ArrayParametersSerialization.Json Fixed Shared GetOrderBookOptions and GetRecentTradeOptions base validations not being called
71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using CryptoExchange.Net.Objects;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace CryptoExchange.Net.SharedApis
|
|
{
|
|
/// <summary>
|
|
/// Options for requesting order book
|
|
/// </summary>
|
|
public class GetOrderBookOptions : EndpointOptions<GetOrderBookRequest>
|
|
{
|
|
/// <summary>
|
|
/// Supported order book depths
|
|
/// </summary>
|
|
public int[]? SupportedLimits { get; set; }
|
|
|
|
/// <summary>
|
|
/// The min order book depth
|
|
/// </summary>
|
|
public int? MinLimit { get; set; }
|
|
/// <summary>
|
|
/// The max order book depth
|
|
/// </summary>
|
|
public int? MaxLimit { get; set; }
|
|
|
|
/// <summary>
|
|
/// ctor
|
|
/// </summary>
|
|
public GetOrderBookOptions(int minLimit, int maxLimit, bool authenticated) : base(authenticated)
|
|
{
|
|
MinLimit = minLimit;
|
|
MaxLimit = maxLimit;
|
|
}
|
|
|
|
/// <summary>
|
|
/// ctor
|
|
/// </summary>
|
|
public GetOrderBookOptions(int[] supportedLimits, bool authenticated) : base(authenticated)
|
|
{
|
|
SupportedLimits = supportedLimits;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override Error? ValidateRequest(string exchange, GetOrderBookRequest request, TradingMode? tradingMode, TradingMode[] supportedApiTypes)
|
|
{
|
|
if (request.Limit == null)
|
|
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
|
|
|
|
if (MaxLimit.HasValue && request.Limit.Value > MaxLimit)
|
|
return ArgumentError.Invalid(nameof(GetOrderBookRequest.Limit), $"Max limit is {MaxLimit}");
|
|
|
|
if (MinLimit.HasValue && request.Limit.Value < MinLimit)
|
|
return ArgumentError.Invalid(nameof(GetOrderBookRequest.Limit), $"Min limit is {MaxLimit}");
|
|
|
|
if (SupportedLimits != null && !SupportedLimits.Contains(request.Limit.Value))
|
|
return ArgumentError.Invalid(nameof(GetOrderBookRequest.Limit), $"Limit should be one of " + string.Join(", ", SupportedLimits));
|
|
|
|
return base.ValidateRequest(exchange, request, tradingMode, supportedApiTypes);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override string ToString(string exchange)
|
|
{
|
|
var sb = new StringBuilder(base.ToString(exchange));
|
|
sb.AppendLine($"Supported limit values: [{(SupportedLimits != null ? string.Join(", ", SupportedLimits) : $"{MinLimit}..{MaxLimit}")}]");
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|