mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-11-07 13:57:40 +00:00
* Added support for Native AOT compilation * Updated all IEnumerable response types to array response types * Added Pass support for ApiCredentials, removing the need for most implementations to add their own ApiCredentials type * Added KeepAliveTimeout setting setting ping frame timeouts for SocketApiClient * Added IBookTickerRestClient Shared interface for requesting book tickers * Added ISpotTriggerOrderRestClient Shared interface for managing spot trigger orders * Added ISpotOrderClientIdClient Shared interface for managing spot orders by client order id * Added IFuturesTriggerOrderRestClient Shared interface for managing futures trigger orders * Added IFuturesOrderClientIdClient Shared interface for managing futures orders by client order id * Added IFuturesTpSlRestClient Shared interface for setting TP/SL on open futures positions * Added GenerateClientOrderId to ISpotOrderRestClient and IFuturesOrderRestClient interface * Added OptionalExchangeParameters and Supported properties to EndpointOptions * Refactor Shared interfaces quantity parameters and properties to use SharedQuantity * Added SharedSymbol property to Shared interface models returning a symbol * Added TriggerPrice, IsTriggerOrder, TakeProfitPrice, StopLossPrice and IsCloseOrder to SharedFuturesOrder response model * Added MaxShortLeverage and MaxLongLeverage to SharedFuturesSymbol response model * Added StopLossPrice and TakeProfitPrice to SharedPosition response model * Added TriggerPrice and IsTriggerOrder to SharedSpotOrder response model * Added QuoteVolume property to SharedSpotTicker response model * Added AssetAlias configuration models * Added static ExchangeSymbolCache for tracking symbol information from exchanges * Added static CallResult.SuccessResult to be used instead of constructing success CallResult instance * Added static ApplyRules, RandomHexString and RandomLong helper methods to ExchangeHelpers class * Added AsErrorWithData To CallResult * Added OriginalData property to CallResult * Added support for adjusting the rate limit key per call, allowing for ratelimiting depending on request parameters * Added implementation for integration testing ISymbolOrderBook instances * Added implementation for integration testing socket subscriptions * Added implementation for testing socket queries * Updated request cancellation logging to Debug level * Updated logging SourceContext to include the client type * Updated some logging logic, errors no longer contain any data, exception are not logged as string but instead forwarded to structured logging * Fixed warning for Enum parsing throwing exception and output warnings for each object in a response to only once to prevent slowing down execution * Fixed memory leak in AsyncAutoRestEvent * Fixed logging for ping frame timeout * Fixed warning getting logged when user stops SymbolOrderBook instance * Fixed socket client `UnsubscribeAll` not unsubscribing dedicated connections * Fixed memory leak in Rest client cache * Fixed integers bigger than int16 not getting correctly parsed to enums * Fixed issue where the default options were overridden when using SetApiCredentials * Removed Newtonsoft.Json dependency * Removed legacy Rest client code * Removed legacy ISpotClient and IFuturesClient support
131 lines
6.3 KiB
C#
131 lines
6.3 KiB
C#
using CryptoExchange.Net.Authentication;
|
|
using System;
|
|
|
|
namespace CryptoExchange.Net.Objects.Options
|
|
{
|
|
/// <summary>
|
|
/// Options for a websocket exchange client
|
|
/// </summary>
|
|
public class SocketExchangeOptions : ExchangeOptions
|
|
{
|
|
/// <summary>
|
|
/// The fixed time to wait between reconnect attempts, only used when `ReconnectPolicy` is set to `ReconnectPolicy.ExponentialBackoff`
|
|
/// </summary>
|
|
public TimeSpan ReconnectInterval { get; set; } = TimeSpan.FromSeconds(5);
|
|
|
|
/// <summary>
|
|
/// Reconnect policy
|
|
/// </summary>
|
|
public ReconnectPolicy ReconnectPolicy { get; set; } = ReconnectPolicy.FixedDelay;
|
|
|
|
/// <summary>
|
|
/// Max number of concurrent resubscription tasks per socket after reconnecting a socket
|
|
/// </summary>
|
|
public int MaxConcurrentResubscriptionsPerSocket { get; set; } = 5;
|
|
|
|
/// <summary>
|
|
/// The max time of not receiving any data after which the connection is assumed to be dropped. This can only be used for socket connections where a steady flow of data is expected,
|
|
/// for example when the server sends intermittent ping requests
|
|
/// </summary>
|
|
public TimeSpan SocketNoDataTimeout { get; set; }
|
|
|
|
/// <summary>
|
|
/// The amount of subscriptions that should be made on a single socket connection. Not all API's support multiple subscriptions on a single socket.
|
|
/// Setting this to a higher number increases subscription speed because not every subscription needs to connect to the server, but having more subscriptions on a
|
|
/// single connection will also increase the amount of traffic on that single connection, potentially leading to issues.
|
|
/// </summary>
|
|
public int? SocketSubscriptionsCombineTarget { get; set; }
|
|
|
|
/// <summary>
|
|
/// The max amount of connections to make to the server. Can be used for API's which only allow a certain number of connections. Changing this to a high value might cause issues.
|
|
/// </summary>
|
|
public int? MaxSocketConnections { get; set; }
|
|
|
|
/// <summary>
|
|
/// The time to wait after connecting a socket before sending messages. Can be used for API's which will rate limit if you subscribe directly after connecting.
|
|
/// </summary>
|
|
public TimeSpan DelayAfterConnect { get; set; } = TimeSpan.Zero;
|
|
|
|
/// <summary>
|
|
/// This delay is used to set a RetryAfter guard on the connection after a rate limit is hit on the server.
|
|
/// This is used to prevent the client from reconnecting too quickly after a rate limit is hit.
|
|
/// </summary>
|
|
public TimeSpan? ConnectDelayAfterRateLimited { get; set; }
|
|
|
|
/// <summary>
|
|
/// The buffer size to use for receiving data. Leave unset to use the default buffer size.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Only specify this if you are creating a significant amount of connections and understand the typical message length we receive from the exchange.
|
|
/// Setting this too low can increase memory consumption and allocations.
|
|
/// </remarks>
|
|
public int? ReceiveBufferSize { get; set; }
|
|
|
|
/// <summary>
|
|
/// Create a copy of this options
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <returns></returns>
|
|
public T Set<T>(T item) where T : SocketExchangeOptions, new()
|
|
{
|
|
item.ApiCredentials = ApiCredentials?.Copy();
|
|
item.OutputOriginalData = OutputOriginalData;
|
|
item.ReconnectPolicy = ReconnectPolicy;
|
|
item.DelayAfterConnect = DelayAfterConnect;
|
|
item.MaxConcurrentResubscriptionsPerSocket = MaxConcurrentResubscriptionsPerSocket;
|
|
item.ReconnectInterval = ReconnectInterval;
|
|
item.SocketNoDataTimeout = SocketNoDataTimeout;
|
|
item.SocketSubscriptionsCombineTarget = SocketSubscriptionsCombineTarget;
|
|
item.MaxSocketConnections = MaxSocketConnections;
|
|
item.Proxy = Proxy;
|
|
item.RequestTimeout = RequestTimeout;
|
|
item.RateLimitingBehaviour = RateLimitingBehaviour;
|
|
item.RateLimiterEnabled = RateLimiterEnabled;
|
|
item.ReceiveBufferSize = ReceiveBufferSize;
|
|
return item;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Options for a socket exchange client
|
|
/// </summary>
|
|
/// <typeparam name="TEnvironment"></typeparam>
|
|
public class SocketExchangeOptions<TEnvironment> : SocketExchangeOptions where TEnvironment : TradeEnvironment
|
|
{
|
|
/// <summary>
|
|
/// Trade environment. Contains info about URL's to use to connect to the API. To swap environment select another environment for
|
|
/// the exchange's environment list or create a custom environment using either `[Exchange]Environment.CreateCustom()` or `[Exchange]Environment.[Environment]`, for example `KucoinEnvironment.TestNet` or `BinanceEnvironment.Live`
|
|
/// </summary>
|
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
|
public TEnvironment Environment { get; set; }
|
|
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
|
|
|
/// <summary>
|
|
/// Set the values of this options on the target options
|
|
/// </summary>
|
|
public new T Set<T>(T target) where T : SocketExchangeOptions<TEnvironment>, new()
|
|
{
|
|
base.Set(target);
|
|
target.Environment = Environment;
|
|
return target;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Options for a socket exchange client
|
|
/// </summary>
|
|
/// <typeparam name="TEnvironment"></typeparam>
|
|
/// <typeparam name="TApiCredentials"></typeparam>
|
|
public class SocketExchangeOptions<TEnvironment, TApiCredentials> : SocketExchangeOptions<TEnvironment> where TEnvironment : TradeEnvironment where TApiCredentials : ApiCredentials
|
|
{
|
|
/// <summary>
|
|
/// The api credentials used for signing requests to this API.
|
|
/// </summary>
|
|
public new TApiCredentials? ApiCredentials
|
|
{
|
|
get => (TApiCredentials?)base.ApiCredentials;
|
|
set => base.ApiCredentials = value;
|
|
}
|
|
}
|
|
}
|