using CryptoExchange.Net.Authentication; using System; namespace CryptoExchange.Net.Objects.Options { /// /// Options for a websocket exchange client /// public class SocketExchangeOptions : ExchangeOptions { /// /// The fixed time to wait between reconnect attempts, only used when `ReconnectPolicy` is set to `ReconnectPolicy.ExponentialBackoff` /// public TimeSpan ReconnectInterval { get; set; } = TimeSpan.FromSeconds(5); /// /// Reconnect policy /// public ReconnectPolicy ReconnectPolicy { get; set; } = ReconnectPolicy.FixedDelay; /// /// Max number of concurrent resubscription tasks per socket after reconnecting a socket /// public int MaxConcurrentResubscriptionsPerSocket { get; set; } = 5; /// /// 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 /// public TimeSpan SocketNoDataTimeout { get; set; } /// /// 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. /// public int? SocketSubscriptionsCombineTarget { get; set; } /// /// 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. /// public int? MaxSocketConnections { get; set; } /// /// 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. /// public TimeSpan DelayAfterConnect { get; set; } = TimeSpan.Zero; /// /// 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. /// public TimeSpan? ConnectDelayAfterRateLimited { get; set; } /// /// The buffer size to use for receiving data. Leave unset to use the default buffer size. /// /// /// 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. /// public int? ReceiveBufferSize { get; set; } /// /// Create a copy of this options /// /// /// public T Set(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; } } /// /// Options for a socket exchange client /// /// public class SocketExchangeOptions : SocketExchangeOptions where TEnvironment : TradeEnvironment { /// /// 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` /// #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. /// /// Set the values of this options on the target options /// public new T Set(T target) where T : SocketExchangeOptions, new() { base.Set(target); target.Environment = Environment; return target; } } /// /// Options for a socket exchange client /// /// /// public class SocketExchangeOptions : SocketExchangeOptions where TEnvironment : TradeEnvironment where TApiCredentials : ApiCredentials { /// /// The api credentials used for signing requests to this API. /// public new TApiCredentials? ApiCredentials { get => (TApiCredentials?)base.ApiCredentials; set => base.ApiCredentials = value; } } }