No description
- Python 76.5%
- HCL 18.9%
- Makefile 4.6%
| terraform | ||
| .gitignore | ||
| check_latency.py | ||
| invoke_and_report.py | ||
| Makefile | ||
| README.md | ||
| requirements.txt | ||
Polymarket Latency Checker
A tool to measure real-time latency between Polymarket's CLOB WebSocket and various AWS regions (US, EU, Spain, and Tokyo).
Architecture
- Lambda Layer: A Python script (
check_latency.py) that connects to Polymarket'sws-subscriptions-clobWebSocket, subscribes to an active market, and calculates the difference between the server's message timestamp and the local arrival time for 30 seconds. - Infrastructure: Managed with Terraform 6.0, deploying the same Lambda function to 6 global regions using
for_each. - Runner: A local Python script (
invoke_and_report.py) that triggers all Lambdas concurrently and generates a comparative report.
Regions Included
us-east-1(N. Virginia)us-west-2(Oregon)eu-west-1(Ireland)eu-central-1(Frankfurt)eu-south-2(Spain - Madrid)ap-northeast-1(Tokyo)eu-west-2(London)
Prerequisites
- uv (Fast Python package manager)
- Terraform (>= 1.0)
- AWS CLI configured with appropriate credentials.
Usage
1. Deploy Infrastructure
This will package the Python dependencies, initialize Terraform, and deploy the Lambdas to all regions.
make deploy
2. Run Latency Test
This will invoke all Lambdas simultaneously, wait for 30 seconds of data collection, and print a consolidated report.
make run-test
3. Clean up
Remove local build artifacts and Terraform plans.
make clean
To destroy infrastructure:
cd terraform && terraform destroy
Statistics Provided
The final report includes:
- Min/Max: Extreme latency values captured.
- Mean (Avg): Average latency.
- p50 (Median): 50th percentile.
- p95/p99: Tail latency indicators (critical for trading).
- StdDev: Stability of the connection.
- Count: Number of messages processed during the window.
Important Note
The Spain region (eu-south-2) may need to be explicitly enabled in your AWS Account console to avoid deployment errors.