Setup Guide
Install and configure the polymarket twap trading bot in minutes.
Requirements
- Node.js ≥ 18
- A funded Polymarket account with API credentials
- (Optional) Dedicated Polygon RPC endpoint for lower-latency reads
Quick start
git clone https://github.com/ruudkoeyvoets/polymarket-trading-bot-twap.git
cd polymarket-trading-bot-twap
npm install
cp .env.example .env # add your Polymarket API credentials
npm run start
Environment variables
| Variable | Description | Default |
|---|---|---|
POLYMARKET_API_KEY | Polymarket API key | — |
POLYMARKET_API_SECRET | API secret | — |
POLYMARKET_PASSPHRASE | API passphrase | — |
CHAINLINK_FEED_ID_BTC | Chainlink feed ID for BTC | — |
CHAINLINK_FEED_ID_ETH | Chainlink feed ID for ETH | — |
GAMMA_API | Polymarket Gamma API | https://gamma-api.polymarket.com |
DATA_API | Polymarket Data API | https://data-api.polymarket.com |
CLOB_API | Polymarket CLOB API | https://clob.polymarket.com |
TWAP_GAP_POLICY | Missing TWAP sample handling | carry_forward |
TWAP_VALIDATION_TOLERANCE_BPS | TWAP validation tolerance (bps) | 2.0 |
POLYGON_RPC_URL | Polygon RPC endpoint | https://polygon-rpc.com |
TWAP_WINDOW_5M | 5-minute contract window (seconds) | 30 |
TWAP_WINDOW_15M_4H | 15m/4h contract window (seconds) | 60 |
MAX_FEED_STALENESS_MS | Max oracle lag before sitting out | 2000 |
TRADE_THRESHOLD | Minimum edge to trade | 0.02 |
RTDS_WS_URL | Chainlink RTDS WebSocket | wss://ws-live-data.polymarket.com |
SYMBOLS | Symbols to track | btc/usd,eth/usd |
MAX_POSITION_USD | Per-market exposure cap | 100 |
MAX_DAILY_LOSS_USD | Daily loss limit | 500 |
LOG_LEVEL | Logging verbosity | info |
See .env.example in the repository for the full list.
Before going live
- Read the TWAP Guide to understand settlement windows
- Start with small
MAX_POSITION_USDlimits - Verify oracle feed connectivity and staleness thresholds
- Run backtesting mode against reconstructed TWAP windows if available
- Monitor the live account on Polymarket