Requirements

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_KEYPolymarket API key
POLYMARKET_API_SECRETAPI secret
POLYMARKET_PASSPHRASEAPI passphrase
CHAINLINK_FEED_ID_BTCChainlink feed ID for BTC
CHAINLINK_FEED_ID_ETHChainlink feed ID for ETH
GAMMA_APIPolymarket Gamma APIhttps://gamma-api.polymarket.com
DATA_APIPolymarket Data APIhttps://data-api.polymarket.com
CLOB_APIPolymarket CLOB APIhttps://clob.polymarket.com
TWAP_GAP_POLICYMissing TWAP sample handlingcarry_forward
TWAP_VALIDATION_TOLERANCE_BPSTWAP validation tolerance (bps)2.0
POLYGON_RPC_URLPolygon RPC endpointhttps://polygon-rpc.com
TWAP_WINDOW_5M5-minute contract window (seconds)30
TWAP_WINDOW_15M_4H15m/4h contract window (seconds)60
MAX_FEED_STALENESS_MSMax oracle lag before sitting out2000
TRADE_THRESHOLDMinimum edge to trade0.02
RTDS_WS_URLChainlink RTDS WebSocketwss://ws-live-data.polymarket.com
SYMBOLSSymbols to trackbtc/usd,eth/usd
MAX_POSITION_USDPer-market exposure cap100
MAX_DAILY_LOSS_USDDaily loss limit500
LOG_LEVELLogging verbosityinfo

See .env.example in the repository for the full list.

Before going live

  1. Read the TWAP Guide to understand settlement windows
  2. Start with small MAX_POSITION_USD limits
  3. Verify oracle feed connectivity and staleness thresholds
  4. Run backtesting mode against reconstructed TWAP windows if available
  5. Monitor the live account on Polymarket

Clone the repository

Full source code and configuration on GitHub.

Open GitHub