mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
Updated rate limiters to support multiple instances
This commit is contained in:
parent
48e2e6468e
commit
69a7a714cd
@ -117,10 +117,10 @@ namespace CryptoExchange.Net.Objects
|
|||||||
{
|
{
|
||||||
int totalWaitTime = 0;
|
int totalWaitTime = 0;
|
||||||
|
|
||||||
EndpointRateLimiter? endpointLimit;
|
List<EndpointRateLimiter> endpointLimits;
|
||||||
lock (_limiterLock)
|
lock (_limiterLock)
|
||||||
endpointLimit = _limiters.OfType<EndpointRateLimiter>().SingleOrDefault(h => h.Endpoints.Contains(endpoint) && (h.Method == null || h.Method == method));
|
endpointLimits = _limiters.OfType<EndpointRateLimiter>().Where(h => h.Endpoints.Contains(endpoint) && (h.Method == null || h.Method == method)).ToList();
|
||||||
if(endpointLimit != null)
|
foreach (var endpointLimit in endpointLimits)
|
||||||
{
|
{
|
||||||
var waitResult = await ProcessTopic(logger, endpointLimit, endpoint, requestWeight, limitBehaviour, ct).ConfigureAwait(false);
|
var waitResult = await ProcessTopic(logger, endpointLimit, endpoint, requestWeight, limitBehaviour, ct).ConfigureAwait(false);
|
||||||
if (!waitResult)
|
if (!waitResult)
|
||||||
@ -129,7 +129,7 @@ namespace CryptoExchange.Net.Objects
|
|||||||
totalWaitTime += waitResult.Data;
|
totalWaitTime += waitResult.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endpointLimit?.IgnoreOtherRateLimits == true)
|
if (endpointLimits.Any(l => l.IgnoreOtherRateLimits))
|
||||||
return new CallResult<int>(totalWaitTime);
|
return new CallResult<int>(totalWaitTime);
|
||||||
|
|
||||||
List<PartialEndpointRateLimiter> partialEndpointLimits;
|
List<PartialEndpointRateLimiter> partialEndpointLimits;
|
||||||
@ -169,10 +169,10 @@ namespace CryptoExchange.Net.Objects
|
|||||||
if(partialEndpointLimits.Any(p => p.IgnoreOtherRateLimits))
|
if(partialEndpointLimits.Any(p => p.IgnoreOtherRateLimits))
|
||||||
return new CallResult<int>(totalWaitTime);
|
return new CallResult<int>(totalWaitTime);
|
||||||
|
|
||||||
ApiKeyRateLimiter? apiLimit;
|
List<ApiKeyRateLimiter> apiLimits;
|
||||||
lock (_limiterLock)
|
lock (_limiterLock)
|
||||||
apiLimit = _limiters.OfType<ApiKeyRateLimiter>().SingleOrDefault(h => h.Type == RateLimitType.ApiKey);
|
apiLimits = _limiters.OfType<ApiKeyRateLimiter>().Where(h => h.Type == RateLimitType.ApiKey).ToList();
|
||||||
if (apiLimit != null)
|
foreach (var apiLimit in apiLimits)
|
||||||
{
|
{
|
||||||
if(apiKey == null)
|
if(apiKey == null)
|
||||||
{
|
{
|
||||||
@ -206,13 +206,13 @@ namespace CryptoExchange.Net.Objects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((signed || apiLimit?.OnlyForSignedRequests == false) && apiLimit?.IgnoreTotalRateLimit == true)
|
if ((signed || apiLimits.All(l => !l.OnlyForSignedRequests)) && apiLimits.Any(l => l.IgnoreTotalRateLimit))
|
||||||
return new CallResult<int>(totalWaitTime);
|
return new CallResult<int>(totalWaitTime);
|
||||||
|
|
||||||
TotalRateLimiter? totalLimit;
|
List<TotalRateLimiter> totalLimits;
|
||||||
lock (_limiterLock)
|
lock (_limiterLock)
|
||||||
totalLimit = _limiters.OfType<TotalRateLimiter>().SingleOrDefault();
|
totalLimits = _limiters.OfType<TotalRateLimiter>().ToList();
|
||||||
if (totalLimit != null)
|
foreach(var totalLimit in totalLimits)
|
||||||
{
|
{
|
||||||
var waitResult = await ProcessTopic(logger, totalLimit, endpoint, requestWeight, limitBehaviour, ct).ConfigureAwait(false);
|
var waitResult = await ProcessTopic(logger, totalLimit, endpoint, requestWeight, limitBehaviour, ct).ConfigureAwait(false);
|
||||||
if (!waitResult)
|
if (!waitResult)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user