CCXT.RateLimiter.Info (ccxt_client v0.6.1)

Copy Markdown View Source

Rate limit status information parsed from exchange response headers.

Exchanges report rate limit status with every API response (not just 429s). This struct captures that information in a normalized format.

Sources

Different exchanges use different header patterns:

SourceExchangeHeaders
:binance_weightBinancex-mbx-used-weight-1m, x-sapi-used-ip-weight-1m
:bybit_bapiBybitx-bapi-limit, x-bapi-limit-status, x-bapi-limit-reset-timestamp
:standardKuCoin, othersx-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset

Summary

Functions

Returns true if remaining capacity is below the threshold percentage.

Returns the percentage of rate limit capacity used (0.0 to 100.0).

Returns milliseconds to wait until the rate limit window resets.

Types

t()

@type t() :: %CCXT.RateLimiter.Info{
  exchange: String.t() | nil,
  limit: non_neg_integer() | nil,
  raw_headers: %{required(String.t()) => String.t()},
  remaining: non_neg_integer() | nil,
  reset_at: integer() | nil,
  source: atom(),
  used: non_neg_integer() | nil
}

Functions

should_wait?(info, threshold \\ 0.1)

@spec should_wait?(t(), float()) :: boolean()

Returns true if remaining capacity is below the threshold percentage.

Threshold is a float between 0.0 and 1.0 representing the fraction of total capacity. Default is 0.1 (10%).

Returns false if limit or remaining data is not available.

usage_percent(info)

@spec usage_percent(t()) :: float() | nil

Returns the percentage of rate limit capacity used (0.0 to 100.0).

Returns nil if insufficient data to calculate usage.

wait_time(info)

@spec wait_time(t()) :: non_neg_integer()

Returns milliseconds to wait until the rate limit window resets.

Returns 0 if no reset time is available or the reset time has already passed.