CCXT.RateLimiter.Headers (ccxt_client v0.6.1)

Copy Markdown View Source

Parses rate limit status headers from exchange API responses.

Exchanges return rate limit information with every response, not just 429s. This module detects the header pattern and extracts normalized rate limit data.

Supported Patterns

Patterns are tried in order; the first match wins:

  1. Binance -- x-mbx-used-weight-1m or x-sapi-used-ip-weight-1m
  2. Bybit -- x-bapi-limit, x-bapi-limit-status, x-bapi-limit-reset-timestamp
  3. Standard -- x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset

Exchanges without custom rate limit headers (OKX, Kraken) return :none.

Summary

Functions

Parses rate limit headers from a response.

Functions

parse(exchange_id, headers, spec_rate_limit \\ nil)

@spec parse(String.t(), %{required(String.t()) => [String.t()]}, number() | nil) ::
  {:ok, CCXT.RateLimiter.Info.t()} | :none

Parses rate limit headers from a response.

Headers are in Req format: %{String.t() => [String.t()]} with lowercase keys.

spec_rate_limit is the exchange's rate_limit_ms value (milliseconds between requests). Converted to max requests per minute (60_000 / rate_limit_ms) to derive limit when the exchange only reports used (e.g., Binance).

Returns {:ok, %Info{}} if rate limit headers are found, :none otherwise.