1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-08-22 22:02:59 +00:00

Feature/ratelimit refactor (#197)

This commit is contained in:
Jan Korf
2024-04-16 14:55:27 +02:00
committed by GitHub
parent 2dbd5be924
commit 1b1961db00
57 changed files with 2294 additions and 688 deletions
@@ -0,0 +1,60 @@
using System;
namespace CryptoExchange.Net.RateLimiting
{
/// <summary>
/// Limit check
/// </summary>
public readonly struct LimitCheck
{
/// <summary>
/// Is guard applicable
/// </summary>
public bool Applicable { get; }
/// <summary>
/// Delay needed
/// </summary>
public TimeSpan Delay { get; }
/// <summary>
/// Current counter
/// </summary>
public int Current { get; }
/// <summary>
/// Limit
/// </summary>
public int? Limit { get; }
/// <summary>
/// Time period
/// </summary>
public TimeSpan? Period { get; }
private LimitCheck(bool applicable, TimeSpan delay, int limit, TimeSpan period, int current)
{
Applicable = applicable;
Delay = delay;
Limit = limit;
Period = period;
Current = current;
}
/// <summary>
/// Not applicable
/// </summary>
public static LimitCheck NotApplicable { get; } = new LimitCheck(false, default, default, default, default);
/// <summary>
/// No wait needed
/// </summary>
public static LimitCheck NotNeeded { get; } = new LimitCheck(true, default, default, default, default);
/// <summary>
/// Wait needed
/// </summary>
/// <param name="delay">The delay needed</param>
/// <param name="limit">Limit per period</param>
/// <param name="period">Period the limit is for</param>
/// <param name="current">Current counter</param>
/// <returns></returns>
public static LimitCheck Needed(TimeSpan delay, int limit, TimeSpan period, int current) => new(true, delay, limit, period, current);
}
}