diff --git a/CryptoExchange.Net/Clients/SocketApiClient.cs b/CryptoExchange.Net/Clients/SocketApiClient.cs index e9b79194..63ab6207 100644 --- a/CryptoExchange.Net/Clients/SocketApiClient.cs +++ b/CryptoExchange.Net/Clients/SocketApiClient.cs @@ -158,7 +158,7 @@ protected virtual void SetDedicatedConnection(string url, bool auth) /// /// /// - protected virtual void RegisterPeriodicQuery(string identifier, TimeSpan interval, Func queryDelegate, Action? callback) + protected virtual void RegisterPeriodicQuery(string identifier, TimeSpan interval, Func queryDelegate, Action? callback) { PeriodicTaskRegistrations.Add(new PeriodicTaskRegistration { @@ -422,9 +422,10 @@ public virtual async Task AuthenticateSocketAsync(SocketConnection s result.Error!.Message = "Authentication failed: " + result.Error.Message; return new CallResult(result.Error)!; } + + _logger.Authenticated(socket.SocketId); } - _logger.Authenticated(socket.SocketId); socket.Authenticated = true; return new CallResult(null); } diff --git a/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs b/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs index b3bca4dd..1d364ebd 100644 --- a/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs +++ b/CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs @@ -441,8 +441,8 @@ private async Task CloseInternalAsync() { // Wait until we receive close confirmation await Task.Delay(10).ConfigureAwait(false); - if (DateTime.UtcNow - startWait > TimeSpan.FromSeconds(5)) - break; // Wait for max 5 seconds, then just abort the connection + if (DateTime.UtcNow - startWait > TimeSpan.FromSeconds(1)) + break; // Wait for max 1 second, then just abort the connection } } } diff --git a/CryptoExchange.Net/Sockets/PeriodicTaskRegistration.cs b/CryptoExchange.Net/Sockets/PeriodicTaskRegistration.cs index 8f9ccaf7..9c532bba 100644 --- a/CryptoExchange.Net/Sockets/PeriodicTaskRegistration.cs +++ b/CryptoExchange.Net/Sockets/PeriodicTaskRegistration.cs @@ -23,6 +23,6 @@ public class PeriodicTaskRegistration /// /// Callback after query /// - public Action? Callback { get; set; } + public Action? Callback { get; set; } } } diff --git a/CryptoExchange.Net/Sockets/Query.cs b/CryptoExchange.Net/Sockets/Query.cs index 833abf8b..397ae433 100644 --- a/CryptoExchange.Net/Sockets/Query.cs +++ b/CryptoExchange.Net/Sockets/Query.cs @@ -23,6 +23,11 @@ public abstract class Query : IMessageProcessor /// public bool Completed { get; set; } + /// + /// Timeout for the request + /// + public TimeSpan? RequestTimeout { get; set; } + /// /// The number of required responses. Can be more than 1 when for example subscribing multiple symbols streams in a single request, /// and each symbol receives it's own confirmation response diff --git a/CryptoExchange.Net/Sockets/SocketConnection.cs b/CryptoExchange.Net/Sockets/SocketConnection.cs index 43c08817..a1deaaa6 100644 --- a/CryptoExchange.Net/Sockets/SocketConnection.cs +++ b/CryptoExchange.Net/Sockets/SocketConnection.cs @@ -439,7 +439,7 @@ protected virtual Task HandleRequestSentAsync(int requestId) return Task.CompletedTask; } - query.IsSend(ApiClient.ClientOptions.RequestTimeout); + query.IsSend(query.RequestTimeout ?? ApiClient.ClientOptions.RequestTimeout); return Task.CompletedTask; } @@ -1000,7 +1000,7 @@ internal async Task ResubscribeAsync(Subscription subscription) /// How often /// Method returning the query to send /// The callback for processing the response - public virtual void QueryPeriodic(string identifier, TimeSpan interval, Func queryDelegate, Action? callback) + public virtual void QueryPeriodic(string identifier, TimeSpan interval, Func queryDelegate, Action? callback) { if (queryDelegate == null) throw new ArgumentNullException(nameof(queryDelegate)); @@ -1032,7 +1032,7 @@ public virtual void QueryPeriodic(string identifier, TimeSpan interval, Func data) _data.Add(item); } - _firstTimestamp = _data.Min(v => v.Timestamp); + if (_data.Any()) + _firstTimestamp = _data.Min(v => v.Timestamp); ApplyWindow(false); }