Polymarket_rate_limiter.GcraSourceGeneric 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:
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.
GCRA state for a single limit
Create a new GCRA state from a limit configuration
Check if a request is allowed at the given time.
Update state after a request is allowed. Must be called after check returns Ok () and before releasing any locks.
Combined check and update. Atomically checks if allowed and updates state.
Calculate seconds until the next request can proceed
Get the emission interval (time between requests at sustained rate)