1
0
mirror of https://github.com/JKorf/CryptoExchange.Net.git synced 2026-10-06 11:21:10 +00:00
Files
CryptoExchange.Net/CryptoExchange.Net/RateLimiting/RateLimitAdmission.cs
T
Jan Korf ae7504c26c Shared API's V2 (#289)
Added V2 Shared API's infrastructure
Added request coalescing
Added rate limiting admission logic
Fixed some rate limiting issues
2026-09-23 09:15:39 +02:00

33 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.RateLimiting
{
/// <summary>
/// Rate limit admission decision result
/// </summary>
public record RateLimitAdmission
{
/// <summary>
/// Value ratio between 0 and 1
/// </summary>
public double MaxUtilizationRatio { get; }
private RateLimitAdmission(double maxUtilizationValue) {
if (maxUtilizationValue <= 0 || maxUtilizationValue > 1)
throw new ArgumentOutOfRangeException(nameof(maxUtilizationValue), "Max utilization value must be bigger than 0 and less than or equal to 1");
MaxUtilizationRatio = maxUtilizationValue;
}
/// <summary>
/// Only allow the request when below a certain ratio of the rate limit, for example 0.5 means it can use a max of 50% of the rate limit,
/// 1 means it's allowed to use the full rate limit.
/// </summary>
/// <param name="value">0.5 means a max use 50% of the rate limit, 1 means the request is allowed to use the full rate limit</param>
public static RateLimitAdmission WithMaxUtilizationRatio(double value)
=> new RateLimitAdmission(value);
}
}