package polymarket

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Polymarket_rate_limiter.GcraSource

Generic Cell Rate Algorithm (GCRA) for rate limiting.

GCRA tracks a theoretical arrival time (TAT) for the next request. It provides fair rate limiting with configurable burst capacity.

For a limit of N requests per T seconds:

  • Sustained rate: N/T requests per second
  • Burst capacity: N requests (the full quota can be used immediately)

The algorithm ensures that over any T-second window, no more than N requests are allowed, while permitting short bursts when there's available quota.

Sourcetype t

GCRA state for a single limit

Sourceval create : Types.limit_config -> t

Create a new GCRA state from a limit configuration

Sourceval check : t -> now:float -> (unit, float) result

Check if a request is allowed at the given time.

  • parameter now

    Current time in seconds (e.g., from Eio.Time.now)

  • returns

    Ok () if allowed, Error retry_after if rate limited

Sourceval update : t -> now:float -> unit

Update state after a request is allowed. Must be called after check returns Ok () and before releasing any locks.

Sourceval check_and_update : t -> now:float -> (unit, float) result

Combined check and update. Atomically checks if allowed and updates state.

  • returns

    Ok () if allowed, Error retry_after if rate limited

Sourceval reset : t -> unit

Reset the state (for testing)

Sourceval time_until_ready : t -> now:float -> float

Calculate seconds until the next request can proceed

Sourceval emission_interval : t -> float

Get the emission interval (time between requests at sustained rate)

Sourceval burst_allowance : t -> float

Get the burst allowance in seconds