mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-18 03:43:00 +00:00
feature: Handle error 429 when connecting websocket (#213)
* feature: Handle error 429 when connecting websocket * Add preprocessor directive for NET6_0_OR_GREATER when checking for connection rate limit
This commit is contained in:
@@ -519,6 +519,7 @@ namespace CryptoExchange.Net.Clients
|
||||
var socket = CreateSocket(connectionAddress.Data!);
|
||||
var socketConnection = new SocketConnection(_logger, this, socket, address);
|
||||
socketConnection.UnhandledMessage += HandleUnhandledMessage;
|
||||
socketConnection.ConnectRateLimitedAsync += HandleConnectRateLimitedAsync;
|
||||
socketConnection.DedicatedRequestConnection = dedicatedRequestConnection;
|
||||
|
||||
foreach (var ptg in PeriodicTaskRegistrations)
|
||||
@@ -538,6 +539,19 @@ namespace CryptoExchange.Net.Clients
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Process connect rate limited
|
||||
/// </summary>
|
||||
protected async virtual Task HandleConnectRateLimitedAsync()
|
||||
{
|
||||
if (ClientOptions.RateLimiterEnabled && RateLimiter is not null && ClientOptions.ConnectDelayAfterRateLimited is not null)
|
||||
{
|
||||
var retryAfter = DateTime.UtcNow.Add(ClientOptions.ConnectDelayAfterRateLimited.Value);
|
||||
_logger.AddingRetryAfterGuard(retryAfter);
|
||||
await RateLimiter.SetRetryAfterGuardAsync(retryAfter, RateLimiting.RateLimitItemType.Connection).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connect a socket
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user