Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
JKorf committed Dec 20, 2024
1 parent 0b09672 commit a0b8a4d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions CryptoExchange.Net/Clients/SocketApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected virtual void SetDedicatedConnection(string url, bool auth)
/// <param name="interval"></param>
/// <param name="queryDelegate"></param>
/// <param name="callback"></param>
protected virtual void RegisterPeriodicQuery(string identifier, TimeSpan interval, Func<SocketConnection, Query> queryDelegate, Action<CallResult>? callback)
protected virtual void RegisterPeriodicQuery(string identifier, TimeSpan interval, Func<SocketConnection, Query> queryDelegate, Action<SocketConnection, CallResult>? callback)
{
PeriodicTaskRegistrations.Add(new PeriodicTaskRegistration
{
Expand Down Expand Up @@ -422,9 +422,10 @@ public virtual async Task<CallResult> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions CryptoExchange.Net/Sockets/CryptoExchangeWebSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion CryptoExchange.Net/Sockets/PeriodicTaskRegistration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public class PeriodicTaskRegistration
/// <summary>
/// Callback after query
/// </summary>
public Action<CallResult>? Callback { get; set; }
public Action<SocketConnection, CallResult>? Callback { get; set; }
}
}
5 changes: 5 additions & 0 deletions CryptoExchange.Net/Sockets/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public abstract class Query : IMessageProcessor
/// </summary>
public bool Completed { get; set; }

/// <summary>
/// Timeout for the request
/// </summary>
public TimeSpan? RequestTimeout { get; set; }

/// <summary>
/// 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
Expand Down
6 changes: 3 additions & 3 deletions CryptoExchange.Net/Sockets/SocketConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -1000,7 +1000,7 @@ internal async Task<CallResult> ResubscribeAsync(Subscription subscription)
/// <param name="interval">How often</param>
/// <param name="queryDelegate">Method returning the query to send</param>
/// <param name="callback">The callback for processing the response</param>
public virtual void QueryPeriodic(string identifier, TimeSpan interval, Func<SocketConnection, Query> queryDelegate, Action<CallResult>? callback)
public virtual void QueryPeriodic(string identifier, TimeSpan interval, Func<SocketConnection, Query> queryDelegate, Action<SocketConnection, CallResult>? callback)
{
if (queryDelegate == null)
throw new ArgumentNullException(nameof(queryDelegate));
Expand Down Expand Up @@ -1032,7 +1032,7 @@ public virtual void QueryPeriodic(string identifier, TimeSpan interval, Func<Soc
try
{
var result = await SendAndWaitQueryAsync(query).ConfigureAwait(false);
callback?.Invoke(result);
callback?.Invoke(this, result);
}
catch (Exception ex)
{
Expand Down
3 changes: 2 additions & 1 deletion CryptoExchange.Net/Trackers/Trades/TradeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ protected void SetInitialData(IEnumerable<SharedTrade> data)
_data.Add(item);
}

_firstTimestamp = _data.Min(v => v.Timestamp);
if (_data.Any())
_firstTimestamp = _data.Min(v => v.Timestamp);

ApplyWindow(false);
}
Expand Down

0 comments on commit a0b8a4d

Please sign in to comment.