package polymarket
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page
Module Polymarket_rate_limiter.Rate_limiterSource
Route-based rate limiting for HTTP clients.
This library provides GCRA-based rate limiting with route matching, supporting multiple limits per route and configurable delay/error behaviors.
Quick Start
(* Create a shared rate limiter with Polymarket API limits *)
let routes = Polymarket_common.Rate_limit_presets.all ~behavior:Delay in
let rate_limiter =
Rate_limiter.create ~routes ~clock:(Eio.Stdenv.clock env) ()
in
(* Pass to all API clients *)
let gamma = Gamma.create ~sw ~net ~rate_limiter () in
let data = Data.create ~sw ~net ~rate_limiter () inFeatures
- Route matching: Match requests by host, HTTP method, and path prefix
- Multiple limits: Stack burst and sustained limits on the same route
- GCRA algorithm: Fair rate limiting using Generic Cell Rate Algorithm
- Configurable behavior: Delay requests or return errors per route
Core Types
Route matching pattern
Rate limit configuration
Source
type route_config = Types.route_config = {pattern : route_pattern;limits : limit_config list;behavior : behavior;
}Complete route configuration
Rate Limiter
Rate limiter state
Raised by before_request when behavior is Error and limit exceeded
Source
val create :
routes:route_config list ->
clock:_ Eio.Time.clock ->
?max_idle_time:float ->
unit ->
tCreate a rate limiter with custom routes.
Update the rate limit routes at runtime
Check rate limits before making a request.
- For
Delaybehavior: sleeps until the request is allowed - For
Errorbehavior: raisesRate_limit_exceededif limit exceeded
Like before_request but returns a result instead of raising.
State Management
Sub-modules
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page