package polymarket

  1. Overview
  2. Docs
OCaml client library for the Polymarket prediction market API

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.2.0.tar.gz
md5=4eb4c5d2f63ff081c9713d90be5a51b2
sha512=0e3de0c9b40683e09ab8f9f966a44784ef1b9b482c3eefef84104a7e8042c92f1d79893ee9588b24fa3d0decaed7f365509f4d1c23c66ce8328efb64e721f276

doc/polymarket.rate_limiter/Polymarket_rate_limiter/Gcra/index.html

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