1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-10-14 07:01:46 +00:00
This commit is contained in:
JKorf
2026-09-05 20:28:11 +02:00
parent 431ef93611
commit f215b729ed
263 changed files with 1313 additions and 391 deletions
@@ -4,9 +4,18 @@ using System.Text;
namespace CryptoExchange.Net.SharedApis namespace CryptoExchange.Net.SharedApis
{ {
/// <summary>
/// The type of transport used for the shared API
/// </summary>
public record SharedTransport(string Name) public record SharedTransport(string Name)
{ {
/// <summary>
/// REST transport
/// </summary>
public static SharedTransport Rest { get; } = new("REST"); public static SharedTransport Rest { get; } = new("REST");
/// <summary>
/// WebSocket transport
/// </summary>
public static SharedTransport Socket { get; } = new("WebSocket"); public static SharedTransport Socket { get; } = new("WebSocket");
} }
} }
@@ -1,56 +0,0 @@
using System;
using System.Linq;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Parameter description
/// </summary>
public class ParameterDescription
{
/// <summary>
/// Possible names for the parameter. One of these names can be used to provide the parameter in the ExchangeParameters of the request.
/// </summary>
public string[] Names { get; set; }
/// <summary>
/// Type of the value
/// </summary>
public Type ValueType { get; set; }
/// <summary>
/// Parameter description
/// </summary>
public string Description { get; set; }
/// <summary>
/// Example value
/// </summary>
public object ExampleValue { get; set; }
/// <summary>
/// ctor
/// </summary>
public ParameterDescription(string parameterName, Type valueType, string description, object exampleValue)
{
Names = [parameterName];
ValueType = valueType;
Description = description;
ExampleValue = exampleValue;
}
/// <summary>
/// ctor
/// </summary>
public ParameterDescription(string[] parameterNames, Type valueType, string description, object exampleValue)
{
Names = parameterNames;
ValueType = valueType;
Description = description;
ExampleValue = exampleValue;
}
/// <inheritdoc />
public override string ToString()
{
return $"[{ValueType.Name}] {string.Join(" / ", Names.Select(x => $"\"{x}\""))}: {Description}";
}
}
}
@@ -13,26 +13,44 @@ namespace CryptoExchange.Net.SharedApis
/// </summary> /// </summary>
public abstract class CapabilityOptions public abstract class CapabilityOptions
{ {
private List<ParameterDescription> _requiredRequestParameters = new(); /// <summary>
/// Request parameter rules for the capability. The rules differ per exchange API and can be used to
/// dynamically discover and adjust the request parameters for a capability.
/// </summary>
public RequestParameterDescription[] RequestParameterRules { get; private set; } = [];
/// <summary>
/// Exchange parameter rules for the capability. These are parameters specific to the exchange API and
/// must be provided in the request via the ExchangeParameters property of the request object.
/// </summary>
public ExchangeParameterDescription[] ExchangeParameterRules { get; set; } = [];
private readonly RequestParameterDescription[] _defaultParameterRules;
/// <summary> /// <summary>
/// Request properties that are optional in the shared contract, /// Deprectaed, use RequestParameterRules instead.
/// but required by this exchange implementation.
/// </summary> /// </summary>
public List<ParameterDescription> RequiredRequestParameters public List<ParameterDescription> RequiredOptionalParameters
{ {
get => _requiredRequestParameters; get => RequestParameterRules.Where(x => x.DefaultSupport == RequestParameterSupport.Optional
set => _requiredRequestParameters = value; && x.Support == RequestParameterSupport.Required)
.Cast<ParameterDescription>()
.ToList();
} }
/// <summary> /// <summary>
/// Use RequiredRequestParameters instead. /// Deprectaed, use ExchangeParameterRules instead.
/// </summary> /// </summary>
[Obsolete("Use RequiredRequestParameters instead")] public List<ParameterDescription> RequiredExchangeParameters
public List<ParameterDescription> RequiredOptionalParameters
{ {
get => _requiredRequestParameters; get => ExchangeParameterRules.Where(x => x.Requirement == ExchangeParameterRequirement.Required).Cast<ParameterDescription>().ToList();
set => _requiredRequestParameters = value; }
/// <summary>
/// Deprectaed, use ExchangeParameterRules instead.
/// </summary>
public List<ParameterDescription> OptionalExchangeParameters
{
get => ExchangeParameterRules.Where(x => x.Requirement == ExchangeParameterRequirement.Optional).Cast<ParameterDescription>().ToList();
} }
/// <summary> /// <summary>
@@ -43,15 +61,6 @@ namespace CryptoExchange.Net.SharedApis
/// The max number of symbols which can be passed in a call (Only applicable to request requiring symbol parameters) /// The max number of symbols which can be passed in a call (Only applicable to request requiring symbol parameters)
/// </summary> /// </summary>
public int? MaxSymbolCount { get; set; } public int? MaxSymbolCount { get; set; }
/// <summary>
/// Required exchange-specific parameters. These can be provided via the `exchangeParameters` property of the request object.
/// </summary>
public List<ParameterDescription> RequiredExchangeParameters { get; set; } = new List<ParameterDescription>();
/// <summary>
/// Optional exchange-specific parameters. These can be provided via the `exchangeParameters` property of the request object.
/// </summary>
public List<ParameterDescription> OptionalExchangeParameters { get; set; } = new List<ParameterDescription>();
/// <summary> /// <summary>
/// Exchange /// Exchange
/// </summary> /// </summary>
@@ -84,11 +93,59 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public CapabilityOptions(string exchange, string operationName, bool needAuthentication) public CapabilityOptions(
string exchange,
string operationName,
bool needAuthentication,
IEnumerable<RequestParameterDescription> defaultParameterRules)
{ {
Exchange = exchange; Exchange = exchange;
OperationName = operationName; OperationName = operationName;
NeedsAuthentication = needAuthentication; NeedsAuthentication = needAuthentication;
_defaultParameterRules = defaultParameterRules
.Select(x => x.WithSupport(x.DefaultSupport))
.ToArray();
RequestParameterRules = CombineParameters(
_defaultParameterRules,
Array.Empty<RequestParameterRuleOverride>());
}
/// <summary>
/// Set request parameter overrides for this instance
/// </summary>
/// <param name="overrides">The parameter overrides</param>
protected void SetRequestParameters(IEnumerable<RequestParameterRuleOverride> overrides)
{
RequestParameterRules = CombineParameters(_defaultParameterRules, overrides);
}
private RequestParameterDescription[] CombineParameters(
RequestParameterDescription[] defaultParameters,
IEnumerable<RequestParameterRuleOverride> overrideParameters
)
{
var result = defaultParameters
.Select(x => x.WithSupport(x.DefaultSupport))
.ToList();
foreach (var item in overrideParameters)
{
var index = result.FindIndex(
x => x.Name == item.ParameterName);
if (index == -1)
{
throw new ArgumentException(
$"No default request parameter rule exists for " +
$"`{item.ParameterName}`");
}
result[index] = result[index].WithOverride(item);
}
return result.ToArray();
} }
/// <summary> /// <summary>
@@ -108,12 +165,13 @@ namespace CryptoExchange.Net.SharedApis
foreach (var param in RequiredExchangeParameters) foreach (var param in RequiredExchangeParameters)
{ {
if (param.Names!.All(x => ExchangeParameters.HasValue(exchangeParameters, Exchange, x, param.ValueType) != true)) if (ExchangeParameters.HasValue(exchangeParameters, Exchange, param.Name, param.ValueType) != true
&& param.Aliases.Any(x => ExchangeParameters.HasValue(exchangeParameters, Exchange, x, param.ValueType) != true))
{ {
if (param.Names.Length == 1) if (param.Aliases.Length == 0)
return ArgumentError.Invalid(string.Join("/", param.Names!), $"Exchange parameter `{param.Names[0]}` for exchange `{Exchange}` should be provided. Example: {param.ExampleValue}"); return ArgumentError.Invalid(param.Name, $"Exchange parameter `{param.Name}` for exchange `{Exchange}` should be provided. Example: {param.ExampleValue}");
else else
return ArgumentError.Invalid(string.Join("/", param.Names!), $"One of exchange parameters `{string.Join(", ", param.Names!)}` for exchange `{Exchange}` should be provided. Example: {param.ExampleValue}"); return ArgumentError.Invalid(string.Join("/", [param.Name, .. param.Aliases]), $"One of exchange parameters `{string.Join(", ", [param.Name, .. param.Aliases])}` for exchange `{Exchange}` should be provided. Example: {param.ExampleValue}");
} }
} }
@@ -137,22 +195,16 @@ namespace CryptoExchange.Net.SharedApis
sb.Append(" Notes: "); sb.Append(" Notes: ");
sb.AppendLine(RequestNotes); sb.AppendLine(RequestNotes);
} }
if (RequiredRequestParameters.Any()) if (RequestParameterRules.Any())
{ {
sb.AppendLine($" Required request parameters:"); sb.AppendLine($" Request parameters:");
foreach (var param in RequiredRequestParameters) foreach (var param in RequestParameterRules)
sb.AppendLine($" {param}"); sb.AppendLine($" {param}");
} }
if (RequiredExchangeParameters.Any()) if (ExchangeParameterRules.Any())
{ {
sb.AppendLine($" Required exchange specific parameters:"); sb.AppendLine($" Exchange specific parameters:");
foreach (var param in RequiredExchangeParameters) foreach (var param in ExchangeParameterRules)
sb.AppendLine($" {param}");
}
if (OptionalExchangeParameters.Any())
{
sb.AppendLine($" Optional exchange specific parameters:");
foreach (var param in OptionalExchangeParameters)
sb.AppendLine($" {param}"); sb.AppendLine($" {param}");
} }
sb.Append(" Needs authentication: "); sb.Append(" Needs authentication: ");
@@ -179,10 +231,17 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override Type CapabilityType => typeof(TCapability); public override Type CapabilityType => typeof(TCapability);
/// <inheritdoc />
public virtual RequestParameterRuleOverride[] ParameterRuleOverwrites
{
set => SetRequestParameters(value);
}
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public CapabilityOptions(string exchange, bool needsAuthentication, string requestName) : base(exchange, requestName, needsAuthentication) public CapabilityOptions(string exchange, bool needsAuthentication, string requestName, IEnumerable<RequestParameterDescription> defaultParameterRules)
: base(exchange, requestName, needsAuthentication, defaultParameterRules)
{ {
} }
@@ -197,14 +256,28 @@ namespace CryptoExchange.Net.SharedApis
if (NeedsAuthentication && !client.Authenticated) if (NeedsAuthentication && !client.Authenticated)
return new NoApiCredentialsError(); return new NoApiCredentialsError();
foreach (var param in RequiredRequestParameters) foreach (var param in RequestParameterRules)
{ {
if (param.Names!.All(x => _requestProperties.Single(p => p.Name == x).GetValue(request, null) == null)) var property = _requestProperties.Single(x => x.Name == param.Name);
var value = property.GetValue(request);
if (param.Support == RequestParameterSupport.Required)
{ {
if (param.Names.Length == 1) if (value == null)
return ArgumentError.Invalid(string.Join("/", param.Names!), $"Optional parameter `{param.Names[0]}` for exchange `{Exchange}` should be provided. Example: {param.ExampleValue}"); {
else return ArgumentError.Invalid(
return ArgumentError.Invalid(string.Join("/", param.Names!), $"One of optional parameters `{string.Join(", ", param.Names!)}` for exchange `{Exchange}` should be provided. Example: {param.ExampleValue}"); param.Name,
$"Request parameter `{param.Name}` for exchange `{Exchange}` is required and should be provided. Example: {param.ExampleValue}");
}
}
else if (param.Support == RequestParameterSupport.NotSupported)
{
if (value != null)
{
return ArgumentError.Invalid(
param.Name,
$"Request parameter `{param.Name}` is not supported by exchange `{Exchange}`");
}
} }
} }
@@ -30,8 +30,9 @@ namespace CryptoExchange.Net.SharedApis
protected EndpointOptions( protected EndpointOptions(
string exchange, string exchange,
string operationName, string operationName,
bool needsAuthentication) bool needsAuthentication,
: base(exchange, operationName, needsAuthentication) IEnumerable<RequestParameterDescription> defaultParameterRules)
: base(exchange, operationName, needsAuthentication, defaultParameterRules)
{ {
} }
} }
@@ -1,4 +1,6 @@
using System; using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Text; using System.Text;
@@ -49,7 +51,8 @@ namespace CryptoExchange.Net.SharedApis
bool timePeriodSupport, bool timePeriodSupport,
int maxLimit, int maxLimit,
bool needsAuthentication, bool needsAuthentication,
string requestName) : base(exchange, needsAuthentication, requestName) string requestName,
IEnumerable<RequestParameterDescription> defaultParameterRules) : base(exchange, needsAuthentication, requestName, defaultParameterRules)
{ {
SupportsAscending = supportsAscending; SupportsAscending = supportsAscending;
SupportsDescending = supportsDescending; SupportsDescending = supportsDescending;
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Exchange parameter requirements
/// </summary>
public enum ExchangeParameterRequirement
{
/// <summary>
/// Required parameter
/// </summary>
Required,
/// <summary>
/// Optional parameter
/// </summary>
Optional
}
}
@@ -0,0 +1,173 @@
using System;
using System.Linq;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Parameter description
/// </summary>
public class ParameterDescription
{
/// <summary>
/// Name of the parameter
/// </summary>
public string Name { get; set; }
/// <summary>
/// Alternative names for the parameter.
/// </summary>
public string[] Aliases { get; set; } = [];
/// <summary>
/// Type of the value
/// </summary>
public Type ValueType { get; set; }
/// <summary>
/// Parameter description
/// </summary>
public string Description { get; set; }
/// <summary>
/// Example value
/// </summary>
public object ExampleValue { get; set; }
/// <summary>
/// Names of the parameter
/// </summary>
[Obsolete("Use Name and Aliases instead")]
public string[] Names
{
get => [Name, .. Aliases];
}
/// <summary>
/// ctor
/// </summary>
public ParameterDescription(string parameterName, Type valueType, string description, object exampleValue)
{
Name = parameterName;
ValueType = valueType;
Description = description;
ExampleValue = exampleValue;
}
/// <summary>
/// ctor
/// </summary>
public ParameterDescription(string parameterName, string[] aliases, Type valueType, string description, object exampleValue)
{
Name = parameterName;
Aliases = aliases;
ValueType = valueType;
Description = description;
ExampleValue = exampleValue;
}
/// <inheritdoc />
public override string ToString()
{
return $"[{ValueType.Name}] \"{Name}\" {string.Join(" / ", Aliases.Select(x => $"\"{x}\""))}: {Description}";
}
}
/// <summary>
/// Request parameter description
/// </summary>
public class RequestParameterDescription : ParameterDescription
{
/// <summary>
/// Status defined by the shared request contract.
/// </summary>
public RequestParameterSupport DefaultSupport { get; }
/// <summary>
/// Status after applying exchange overrides.
/// </summary>
public RequestParameterSupport Support { get; }
/// <summary>
/// ctor
/// </summary>
public RequestParameterDescription(
RequestParameterSupport support,
string parameterName,
Type valueType,
string description,
object exampleValue)
: base(parameterName, valueType, description, exampleValue)
{
Support = support;
DefaultSupport = support;
}
private RequestParameterDescription(
RequestParameterSupport defaultSupport,
RequestParameterSupport support,
string parameterName,
Type valueType,
string description,
object exampleValue)
: base(parameterName, valueType, description, exampleValue)
{
DefaultSupport = defaultSupport;
Support = support;
}
internal RequestParameterDescription WithSupport(
RequestParameterSupport support)
=> new(
DefaultSupport,
support,
Name,
ValueType,
Description,
ExampleValue);
internal RequestParameterDescription WithOverride(
RequestParameterRuleOverride parameterOverride)
=> new(
DefaultSupport,
parameterOverride.Support,
Name,
ValueType,
parameterOverride.Description ?? Description,
ExampleValue);
/// <inheritdoc />
public override string ToString()
{
return $"[{Support}] [{ValueType.Name}] \"{Name}\" {string.Join(" / ", Aliases.Select(x => $"\"{x}\""))}: {Description}";
}
}
/// <summary>
/// Exchange-specific parameter description
/// </summary>
public class ExchangeParameterDescription : ParameterDescription
{
/// <summary>
/// Requirement for the parameter
/// </summary>
public ExchangeParameterRequirement Requirement { get; init; }
/// <summary>
/// ctor
/// </summary>
public ExchangeParameterDescription(
ExchangeParameterRequirement requirement,
string parameterName,
string[] aliases,
Type valueType,
string description,
object exampleValue)
: base(parameterName, aliases, valueType, description, exampleValue)
{
Requirement = requirement;
}
/// <inheritdoc />
public override string ToString()
{
return $"[{Requirement}] [{ValueType.Name}] \"{Name}\" {string.Join(" / ", Aliases.Select(x => $"\"{x}\""))}: {Description}";
}
}
}
@@ -9,13 +9,13 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// Creates descriptions for properties on a shared request. /// Creates descriptions for properties on a shared request.
/// </summary> /// </summary>
public static class RequestParameter<TRequest> public static class RequestParameterRule<TRequest>
where TRequest : SharedRequest where TRequest : SharedRequest
{ {
/// <summary> /// <summary>
/// Describe a request property which is required by an implementation. /// Describe a request property which is required by an implementation.
/// </summary> /// </summary>
public static ParameterDescription Required<TValue>( public static RequestParameterDescription Required<TValue>(
Expression<Func<TRequest, TValue>> selector, Expression<Func<TRequest, TValue>> selector,
string description, string description,
TValue exampleValue) TValue exampleValue)
@@ -37,51 +37,86 @@ namespace CryptoExchange.Net.SharedApis
nameof(selector)); nameof(selector));
} }
return new ParameterDescription( return new RequestParameterDescription(
RequestParameterSupport.Required,
property.Name, property.Name,
property.PropertyType, property.PropertyType,
description, description,
exampleValue!); exampleValue!
);
} }
/// <summary>
/// Describe a request property which is optional by an implementation.
/// </summary>
public static RequestParameterDescription Optional<TValue>(
Expression<Func<TRequest, TValue>> selector,
string description,
TValue exampleValue)
{
Expression body = selector.Body;
if (body is UnaryExpression unary
&& unary.NodeType == ExpressionType.Convert)
{
body = unary.Operand;
}
if (body is not MemberExpression member
|| member.Member is not PropertyInfo property
|| member.Expression != selector.Parameters[0])
{
throw new ArgumentException(
"Selector must select a direct request property",
nameof(selector));
}
return new RequestParameterDescription(
RequestParameterSupport.Optional,
property.Name,
property.PropertyType,
description,
exampleValue!
);
}
} }
/// <summary> /// <summary>
/// Creates descriptions for exchange-specific parameters. /// Creates descriptions for exchange-specific parameters.
/// </summary> /// </summary>
public static class ExchangeParameterDescription public static class ExchangeParameterRule
{ {
/// <summary> /// <summary>
/// Describe a required exchange-specific parameter. /// Describe a required exchange-specific parameter.
/// </summary> /// </summary>
public static ParameterDescription Required<TValue>( public static ExchangeParameterDescription Required<TValue>(
string name, string name,
string description, string description,
TValue exampleValue, TValue exampleValue,
params string[] aliases) params string[] aliases)
=> Create(name, description, exampleValue, aliases); => Create(ExchangeParameterRequirement.Required, name, description, exampleValue, aliases);
/// <summary> /// <summary>
/// Describe an optional exchange-specific parameter. /// Describe an optional exchange-specific parameter.
/// </summary> /// </summary>
public static ParameterDescription Optional<TValue>( public static ExchangeParameterDescription Optional<TValue>(
string name, string name,
string description, string description,
TValue exampleValue, TValue exampleValue,
params string[] aliases) params string[] aliases)
=> Create(name, description, exampleValue, aliases); => Create(ExchangeParameterRequirement.Optional, name, description, exampleValue, aliases);
private static ParameterDescription Create<TValue>( private static ExchangeParameterDescription Create<TValue>(
ExchangeParameterRequirement requirement,
string name, string name,
string description, string description,
TValue exampleValue, TValue exampleValue,
string[] aliases) string[] aliases)
{ {
var names = new string[aliases.Length + 1]; return new ExchangeParameterDescription(
names[0] = name; requirement,
Array.Copy(aliases, 0, names, 1, aliases.Length); name,
aliases,
return new ParameterDescription(
names,
typeof(TValue), typeof(TValue),
description, description,
exampleValue!); exampleValue!);
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Request parameter rule override
/// </summary>
/// <param name="ParameterName">The name of the parameter</param>
/// <param name="Support">The support level of the parameter</param>
/// <param name="Description">A description of the parameter</param>
public record RequestParameterRuleOverride(
string ParameterName,
RequestParameterSupport Support,
string? Description = null);
/// <summary>
/// Request parameter rule override factory
/// </summary>
/// <typeparam name="TRequest">The type of the request</typeparam>
public static class RequestParameterRuleOverride<TRequest>
where TRequest : SharedRequest
{
/// <summary>
/// Required parameter rule override
/// </summary>
public static RequestParameterRuleOverride Required<TValue>(
Expression<Func<TRequest, TValue>> selector,
string? description = null)
=> Create(selector, RequestParameterSupport.Required, description);
/// <summary>
/// Optional parameter rule override
/// </summary>
public static RequestParameterRuleOverride Optional<TValue>(
Expression<Func<TRequest, TValue>> selector,
string? description = null)
=> Create(selector, RequestParameterSupport.Optional, description);
/// <summary>
/// Not supported parameter rule override
/// </summary>
public static RequestParameterRuleOverride NotSupported<TValue>(
Expression<Func<TRequest, TValue>> selector,
string? description = null)
=> Create(selector, RequestParameterSupport.NotSupported, description);
private static RequestParameterRuleOverride Create<TValue>(
Expression<Func<TRequest, TValue>> selector,
RequestParameterSupport support,
string? description)
{
var body = selector.Body is UnaryExpression unary
&& unary.NodeType == ExpressionType.Convert
? unary.Operand
: selector.Body;
if (body is not MemberExpression member
|| member.Member is not PropertyInfo property
|| member.Expression != selector.Parameters[0])
{
throw new ArgumentException(
"Selector must select a direct request property",
nameof(selector));
}
return new RequestParameterRuleOverride(
property.Name,
support,
description);
}
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Request parameter support
/// </summary>
public enum RequestParameterSupport
{
/// <summary>
/// Required parameter
/// </summary>
Required,
/// <summary>
/// Optional parameter
/// </summary>
Optional,
/// <summary>
/// Not supported parameter
/// </summary>
NotSupported
}
}
@@ -12,10 +12,12 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve basic info for all assets and the networks they support for withdrawals/deposits"; public override string Description => "Retrieve basic info for all assets and the networks they support for withdrawals/deposits";
private static readonly RequestParameterDescription[] _defaultParameterRules = [];
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetAllAssetsOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAllAssetsRest.GetAllAssetsAsync)) public GetAllAssetsOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAllAssetsRest.GetAllAssetsAsync), _defaultParameterRules)
{ {
} }
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Assets request options.<br /> /// Assets request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetAllAssetsOptions GetAllAssetsOptions { get; } GetAllAssetsOptions GetAllAssetsOptions { get; }
@@ -12,10 +12,15 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve basic info for a single asset and networks it supports for withdrawals/deposits"; public override string Description => "Retrieve basic info for a single asset and networks it supports for withdrawals/deposits";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetAssetRequest>.Required(x => x.Asset, "The asset to retrieve information for", "ETH"),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetAssetOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAssetRest.GetAssetAsync)) public GetAssetOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAssetRest.GetAssetAsync), _defaultParameterRules)
{ {
} }
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Asset request options.<br /> /// Asset request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetAssetOptions GetAssetOptions { get; } GetAssetOptions GetAssetOptions { get; }
@@ -11,6 +11,12 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve account balances"; public override string Description => "Retrieve account balances";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetBalancesRequest>.Optional(x => x.TradingMode, "Filter the balances by trading mode", TradingMode.Spot),
RequestParameterRule<GetBalancesRequest>.Optional(x => x.AccountType, "The account type to retrieve balances for", SharedAccountType.Spot),
};
/// <summary> /// <summary>
/// Supported account types /// Supported account types
/// </summary> /// </summary>
@@ -19,7 +25,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetBalancesOptions(string exchange, params AccountTypeFilter[] accountTypes) : base(exchange, true, nameof(IGetBalancesRest.GetBalancesAsync)) public GetBalancesOptions(string exchange, params AccountTypeFilter[] accountTypes) : base(exchange, true, nameof(IGetBalancesRest.GetBalancesAsync), _defaultParameterRules)
{ {
SupportedAccountTypes = accountTypes; SupportedAccountTypes = accountTypes;
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Balances request options.<br /> /// Balances request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetBalancesOptions GetBalancesOptions { get; } GetBalancesOptions GetBalancesOptions { get; }
@@ -12,10 +12,15 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Subscribe to balance updates"; public override string Description => "Subscribe to balance updates";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<SubscribeBalancesRequest>.Optional(x => x.TradingMode, "Filter balance updates by trading mode", TradingMode.Spot),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public SubscribeBalanceOptions(string exchange, bool needsAuthentication) : base(exchange, needsAuthentication, nameof(ISubscribeBalancesSocket.SubscribeToBalanceUpdatesAsync)) public SubscribeBalanceOptions(string exchange, bool needsAuthentication) : base(exchange, needsAuthentication, nameof(ISubscribeBalancesSocket.SubscribeToBalanceUpdatesAsync), _defaultParameterRules)
{ {
} }
} }
@@ -12,10 +12,16 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve deposit addresses for an asset"; public override string Description => "Retrieve deposit addresses for an asset";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetDepositAddressesRequest>.Required(x => x.Asset, "The asset to retrieve deposit addresses for", "ETH"),
RequestParameterRule<GetDepositAddressesRequest>.Optional(x => x.Network, "The network to retrieve a deposit address for", "ERC20"),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetDepositAddressesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetDepositAddressesRest.GetDepositAddressesAsync)) public GetDepositAddressesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetDepositAddressesRest.GetDepositAddressesAsync), _defaultParameterRules)
{ {
} }
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Deposit addresses request options.<br /> /// Deposit addresses request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetDepositAddressesOptions GetDepositAddressesOptions { get; } GetDepositAddressesOptions GetDepositAddressesOptions { get; }
@@ -12,11 +12,20 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve deposit history"; public override string Description => "Retrieve deposit history";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetDepositsRequest>.Optional(x => x.Asset, "Filter the result set by asset", "ETH"),
RequestParameterRule<GetDepositsRequest>.Optional(x => x.StartTime, "Filter the result set by start time", DateTime.UtcNow.AddDays(-1)),
RequestParameterRule<GetDepositsRequest>.Optional(x => x.EndTime, "Filter the result set by end time", DateTime.UtcNow.AddHours(-1)),
RequestParameterRule<GetDepositsRequest>.Optional(x => x.Limit, "Limit the result set to a maximum number of items", 100),
RequestParameterRule<GetDepositsRequest>.Optional(x => x.Direction, "The direction in which to retrieve the results", DataDirection.Descending),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetDepositHistoryOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit) public GetDepositHistoryOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, true, nameof(IGetDepositHistoryRest.GetDepositHistoryAsync)) : base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, true, nameof(IGetDepositHistoryRest.GetDepositHistoryAsync), _defaultParameterRules)
{ {
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Deposits request options.<br /> /// Deposits request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetDepositHistoryOptions GetDepositHistoryOptions { get; } GetDepositHistoryOptions GetDepositHistoryOptions { get; }
@@ -12,10 +12,15 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve trading fee information"; public override string Description => "Retrieve trading fee information";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetFeeRequest>.Required(x => x.Symbol, "The symbol to retrieve trading fees for", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetFeeOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetFeesRest.GetFeesAsync)) public GetFeeOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetFeesRest.GetFeesAsync), _defaultParameterRules)
{ {
} }
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Fee request options.<br /> /// Fee request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetFeeOptions GetFeeOptions { get; } GetFeeOptions GetFeeOptions { get; }
@@ -12,11 +12,20 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve historical funding rates for a futures symbol"; public override string Description => "Retrieve historical funding rates for a futures symbol";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetFundingRateHistoryRequest>.Required(x => x.Symbol, "The symbol to retrieve funding rate history for", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<GetFundingRateHistoryRequest>.Optional(x => x.StartTime, "Filter the result set by start time", DateTime.UtcNow.AddDays(-1)),
RequestParameterRule<GetFundingRateHistoryRequest>.Optional(x => x.EndTime, "Filter the result set by end time", DateTime.UtcNow.AddHours(-1)),
RequestParameterRule<GetFundingRateHistoryRequest>.Optional(x => x.Limit, "Limit the result set to a maximum number of items", 100),
RequestParameterRule<GetFundingRateHistoryRequest>.Optional(x => x.Direction, "The direction in which to retrieve the results", DataDirection.Descending),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetFundingRateHistoryOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication) public GetFundingRateHistoryOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetFundingRateHistoryRest.GetFundingRateHistoryAsync)) : base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetFundingRateHistoryRest.GetFundingRateHistoryAsync), _defaultParameterRules)
{ {
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Funding rate request options.<br /> /// Funding rate request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetFundingRateHistoryOptions GetFundingRateHistoryOptions { get; } GetFundingRateHistoryOptions GetFundingRateHistoryOptions { get; }
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Options for requesting the index price
/// </summary>
public class GetAllIndexPricesOptions : CapabilityOptions<GetAllIndexPricesRequest, IGetAllIndexPricesRest>
{
/// <inheritdoc />
public override string Description => "Retrieve the index prices for all futures symbols";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetAllIndexPricesRequest>.Optional(x => x.TradingMode, "Filter the index prices by trading mode", TradingMode.PerpetualLinear),
};
/// <summary>
/// ctor
/// </summary>
public GetAllIndexPricesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAllIndexPricesRest.GetAllIndexPricesAsync), _defaultParameterRules)
{
}
}
}
@@ -3,14 +3,14 @@
/// <summary> /// <summary>
/// Request to retrieve the current index prices for all symbols /// Request to retrieve the current index prices for all symbols
/// </summary> /// </summary>
public record GetIndexPricesRequest : SharedRequest public record GetAllIndexPricesRequest : SharedRequest
{ {
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
/// <param name="tradingMode">Trading mode</param> /// <param name="tradingMode">Trading mode</param>
/// <param name="exchangeParameters">Exchange specific parameters</param> /// <param name="exchangeParameters">Exchange specific parameters</param>
public GetIndexPricesRequest(TradingMode? tradingMode = null, ExchangeParameters? exchangeParameters = null) : base(tradingMode, exchangeParameters) public GetAllIndexPricesRequest(TradingMode? tradingMode = null, ExchangeParameters? exchangeParameters = null) : base(tradingMode, exchangeParameters)
{ {
} }
} }
@@ -0,0 +1,37 @@
using CryptoExchange.Net.Objects;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Operation for retrieving the index price for all symbols from an exchange.
/// </summary>
public interface IGetAllIndexPrices : ISharedApiCapability
{
/// <summary>
/// Index price request options.<br />
/// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary>
GetAllIndexPricesOptions GetAllIndexPricesOptions { get; }
/// <summary>
/// Get the index price for a symbol, see <see cref="GetAllIndexPricesOptions"/> for request options and exchange specific required/optional parameters. <br />
/// </summary>
/// <param name="request">Request info</param>
/// <param name="ct">Cancellation token</param>
Task<ICallResult<SharedIndexPrice[]>> GetAllIndexPricesAsync(GetAllIndexPricesRequest request, CancellationToken ct = default);
}
/// <summary>
/// Operation for retrieving the index price for all symbols from an exchange via the REST API.
/// </summary>
public interface IGetAllIndexPricesRest : IGetAllIndexPrices, ISharedRest
{
/// <inheritdoc />
new Task<HttpResult<SharedIndexPrice[]>> GetAllIndexPricesAsync(GetAllIndexPricesRequest request, CancellationToken ct = default);
}
}
@@ -12,10 +12,15 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve the index price for a futures symbol"; public override string Description => "Retrieve the index price for a futures symbol";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetIndexPriceRequest>.Required(x => x.Symbol, "The symbol to retrieve the index price for", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetIndexPriceOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetIndexPriceRest.GetIndexPriceAsync)) public GetIndexPriceOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetIndexPriceRest.GetIndexPriceAsync), _defaultParameterRules)
{ {
} }
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Index price request options.<br /> /// Index price request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetIndexPriceOptions GetIndexPriceOptions { get; } GetIndexPriceOptions GetIndexPriceOptions { get; }
@@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Options for requesting the index price
/// </summary>
public class GetIndexPricesOptions : CapabilityOptions<GetIndexPricesRequest, IGetIndexPricesRest>
{
/// <inheritdoc />
public override string Description => "Retrieve the index prices for all futures symbols";
/// <summary>
/// ctor
/// </summary>
public GetIndexPricesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetIndexPricesRest.GetIndexPricesAsync))
{
}
}
}
@@ -1,37 +0,0 @@
using CryptoExchange.Net.Objects;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Operation for retrieving the index price for a symbol from an exchange.
/// </summary>
public interface IGetIndexPrices : ISharedApiCapability
{
/// <summary>
/// Index price request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary>
GetIndexPricesOptions GetIndexPricesOptions { get; }
/// <summary>
/// Get the index price for a symbol, see <see cref="GetIndexPricesOptions"/> for request options and exchange specific required/optional parameters. <br />
/// </summary>
/// <param name="request">Request info</param>
/// <param name="ct">Cancellation token</param>
Task<ICallResult<SharedIndexPrice[]>> GetIndexPricesAsync(GetIndexPricesRequest request, CancellationToken ct = default);
}
/// <summary>
/// Operation for retrieving the index price for a symbol from an exchange via the REST API.
/// </summary>
public interface IGetIndexPricesRest : IGetIndexPrices, ISharedRest
{
/// <inheritdoc />
new Task<HttpResult<SharedIndexPrice[]>> GetIndexPricesAsync(GetIndexPricesRequest request, CancellationToken ct = default);
}
}
@@ -13,6 +13,16 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve index price candlestick data"; public override string Description => "Retrieve index price candlestick data";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetKlinesRequest>.Required(x => x.Symbol, "The symbol to retrieve klines for", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<GetKlinesRequest>.Required(x => x.Interval, "The kline interval", SharedKlineInterval.OneMinute),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.StartTime, "Filter the result set by start time", DateTime.UtcNow.AddDays(-1)),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.EndTime, "Filter the result set by end time", DateTime.UtcNow.AddHours(-1)),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.Limit, "Limit the result set to a maximum number of items", 100),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.Direction, "The direction in which to retrieve the results", DataDirection.Descending),
};
/// <summary> /// <summary>
/// The supported kline intervals /// The supported kline intervals
/// </summary> /// </summary>
@@ -26,7 +36,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor /// ctor
/// </summary> /// </summary>
public GetIndexPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication) public GetIndexPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetIndexPriceKlinesRest.GetIndexPriceKlinesAsync)) : base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetIndexPriceKlinesRest.GetIndexPriceKlinesAsync), _defaultParameterRules)
{ {
SupportIntervals = new[] SupportIntervals = new[]
{ {
@@ -51,7 +61,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor /// ctor
/// </summary> /// </summary>
public GetIndexPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals) public GetIndexPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IIndexPriceKlineRestClient.GetIndexPriceKlinesAsync)) : base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IIndexPriceKlineRestClient.GetIndexPriceKlinesAsync), _defaultParameterRules)
{ {
SupportIntervals = intervals; SupportIntervals = intervals;
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Index price klines request options.<br /> /// Index price klines request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetIndexPriceKlinesOptions GetIndexPriceKlinesOptions { get; } GetIndexPriceKlinesOptions GetIndexPriceKlinesOptions { get; }
@@ -13,6 +13,16 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve mark price candlestick data"; public override string Description => "Retrieve mark price candlestick data";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetKlinesRequest>.Required(x => x.Symbol, "The symbol to retrieve klines for", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<GetKlinesRequest>.Required(x => x.Interval, "The kline interval", SharedKlineInterval.OneMinute),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.StartTime, "Filter the result set by start time", DateTime.UtcNow.AddDays(-1)),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.EndTime, "Filter the result set by end time", DateTime.UtcNow.AddHours(-1)),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.Limit, "Limit the result set to a maximum number of items", 100),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.Direction, "The direction in which to retrieve the results", DataDirection.Descending),
};
/// <summary> /// <summary>
/// The supported kline intervals /// The supported kline intervals
/// </summary> /// </summary>
@@ -26,7 +36,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor /// ctor
/// </summary> /// </summary>
public GetMarkPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication) public GetMarkPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetMarkPriceKlinesRest.GetMarkPriceKlinesAsync)) : base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetMarkPriceKlinesRest.GetMarkPriceKlinesAsync), _defaultParameterRules)
{ {
SupportIntervals = new[] SupportIntervals = new[]
{ {
@@ -51,7 +61,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor /// ctor
/// </summary> /// </summary>
public GetMarkPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals) public GetMarkPriceKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetMarkPriceKlinesRest.GetMarkPriceKlinesAsync)) : base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetMarkPriceKlinesRest.GetMarkPriceKlinesAsync), _defaultParameterRules)
{ {
SupportIntervals = intervals; SupportIntervals = intervals;
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Mark price klines request options.<br /> /// Mark price klines request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetMarkPriceKlinesOptions GetMarkPriceKlinesOptions { get; } GetMarkPriceKlinesOptions GetMarkPriceKlinesOptions { get; }
@@ -13,6 +13,16 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve candlestick data for a symbol"; public override string Description => "Retrieve candlestick data for a symbol";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetKlinesRequest>.Required(x => x.Symbol, "The symbol to retrieve klines for", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")),
RequestParameterRule<GetKlinesRequest>.Required(x => x.Interval, "The kline interval", SharedKlineInterval.OneMinute),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.StartTime, "Filter the result set by start time", DateTime.UtcNow.AddDays(-1)),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.EndTime, "Filter the result set by end time", DateTime.UtcNow.AddHours(-1)),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.Limit, "Limit the result set to a maximum number of items", 100),
RequestParameterRule<GetKlinesRequest>.Optional(x => x.Direction, "The direction in which to retrieve the results", DataDirection.Descending),
};
/// <summary> /// <summary>
/// The supported kline intervals /// The supported kline intervals
/// </summary> /// </summary>
@@ -26,7 +36,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor /// ctor
/// </summary> /// </summary>
public GetKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication) public GetKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetKlinesRest.GetKlinesAsync)) : base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetKlinesRest.GetKlinesAsync), _defaultParameterRules)
{ {
SupportIntervals = new[] SupportIntervals = new[]
{ {
@@ -51,7 +61,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor /// ctor
/// </summary> /// </summary>
public GetKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals) public GetKlinesOptions(string exchange, bool supportsAscending, bool supportsDescending, bool timeFilterSupported, int maxLimit, bool needsAuthentication, params SharedKlineInterval[] intervals)
: base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetKlinesRest.GetKlinesAsync)) : base(exchange, supportsAscending, supportsDescending, timeFilterSupported, maxLimit, needsAuthentication, nameof(IGetKlinesRest.GetKlinesAsync), _defaultParameterRules)
{ {
SupportIntervals = intervals; SupportIntervals = intervals;
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Kline request options.<br /> /// Kline request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetKlinesOptions GetKlinesOptions { get; } GetKlinesOptions GetKlinesOptions { get; }
@@ -12,6 +12,13 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Subscribe to candlestick updates for a symbol"; public override string Description => "Subscribe to candlestick updates for a symbol";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<SubscribeKlineRequest>.Optional(x => x.Symbol, "The symbol to subscribe to", new SharedSymbol(TradingMode.Spot, "ETH", "USDT")),
RequestParameterRule<SubscribeKlineRequest>.Optional(x => x.Symbols, "The symbols to subscribe to", new[] { new SharedSymbol(TradingMode.Spot, "ETH", "USDT") }),
RequestParameterRule<SubscribeKlineRequest>.Required(x => x.Interval, "The kline interval", SharedKlineInterval.OneMinute),
};
/// <summary> /// <summary>
/// Kline intervals supported for updates /// Kline intervals supported for updates
/// </summary> /// </summary>
@@ -20,7 +27,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public SubscribeKlineOptions(string exchange, bool needsAuthentication) : base(exchange, needsAuthentication, nameof(ISubscribeKlinesSocket.SubscribeToKlineUpdatesAsync)) public SubscribeKlineOptions(string exchange, bool needsAuthentication) : base(exchange, needsAuthentication, nameof(ISubscribeKlinesSocket.SubscribeToKlineUpdatesAsync), _defaultParameterRules)
{ {
SupportIntervals = new[] SupportIntervals = new[]
{ {
@@ -45,7 +52,7 @@ namespace CryptoExchange.Net.SharedApis
/// ctor /// ctor
/// </summary> /// </summary>
public SubscribeKlineOptions(string exchange, bool needsAuthentication, params SharedKlineInterval[] intervals) public SubscribeKlineOptions(string exchange, bool needsAuthentication, params SharedKlineInterval[] intervals)
: base(exchange, needsAuthentication, nameof(ISubscribeKlinesSocket.SubscribeToKlineUpdatesAsync)) : base(exchange, needsAuthentication, nameof(ISubscribeKlinesSocket.SubscribeToKlineUpdatesAsync), _defaultParameterRules)
{ {
SupportIntervals = intervals; SupportIntervals = intervals;
} }
@@ -12,10 +12,17 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Retrieve the current leverage for a futures symbol"; public override string Description => "Retrieve the current leverage for a futures symbol";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetLeverageRequest>.Required(x => x.Symbol, "The symbol to retrieve leverage for", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<GetLeverageRequest>.Optional(x => x.PositionSide, "The position side to retrieve leverage for", SharedPositionSide.Long),
RequestParameterRule<GetLeverageRequest>.Optional(x => x.MarginMode, "The margin mode to retrieve leverage for", SharedMarginMode.Cross),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public GetLeverageOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetLeverageRest.GetLeverageAsync)) public GetLeverageOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetLeverageRest.GetLeverageAsync), _defaultParameterRules)
{ {
} }
} }
@@ -14,7 +14,7 @@ namespace CryptoExchange.Net.SharedApis
{ {
/// <summary> /// <summary>
/// Leverage request options.<br /> /// Leverage request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
GetLeverageOptions GetLeverageOptions { get; } GetLeverageOptions GetLeverageOptions { get; }
@@ -19,7 +19,7 @@ namespace CryptoExchange.Net.SharedApis
/// <summary> /// <summary>
/// Leverage set request options.<br /> /// Leverage set request options.<br />
/// Use <see cref="CapabilityOptions.RequiredRequestParameters"/>, <see cref="CapabilityOptions.RequiredExchangeParameters"/> and <see cref="CapabilityOptions.OptionalExchangeParameters"/> to check for required and optional parameters for the request. <br /> /// Use <see cref="CapabilityOptions.RequestParameterRules"/> and <see cref="CapabilityOptions.ExchangeParameterRules"/> to check for required and optional parameters for the request. <br />
/// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object. /// Exchange specific parameters can be added to the request via the `ExchangeParameters` property of the request object.
/// </summary> /// </summary>
SetLeverageOptions SetLeverageOptions { get; } SetLeverageOptions SetLeverageOptions { get; }
@@ -8,10 +8,18 @@ namespace CryptoExchange.Net.SharedApis
/// <inheritdoc /> /// <inheritdoc />
public override string Description => "Set the leverage for a futures symbol"; public override string Description => "Set the leverage for a futures symbol";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<SetLeverageRequest>.Required(x => x.Symbol, "The symbol to set leverage for", new SharedSymbol(TradingMode.PerpetualLinear, "ETH", "USDT")),
RequestParameterRule<SetLeverageRequest>.Required(x => x.Leverage, "The leverage to set", 10m),
RequestParameterRule<SetLeverageRequest>.Optional(x => x.Side, "The position side to set leverage for", SharedPositionSide.Long),
RequestParameterRule<SetLeverageRequest>.Optional(x => x.MarginMode, "The margin mode to set leverage for", SharedMarginMode.Cross),
};
/// <summary> /// <summary>
/// ctor /// ctor
/// </summary> /// </summary>
public SetLeverageOptions(string exchange) : base(exchange, true, nameof(ISetLeverageRest.SetLeverageAsync)) public SetLeverageOptions(string exchange) : base(exchange, true, nameof(ISetLeverageRest.SetLeverageAsync), _defaultParameterRules)
{ {
} }
} }
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.SharedApis
{
/// <summary>
/// Options for requesting the mark price
/// </summary>
public class GetAllMarkPricesOptions : CapabilityOptions<GetAllMarkPricesRequest, IGetAllMarkPricesRest>
{
/// <inheritdoc />
public override string Description => "Retrieve the mark prices for all futures symbols";
private static readonly RequestParameterDescription[] _defaultParameterRules = new[]
{
RequestParameterRule<GetAllMarkPricesRequest>.Optional(x => x.TradingMode, "Filter the mark prices by trading mode", TradingMode.PerpetualLinear),
};
/// <summary>
/// ctor
/// </summary>
public GetAllMarkPricesOptions(string exchange, bool authenticated) : base(exchange, authenticated, nameof(IGetAllMarkPricesRest.GetAllMarkPricesAsync), _defaultParameterRules)
{
}
}
}

Some files were not shown because too many files have changed in this diff Show More