mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-16 19:03:01 +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:
@@ -71,6 +71,11 @@ namespace CryptoExchange.Net.Sockets
|
||||
/// </summary>
|
||||
public event Action<IMessageAccessor>? UnhandledMessage;
|
||||
|
||||
/// <summary>
|
||||
/// Connection was rate limited and couldn't be established
|
||||
/// </summary>
|
||||
public Func<Task>? ConnectRateLimitedAsync;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of subscriptions on this connection
|
||||
/// </summary>
|
||||
@@ -222,6 +227,7 @@ namespace CryptoExchange.Net.Sockets
|
||||
_socket.OnStreamMessage += HandleStreamMessage;
|
||||
_socket.OnRequestSent += HandleRequestSentAsync;
|
||||
_socket.OnRequestRateLimited += HandleRequestRateLimitedAsync;
|
||||
_socket.OnConnectRateLimited += HandleConnectRateLimitedAsync;
|
||||
_socket.OnOpen += HandleOpenAsync;
|
||||
_socket.OnClose += HandleCloseAsync;
|
||||
_socket.OnReconnecting += HandleReconnectingAsync;
|
||||
@@ -385,6 +391,16 @@ namespace CryptoExchange.Net.Sockets
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handler for whenever a connection was rate limited and couldn't be established
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected async virtual Task HandleConnectRateLimitedAsync()
|
||||
{
|
||||
if (ConnectRateLimitedAsync is not null)
|
||||
await ConnectRateLimitedAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handler for whenever a request is sent over the websocket
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user