Quant.Explorer.RateLimiter (quant v0.1.0-alpha.1)
Advanced rate limiter with pluggable backends and provider-specific configurations.
This module provides a high-level interface for rate limiting that supports:
- Multiple backends (ETS, Redis, GenServer)
- Provider-specific rate limiting patterns
- Complex algorithms (sliding window, token bucket, weighted requests)
- Distributed rate limiting capabilities
Usage
# Basic usage with default backend
{:ok, _} = Quant.Explorer.RateLimiter.start_link()
# Check and consume rate limit
case Quant.Explorer.RateLimiter.check_and_consume(:yahoo_finance, :history) do
:ok ->
# Request allowed, proceed
{:error, :rate_limited} ->
# Rate limited, wait or handle error
end
# Check limit without consuming
case Quant.Explorer.RateLimiter.check_limit(:binance, :klines, weight: 5) do
:ok -> # Would be allowed
{:error, :rate_limited} -> # Would be rate limited
end
Summary
Functions
Checks if a request is allowed and consumes the rate limit if so.
Checks if a request would be allowed without consuming the limit.
Returns a specification to start this module under a supervisor.
Consumes a rate limit without checking (for external request tracking).
Gets the current rate limit status for a provider/endpoint.
Gets rate limiting statistics.
Resets rate limits for a provider/endpoint.
Starts the rate limiter with the specified backend.
Waits until a request is allowed, with exponential backoff.
Functions
Checks if a request is allowed and consumes the rate limit if so.
This is the main function to use for rate limiting API requests.
Checks if a request would be allowed without consuming the limit.
Returns a specification to start this module under a supervisor.
See Supervisor.
Consumes a rate limit without checking (for external request tracking).
Gets the current rate limit status for a provider/endpoint.
Gets rate limiting statistics.
Resets rate limits for a provider/endpoint.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the rate limiter with the specified backend.
Waits until a request is allowed, with exponential backoff.