Automated dump-and-hedge trading for Polymarket’s 15-minute crypto Up/Down markets — written in TypeScript, built on the official CLOB client, and designed to run hands-free across BTC, ETH, SOL, and XRP.
Short-dated prediction markets move fast. When one side dumps in seconds, the other side often lags — and if you can buy both legs cheaply enough, their combined cost can sit below $1 per paired share, locking in a structural edge before resolution.
This bot watches those markets continuously, detects sharp moves that match your thresholds, executes a two-leg cycle (dump capture → hedge), and tracks P&L — with optional simulation so you can validate behavior before risking capital.
| Capability | Description |
|---|---|
| Multi-asset | Trade one or many markets: btc, eth, sol, xrp (comma-separated). |
| Auto-discovery | Resolves the active 15m Up/Down market per asset from Polymarket’s Gamma API and rolls forward each new period. |
| Dump detection | Uses recent ask history to flag a leg when price falls by your move threshold within a short time window. |
| Hedge logic | After leg 1, waits for leg 2 when leg1 entry + opposite ask ≤ your sum target (e.g. 0.95). |
| Risk controls | Configurable stop-loss hedge if the favorable hedge does not appear within N minutes. |
| Settlement | On market close, reconciles winners/losers and can redeem winning positions on-chain (production). |
| Logging | Streams activity to stderr and appends a history file for review and auditing. |
New 15m round
│
▼
┌─────────────────┐ rapid drop on Up or Down ┌──────────────┐
│ Watch window │ ───────────────────────────────► │ Buy dumped │
│ (first N min) │ │ leg (Leg 1) │
└─────────────────┘ └──────┬───────┘
│
opposite ask cheap enough │
(sum ≤ target) ▼
┌──────────────┐
│ Buy hedge │
│ (Leg 2) │
└──────┬───────┘
│
timeout? ──────────────────────────────┤
▼
Stop-loss hedge path
This is a simplified view of the logic implemented in the trader module; tune all thresholds via environment variables.
- Runtime: Node.js 16+
- Language: TypeScript
- Polymarket:
@polymarket/clob-client(orders, auth), Gamma + CLOB HTTP APIs (markets, prices) - Chain: Polygon (USDC, CTF redemption flow)
- Node.js 16 or newer
- A Polymarket-compatible wallet and (for live trading) USDC on Polygon and understanding of proxy vs EOA signing (
SIGNATURE_TYPEin.env)
git clone https://github.com/apechurch/polymarket-arbitrage-trading-bot.git
cd polymarket-arbitrage-trading-bot
npm install
cp .env.example .env
# Edit .env — see table below
npm run build| Command | Purpose |
|---|---|
npm run dev |
Run from TypeScript with ts-node (handy for development). |
npm run typecheck |
Run TypeScript type checks without building output. |
npm run clean |
Remove compiled output in dist. |
npm run sim |
Simulation — logs trades, no real orders (--simulation). |
npm run prod |
Production — real CLOB orders (--production). |
npm start |
Same as build output; default CLI behavior favors simulation unless you pass --production. |
Important: For live trading, set PRODUCTION=true in .env and use npm run prod (or node dist/main.js --production) so the process does not stay in simulation mode.
Copy .env.example to .env and adjust.
| Variable | Role |
|---|---|
PRIVATE_KEY |
Required for real orders and redemption. |
PROXY_WALLET_ADDRESS |
Polymarket proxy/profile address if applicable. |
SIGNATURE_TYPE |
0 EOA, 1 Proxy, 2 Gnosis Safe (default in example: 2). |
MARKETS |
e.g. btc or btc,eth,sol,xrp |
CHECK_INTERVAL_MS |
How often to poll prices (default 1000). |
DUMP_HEDGE_SHARES |
Size per leg (shares). |
DUMP_HEDGE_SUM_TARGET |
Max combined price for hedge (e.g. 0.95). |
DUMP_HEDGE_MOVE_THRESHOLD |
Min fractional drop to count as a dump (e.g. 0.15 = 15%). |
DUMP_HEDGE_WINDOW_MINUTES |
Only look for dumps in the first N minutes of the round. |
DUMP_HEDGE_STOP_LOSS_MAX_WAIT_MINUTES |
Force hedge path if no arb within this time. |
PRODUCTION |
false = simulation-friendly config flag; use --production for live execution. |
Optional: GAMMA_API_URL, CLOB_API_URL, API_KEY / API_SECRET / API_PASSPHRASE if your setup requires them.
src/
main.ts # Entry: discovery, monitors, period rollover
monitor.ts # Price polling & snapshots
dumpHedgeTrader.ts # Dump → hedge → stop-loss → settlement tracking
api.ts # Gamma, CLOB, orders, redemption, activity
config.ts # Environment loading
models.ts # Shared types
logger.ts # History file + stderr
This software is provided for educational and research purposes only. Prediction markets and automated trading involve substantial financial risk, including possible total loss. Past or simulated behavior does not guarantee future results. You are solely responsible for compliance with applicable laws, exchange terms, and tax obligations. Nothing here is investment, legal, or tax advice.
- Run in simulation first and inspect
history.tomlbehavior across multiple rounds. - Start with low
DUMP_HEDGE_SHARESand conservative thresholds in production. - Keep private keys out of source control and rotate compromised credentials immediately.
Issues and pull requests are welcome: strategy ideas, safer defaults, tests, and clearer docs help everyone.
See CONTRIBUTING.md for local workflow and commit guidelines.
Failed to fetch market/orderbookoften means temporary API/network errors; keep retries conservative and verify endpoint connectivity.- If orders fail in production, verify
PRIVATE_KEY,SIGNATURE_TYPE, and proxy wallet settings match your Polymarket account mode. - If no market is found, ensure
MARKETSonly includes supported assets (btc,eth,sol,xrp) and wait for the next 15m round.
Add a LICENSE file to your fork or distribution; this template does not ship one by default.