Skip to content

Commit

Permalink
FiatApi: improve setting reported usages on rate limit
Browse files Browse the repository at this point in the history
Set usages with mode increase-only, for highest usages to eventually survive,
in case of responses of parallel requests arriving out of order, and to avoid
removing counts of additional requests sent in the meantime.
  • Loading branch information
danimoh committed Aug 15, 2024
1 parent 4f56689 commit 0088459
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/fiat-api/FiatApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,10 @@ async function _fetch<T>(
&& typeof parsedResponse.RateLimit?.max_calls?.[timePeriod] === 'number',
)) {
const { calls_made: usages, max_calls: limits } = parsedResponse.RateLimit;
rateLimitScheduler.setUsages(usages);
// Set usages with mode increase-only, for highest usages to eventually survive, in case of responses of
// parallel requests arriving out of order, and to avoid removing counts of additional requests sent in
// the meantime.
rateLimitScheduler.setUsages(usages, 'increase-only');
// Ignore daily and monthly limits in hopes of the usage being reset earlier than on day or month reset,
// for example by IP change, but limit parallel requests when the daily or monthly limit is hit to avoid
// unnecessary parallel requests, see above. The parallel limit is reset on the next successful request.
Expand Down

0 comments on commit 0088459

Please sign in to comment.