- One-time in the
polymarket-botfolder:python -m venv .venvthen.venv\Scripts\python.exe -m pip install -e . - Every time: double-click
run-hub.batin that folder, or in Cursor’s terminal:
cd C:\Users\you\Prediction_Agents\polymarket-bot
.\.venv\Scripts\python.exe -m pm_bot --hubKeeps the window open on errors (run-hub.bat ends with pause). Remove pause from the .bat if you prefer it to exit immediately.
This is a minimal, dry-run by default scaffold for a Polymarket CLOB trading bot:
- Loads secrets from environment variables (never hardcode keys)
- Connects via
py-clob-client - Implements a simple “probability vs market price” decision rule
- Includes basic risk limits, optional polling loop, and persisted notional position
- Uses the real client API (
OrderArgs,create_and_post_order,OrderBookSummary)
This project follows the Polymarket CLOB overview and authentication model:
- L1: your private key derives L2 API credentials (
create_or_derive_api_credsinpy-clob-client). - L2: signed orders are posted with HMAC headers; the SDK handles this after
set_api_creds. - Secrets: use env vars or a secrets manager; never commit keys (
.envis git-ignored). - Signature type + funder: If you use a Polymarket.com account (proxy wallet), set
POLY_SIGNATURE_TYPE=2(GNOSIS_SAFE) andPOLY_FUNDER_ADDRESSto your profile wallet from settings. Omitting these defaults the SDK to EOA (0) — correct only for a standalone key that holds funds directly. - Server / VPS: run the bot on the server only; do not put
POLY_PRIVATE_KEYor API secrets in browser code.
Create and activate a virtualenv, then install the package (recommended) or dependencies only:
cd polymarket-bot
python -m venv .venv
.venv\Scripts\activate
python -m pip install -e .Alternatively: python -m pip install -r requirements.txt (editable install is preferred so pm_bot is importable from any directory).
Environment file:
pm_bot/env.prefill— full commented template (safe to commit). Copy it topm_bot/.env(git-ignored) and fill in at leastPOLY_TOKEN_ID_YESandPOLY_TOKEN_ID_NO.- If you only use the repo root, copy
.env.exampleto.envthere instead.
- Live trading:
POLY_PRIVATE_KEYorPRIVATE_KEYis required (orders are EIP-712 signed). Optionally setPOLY_API_KEY/POLY_API_SECRET/POLY_API_PASSPHRASEif you already have L2 creds; otherwise the client derives them. - Dry-run, quotes only: omit the private key, keep
BOT_DRY_RUN=true. Read-only CLOB endpoints need no auth.
| Variable | Purpose |
|---|---|
POLY_TOKEN_ID_YES / POLY_TOKEN_ID_NO |
Required — outcome token IDs for one market |
POLY_PRIVATE_KEY or PRIVATE_KEY |
Required when BOT_DRY_RUN=false |
POLY_SIGNATURE_TYPE |
Optional. 0 EOA, 1 POLY_PROXY, 2 GNOSIS_SAFE (typical for polymarket.com) |
POLY_FUNDER_ADDRESS or FUNDER_ADDRESS |
Optional. Proxy wallet that holds collateral (required with types 1–2 when applicable) |
BOT_DRY_RUN |
Default true — no orders posted |
BOT_POLL_INTERVAL_SEC |
0 = single run; >0 = loop (seconds between iterations) |
PM_BOT_STATE_FILE |
JSON file tracking estimated USD notional after live fills (default .pm_bot_state.json) |
See pm_bot/env.prefill (or .env.example in the repo root) for the full template.
From the polymarket-bot directory (so .env is found), either:
Unified hub (recommended) — one terminal: Agent tab (primary) and Trading bot tab (Polymarket, secondary). Trading polling runs only while the Trading tab is active.
python -m pm_bot --hub
# or: pm-hub
# or set BOT_UI=hub in .envExtend the agent by editing pm_bot/agent.py (handle_message). Plug in an LLM, call another repo, etc.
Bot-only modes (no agent UI):
python -m pm_botor, after pip install -e .:
pm-botTerminal UI
- Trading-only Textual TUI:
python -m pm_bot --tui— same keyboard tuning as the Trading tab in the hub. - Rich dashboard (default in a real terminal): order book, signal, risk, and decision in panels. Use
BOT_UI=richor rely on the default. - Plain logs:
BOT_UI=plainorpython -m pm_bot --ui plain - JSON (for scripting / “pretty structure”):
BOT_UI=jsonorpython -m pm_bot --json
With BOT_POLL_INTERVAL_SEC greater than 0, the screen refreshes each tick; config is reloaded every iteration so you can edit .env and see changes on the next cycle (the API client is recreated only if host, keys, or token IDs change).
- Install Python 3.10+, clone the repo, create a venv,
pip install -e .. - Upload
pm_bot/.env(or/etc/polymarket-bot.env) with chmod 600; never commit it. - Use
BOT_UI=plainorBOT_UI=jsonunder systemd so logs go to the journal.--tuineeds an interactive terminal (SSH with TTY), not a typical service. - Example systemd
ExecStart:/srv/polymarket-bot/.venv/bin/python -m pm_botwithWorkingDirectory=/srv/polymarket-bot,EnvironmentFile=/srv/polymarket-bot/pm_bot/.env, andRestart=always. - Open outbound HTTPS to
clob.polymarket.com(no inbound port required for the bot). - Check Polymarket docs for geographic and product restrictions that apply to you.
- Replace
pm_bot/strategy.pywith your actual model (BTC 15m, ETH by 1pm, etc.) - Point the bot at a specific market by setting
POLY_TOKEN_ID_YESandPOLY_TOKEN_ID_NO - Flip
BOT_DRY_RUN=falseonly after you’ve tested with tiny size