security(polymarket-browse): add token bucket rate limiter for API calls #36

Closed
shoko wants to merge 0 commits from security/10-rate-limiting into master
Owner

Summary

Add token bucket rate limiter to prevent overwhelming the Polymarket API.

Changes

  • Add RateLimiter class using token bucket algorithm
  • Thread-safe for use with ThreadPoolExecutor
  • RATE_LIMIT_CALLS = 10 per RATE_LIMIT_WINDOW = 1.0 second
  • _rate_limiter.acquire() called before each API request
  • Also includes MAX_RESPONSE_SIZE check (10MB limit)

Design

  • Token bucket allows bursts up to 10 concurrent requests
  • Maintains average rate of 10 requests/second
  • Thread-safe via _lock

Testing

70/70 tests passing

## Summary Add token bucket rate limiter to prevent overwhelming the Polymarket API. ## Changes - Add `RateLimiter` class using token bucket algorithm - Thread-safe for use with `ThreadPoolExecutor` - `RATE_LIMIT_CALLS = 10` per `RATE_LIMIT_WINDOW = 1.0` second - `_rate_limiter.acquire()` called before each API request - Also includes `MAX_RESPONSE_SIZE` check (10MB limit) ## Design - Token bucket allows bursts up to 10 concurrent requests - Maintains average rate of 10 requests/second - Thread-safe via `_lock` ## Testing 70/70 tests passing
shoko added 1 commit 2026-03-26 20:15:22 +01:00
- Add RateLimiter class (token bucket algorithm)
- Thread-safe for use with ThreadPoolExecutor
- RATE_LIMIT_CALLS = 10 per RATE_LIMIT_WINDOW = 1 second
- _rate_limiter.acquire() called before each API request
- Also add MAX_RESPONSE_SIZE check in fetch_page
shoko reviewed 2026-03-27 01:51:04 +01:00
shoko left a comment
Author
Owner

Review requested

Review requested
shoko added the need review label 2026-03-27 01:52:47 +01:00
Collaborator

for the MAX_RESPONSE_SIZE I think you should wait the PR #35 to be merged first. the rest is ok we can merge them

for the MAX_RESPONSE_SIZE I think you should wait the PR #35 to be merged first. the rest is ok we can merge them
han added approvedneed adjustment and removed need review labels 2026-03-27 02:34:31 +01:00
han approved these changes 2026-03-27 02:34:39 +01:00
han left a comment
Collaborator

lgtm

lgtm
shoko closed this pull request 2026-03-27 04:09:45 +01:00

Pull request closed

Sign in to join this conversation.
No Reviewers
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shoko/jujutsu-skills#36