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:
- Binance --
x-mbx-used-weight-1morx-sapi-used-ip-weight-1m - Bybit --
x-bapi-limit,x-bapi-limit-status,x-bapi-limit-reset-timestamp - 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
@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.