[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-83930":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":16,"stars7d":17,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":18,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":20,"hasPages":20,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":30,"readmeContent":31,"aiSummary":10,"trendingCount":15,"starSnapshotCount":15,"syncStatus":32,"lastSyncTime":33,"discoverSource":34},83930,"polymarket-arbitrage-bot","sitodowubb\u002Fpolymarket-arbitrage-bot","sitodowubb","polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage polymarket arbitrage","",null,"TypeScript",229,7444,7,0,3,8,14,57.8,false,"main",[23,24,25,26,27,28,29],"arbitrage","bot","polymarket-arbitrae","polymarket-btc-5min-arbitrage-bot","polymarket-btc-arbitrage-bot","polymarket-crypto-sports-trading-bot","polymarket-trading-bot-strategies","2026-06-12 04:01:42","# Polymarket Arbitrage Bot\n\nPolymarket **arbitrage bot** for 15-minute Up\u002FDown markets. Automates the **dump-and-hedge** strategy with configurable thresholds, stop-loss hedging, and optional simulation mode. Full credential management, CLOB order execution, and market discovery via Gamma API.\n\n[![Node.js](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNode.js-16+-green.svg)](https:\u002F\u002Fnodejs.org\u002F)\n[![TypeScript](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FTypeScript-5+-blue.svg)](https:\u002F\u002Fwww.typescriptlang.org\u002F)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-Apache%202.0-yellow.svg)](LICENSE)\n\n\n![Portfolio](img.png)\n\n\n## 🎯 Overview\n\nThis **Polymarket arbitrage bot** runs a **dump-and-hedge** strategy on Polymarket’s 15m Up\u002FDown markets (e.g. BTC, ETH, SOL, XRP) by:\n\n- **Market discovery** – Finds the current 15m market per asset via Gamma API slug\n- **Price monitoring** – Polls CLOB orderbooks for Up\u002FDown bid\u002Fask and time remaining\n- **Dump detection** – In the first N minutes of each period, detects a sharp price drop on one side (Up or Down)\n- **Leg 1** – Buys the dumped side at the dip\n- **Hedge (Leg 2)** – Waits until combined cost (leg1 + opposite ask) is at or below target (e.g. ≤ 0.95), then buys the opposite side to lock in profit\n- **Stop-loss hedge** – If the hedge condition isn’t met within a max wait time, hedges anyway to limit risk\n- **Settlement** – On market close, redeems winning outcome tokens and tracks P&L\n- **Simulation mode** – Run without placing real orders (default); switch to production when ready\n- **Type-safe** – Full TypeScript with strict types and clear config via `.env`\n\nPerfect for automating the dump-and-hedge arbitrage on Polymarket 15m markets with controllable risk and optional dry-run.\n\n\u003C!-- Add screenshots\u002Fdemo images here -->\n\u003C!--\n![Bot Dashboard](docs\u002Fimages\u002Fdashboard.png)\n![Trade Execution](docs\u002Fimages\u002Ftrades.png)\n-->\n\n## ✨ Key Features\n\n### 🚀 Trading & Strategy\n- **Dump-and-hedge** – Buy the dip on one outcome, then hedge when sum of prices ≤ target\n- **Multi-market** – Supports multiple symbol\u002Ftimeframe pairs (configurable via `ARBITRAGE_MARKETS`, e.g. `btc:5m,btc:15m`)\n- **Automatic market discovery** – Resolves current 15m market by slug and period timestamp\n- **Period rollover** – Detects new 15m periods and switches to the new market automatically\n- **Stop-loss hedge** – Time-based fallback hedge if ideal hedge price isn’t reached\n\n### 🛡️ Risk & Safety\n- **Simulation by default** – No real orders until you set `PRODUCTION=true` or use `npm run prod`\n- **Configurable sizing** – Shares per leg, sum target, move threshold, and watch window\n- **Stop-loss parameters** – Max wait before forced hedge and stop-loss percentage\n- **Position tracking** – Per-period and total P&L; redemption of winning tokens on close\n\n### 🔧 Production-Ready\n- **Env-based config** – All settings in `.env` (no config files to commit)\n- **CLOB auth** – API key derivation from signer or optional explicit API key\u002Fsecret\u002Fpassphrase\n- **Proxy wallet support** – Optional Polymarket proxy\u002Fprofile address and signature type (EOA \u002F Proxy \u002F GnosisSafe)\n- **History logging** – Append-only `history.toml` for audit and debugging\n- **Graceful handling** – Continues monitoring on transient API errors; clear stderr logging\n\n## 🚀 Quick Start\n\n### Prerequisites\n\n- **Node.js 16+** – [Download Node.js](https:\u002F\u002Fnodejs.org\u002F)\n- **Polygon wallet** – With USDC for trading (production)\n- **POL\u002FMATIC** – For gas when redeeming winning tokens (production)\n\n### Installation\n\n```bash\n# Clone the repository\ngit clone https:\u002F\u002Fgithub.com\u002Fsitodowubb\u002Fpolymarket-arbitrage-bot.git\ncd polymarket-arbitrage-bot\n\n# Install dependencies\nnpm install\n\n# Build the project\nnpm run build\n```\n\n### Configuration\n\n1. **Create environment file:**\n```bash\ncp .env.example .env\n```\n\n2. **Edit `.env` with your settings:**\n```env\n# Wallet + auth (required in live mode)\nWALLET_PRIVATE_KEY=0x...              # Alias: PRIVATE_KEY\nPROXY_WALLET_ADDRESS=0x...            # Required when SIGNATURE_TYPE=1 or 2 (Alias: FUNDER_ADDRESS)\nSIGNATURE_TYPE=0                      # 0=EOA, 1=Proxy\u002FMagic, 2=GnosisSafe\n\n# APIs \u002F chain\nGAMMA_API_URL=https:\u002F\u002Fgamma-api.polymarket.com\nCLOB_API_URL=https:\u002F\u002Fclob.polymarket.com # Alias: CLOB_HOST\nCHAIN_ID=137\nPOLYGON_RPC_URL=https:\u002F\u002Fpolygon-rpc.com   # optional override for USDC preflight check\nAMOY_RPC_URL=https:\u002F\u002Frpc-amoy.polygon.technology # optional, used when CHAIN_ID != 137\n\n# Markets\nARBITRAGE_MARKETS=btc:5m,btc:15m\n\n# Mode\nSIMULATION_MODE=true                   # true=paper mode, false=live mode (Alias: PRODUCTION with inverse meaning)\n\n# Strategy tuning\nARBITRAGE_CHECK_INTERVAL_MS=5000\nARBITRAGE_ORDER_USD=20\nARBITRAGE_OBI_DEPTH_LEVELS=5\nARBITRAGE_TREND_THRESHOLD=0.05\n```\n\n3. **Run the bot:**\n```bash\n\n# Development – run TypeScript with ts-node\nnpm run dev\n```\n\nLogs go to stderr and are appended to `history.toml`.\n\n## ⚙️ Configuration Guide\n\n### Environment Variables\n\nThese are the environment variables currently used by the code.\n\n| Variable | Required | Description | Default |\n|----------|----------|-------------|---------|\n| `WALLET_PRIVATE_KEY` | Live mode | Private key used to sign CLOB requests. Alias: `PRIVATE_KEY` | - |\n| `PROXY_WALLET_ADDRESS` | Live mode when `SIGNATURE_TYPE` is `1` or `2` | Polymarket proxy\u002Fprofile wallet. Alias: `FUNDER_ADDRESS` | - |\n| `SIGNATURE_TYPE` | No | `0` EOA, `1` Proxy\u002FMagic, `2` GnosisSafe | `0` |\n| `GAMMA_API_URL` | No | Gamma API base URL (used for market discovery + proxy validation) | `https:\u002F\u002Fgamma-api.polymarket.com` |\n| `CLOB_API_URL` | No | CLOB API base URL. Alias: `CLOB_HOST` | `https:\u002F\u002Fclob.polymarket.com` |\n| `CHAIN_ID` | No | Network chain id (`137` Polygon mainnet) | `137` |\n| `POLYGON_RPC_URL` | No | RPC endpoint for Polygon USDC balance preflight check | `https:\u002F\u002Fpolygon-rpc.com` |\n| `AMOY_RPC_URL` | No | RPC endpoint for Amoy (used when `CHAIN_ID != 137`) | `https:\u002F\u002Frpc-amoy.polygon.technology` |\n| `SIMULATION_MODE` | No | `true` = paper mode, `false` = live orders | `false` |\n| `PRODUCTION` | No | Backward-compatible alias of mode with inverse semantics (`true` => live) | `false` |\n| `ARBITRAGE_MARKETS` | No | Comma-separated `symbol:timeframe` list | `btc:5m,btc:15m` |\n| `ARBITRAGE_CHECK_INTERVAL_MS` | No | Poll interval in milliseconds | `5000` |\n| `ARBITRAGE_ORDER_USD` | No | Order size in USDC per entry\u002Fswitch action | `20` |\n| `ARBITRAGE_OBI_DEPTH_LEVELS` | No | Orderbook bid depth levels used for OBI trend calc | `5` |\n| `ARBITRAGE_TREND_THRESHOLD` | No | OBI threshold above\u002Fbelow neutral trend | `0.05` |\n\n### Preflight checks (live mode)\n\nBefore trading starts, the bot validates:\n- `PRIVATE_KEY` ↔ `PROXY_WALLET_ADDRESS` binding via Gamma `public-profile`\n- USDC balance of trading wallet\u002Fproxy is `>= ARBITRAGE_ORDER_USD`\n\n## 📖 How It Works\n\n### Dump-and-hedge flow\n\n1. **Discovery** – For each target in `ARBITRAGE_MARKETS`, the bot finds the active Up\u002FDown market via Gamma slug matching.\n2. **Monitoring** – Every `ARBITRAGE_CHECK_INTERVAL_MS`, it fetches YES\u002FNO orderbooks and computes OBI trend from bid depth.\n3. **Entry** – If no position: buy YES on uptrend, buy NO on downtrend.\n4. **Neutral exit** – If trend is neutral and a position exists, sell current position.\n5. **Trend-follow hold** – Hold YES on uptrend and hold NO on downtrend.\n6. **Trend-flip switch** – If trend flips against the held side, sell and rotate into the new trend side.\n7. **Preflight safety** – In live mode, validates key\u002Fproxy binding and checks USDC balance is at least `ARBITRAGE_ORDER_USD`.\n\n### Simulation vs production\n\n- **Simulation** (`SIMULATION_MODE=true`): no orders sent to the CLOB; strategy logic and logging run as normal.\n- **Production** (`SIMULATION_MODE=false`): real orders sent to the CLOB. Requires `WALLET_PRIVATE_KEY`; set `PROXY_WALLET_ADDRESS` and `SIGNATURE_TYPE` for proxy\u002FGnosisSafe accounts.\n\n## 📦 Available Scripts\n\n| Command | Description |\n|---------|-------------|\n| `npm run dev` | Run with ts-node |\n\n\n\n## 🛠️ Troubleshooting\n\n### Bot doesn’t find markets\n- Confirm `ARBITRAGE_MARKETS` is valid `symbol:timeframe` pairs (example: `btc:5m,btc:15m`).\n- Check network access to Gamma and CLOB APIs; try default `GAMMA_API_URL` and `CLOB_API_URL` first.\n\n### Orders fail in production\n- Ensure `WALLET_PRIVATE_KEY` is set and correct (hex, with or without `0x`).\n- If using a proxy, set `PROXY_WALLET_ADDRESS` and `SIGNATURE_TYPE` (usually `2` for GnosisSafe).\n- Verify USDC balance and that the market is still active and accepting orders.\n\n### Redemption fails\n- Ensure you have enough POL for gas on Polygon.\n- Confirm the market is closed and resolved; the bot only redeems after resolution.\n\n### Strategy not entering trades\n- Lower `ARBITRAGE_TREND_THRESHOLD` if trend stays neutral too often.\n- Increase `ARBITRAGE_OBI_DEPTH_LEVELS` to smooth noisy orderbook signals.\n\n\n## 📚 Project structure\n\n- `src\u002Fmain.ts` – Entry point, config load, market discovery, and monitor\u002Ftrader wiring.\n- `src\u002Fconfig.ts` – Loads and validates `.env` into typed config.\n- `src\u002Fapi.ts` – Polymarket Gamma + CLOB API client (markets, orderbook, orders, redemption).\n- `src\u002Fmonitor.ts` – Fetches orderbook snapshots and drives the strategy callback.\n- `src\u002FdumpHedgeTrader.ts` – Dump detection, leg 1\u002F2, stop-loss hedge, closure and P&L.\n- `src\u002Fmodels.ts` – Shared types (Market, OrderBook, TokenPrice, etc.).\n- `src\u002Flogger.ts` – History log and stderr output.\n- `history.toml` – Append-only log (created at runtime; in `.gitignore`).\n\n\n## ⚠️ Disclaimer\n\n**IMPORTANT LEGAL DISCLAIMER:**\n\nThis software is provided “as-is” for educational and research purposes only. Trading on prediction markets involves substantial risk of loss.\n\n- **No warranty** – The software is provided without any warranties.  \n- **Use at your own risk** – You are solely responsible for any losses incurred.  \n- **Not financial advice** – This is not investment or trading advice.  \n- **Compliance** – Ensure compliance with local laws and regulations.  \n\nThe authors and contributors are not responsible for any financial losses, damages, or legal issues arising from the use of this software.\n\n\n## 🌟 Star history\n\nIf you find this project useful, please consider giving it a star ⭐\n\n## 📈 Roadmap\n\n- [ ] Optional WebSocket orderbook updates for lower latency  \n- [ ] Backtesting \u002F replay mode for strategy tuning  \n- [ ] Optional Telegram\u002FDiscord notifications  \n- [ ] More timeframe support (e.g. 1h)  \n- [ ] PnL export and simple reporting  \n",2,"2026-06-11 04:11:50","CREATED_QUERY"]