mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-10-04 02:11:11 +00:00
Added DelayAfterConnect to SocketApiOptions, fixed DelayAfterConnect not being respected on reconnection
This commit is contained in:
@@ -533,9 +533,6 @@ namespace CryptoExchange.Net.Clients
|
|||||||
if (!connectResult.Success)
|
if (!connectResult.Success)
|
||||||
return connectResult;
|
return connectResult;
|
||||||
|
|
||||||
if (ClientOptions.DelayAfterConnect != TimeSpan.Zero)
|
|
||||||
await Task.Delay(ClientOptions.DelayAfterConnect).ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (!authenticated || socket.Authenticated)
|
if (!authenticated || socket.Authenticated)
|
||||||
return CallResult.Ok();
|
return CallResult.Ok();
|
||||||
|
|
||||||
@@ -862,7 +859,7 @@ namespace CryptoExchange.Net.Clients
|
|||||||
RateLimitAdmissionCallbackRequest = () => AdmissionOverride.Value,
|
RateLimitAdmissionCallbackRequest = () => AdmissionOverride.Value,
|
||||||
Proxy = ClientOptions.Proxy,
|
Proxy = ClientOptions.Proxy,
|
||||||
Timeout = ApiOptions.SocketNoDataTimeout ?? ClientOptions.SocketNoDataTimeout,
|
Timeout = ApiOptions.SocketNoDataTimeout ?? ClientOptions.SocketNoDataTimeout,
|
||||||
ReceiveBufferSize = ClientOptions.ReceiveBufferSize,
|
ReceiveBufferSize = ClientOptions.ReceiveBufferSize
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int? MaxSocketConnections { get; set; }
|
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; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Set the values of this options on the target options
|
/// Set the values of this options on the target options
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -28,6 +33,7 @@ namespace CryptoExchange.Net.Objects.Options
|
|||||||
item.SocketNoDataTimeout = SocketNoDataTimeout;
|
item.SocketNoDataTimeout = SocketNoDataTimeout;
|
||||||
item.AutoTimestamp = AutoTimestamp;
|
item.AutoTimestamp = AutoTimestamp;
|
||||||
item.MaxSocketConnections = MaxSocketConnections;
|
item.MaxSocketConnections = MaxSocketConnections;
|
||||||
|
item.DelayAfterConnect = DelayAfterConnect;
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -424,6 +424,9 @@ namespace CryptoExchange.Net.Sockets.Default
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if ((ApiClient.ApiOptions.DelayAfterConnect ?? ApiClient.ClientOptions.DelayAfterConnect) != TimeSpan.Zero)
|
||||||
|
await Task.Delay(ApiClient.ApiOptions.DelayAfterConnect ?? ApiClient.ClientOptions.DelayAfterConnect).ConfigureAwait(false);
|
||||||
|
|
||||||
var reconnectSuccessful = await ProcessReconnectAsync().ConfigureAwait(false);
|
var reconnectSuccessful = await ProcessReconnectAsync().ConfigureAwait(false);
|
||||||
if (!reconnectSuccessful.Success)
|
if (!reconnectSuccessful.Success)
|
||||||
{
|
{
|
||||||
@@ -616,7 +619,17 @@ namespace CryptoExchange.Net.Sockets.Default
|
|||||||
/// Connect the websocket
|
/// Connect the websocket
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<CallResult> ConnectAsync(CancellationToken ct) => await _socket.ConnectAsync(ct).ConfigureAwait(false);
|
public async Task<CallResult> ConnectAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
var result = await _socket.ConnectAsync(ct).ConfigureAwait(false);
|
||||||
|
if (!result.Success)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
if ((ApiClient.ApiOptions.DelayAfterConnect ?? ApiClient.ClientOptions.DelayAfterConnect) != TimeSpan.Zero)
|
||||||
|
await Task.Delay(ApiClient.ApiOptions.DelayAfterConnect ?? ApiClient.ClientOptions.DelayAfterConnect).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve the underlying socket
|
/// Retrieve the underlying socket
|
||||||
|
|||||||
Reference in New Issue
Block a user