[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-78416":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":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":18,"fork":18,"defaultBranch":19,"hasWiki":20,"hasPages":18,"topics":21,"createdAt":10,"pushedAt":10,"updatedAt":28,"readmeContent":29,"aiSummary":30,"trendingCount":15,"starSnapshotCount":15,"syncStatus":31,"lastSyncTime":32,"discoverSource":33},78416,"polymarket-trading-bot","mila89\u002Fpolymarket-trading-bot","mila89","Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot Polymarket Trading Bot bot","",null,"TypeScript",296,4384,32,0,142,57,false,"main",true,[22,23,24,25,26,5,27],"arbitrage-bot","arbitrage-trading-bot","bot","polymarket-arbitrage-trading-bot","polymarket-btc-arbitrage-bot","trading-bot","2026-06-12 04:01:23","# Polymarket Arbitrage Trading Bot (TypeScript)\n\nOpen-source **Polymarket trading bot** for automated UP\u002FDOWN crypto prediction markets—a TypeScript **Polymarket trading bot** built on `@polymarket\u002Fclob-client-v2`. This **Polymarket trading bot** resolves your coin and window (BTC\u002FETH\u002FSOL\u002FXRP, 5m–24h), streams CLOB bid\u002Fask every second, and runs `trade_1` or `trade_2` from `trade.toml`. Each **Polymarket trading bot** cycle applies live strategy rules; deploy this production **Polymarket trading bot** to post FAK orders with on-chain proxy-wallet balances (no simulated PnL). Clone, configure, and run this **Polymarket trading bot** with `npm run dev`. Fork or extend this **Polymarket trading bot** when you need a configurable **Polymarket trading bot** for hands-off Polymarket automation.\n\n## What this bot does\n\n- Resolves the live market slug for the configured coin + period and locks onto\n  its UP \u002F DOWN `clobTokenIds` until the window expires\n- Polls bid\u002Fask for both tokens every second from\n  `https:\u002F\u002Fclob.polymarket.com\u002Fprices`\n- Maintains real on-chain state by reading `CONDITIONAL` and `COLLATERAL`\n  balances through `getBalanceAllowance` (no in-memory PnL guessing)\n- Runs strategy logic (`trade_1` or `trade_2`) on every tick\n- Posts FAK (Fill-and-Kill) market orders with automatic retry on transient\n  failure and post-order balance polling for settlement confirmation\n- Prints periodic market snapshot + portfolio status with trend \u002F position\n  legend for operator visibility\n\n## Strategy model\n\nStrategy is selected via `strategy` in `trade.toml` and currently implements\ntwo rule sets. Both reference the same derived signals:\n\n- `remaining_time_ratio = (marketTime - remainingTime) \u002F marketTime`\n  (0 at window start → 1 at window end)\n- `up_price_ratio = |upBuyPrice - 0.5| \u002F 0.5`\n  (0 when UP is at $0.50 → 1 when UP is at $0.00 or $1.00)\n\n### `trade_1` (time \u002F price driven exit-only model)\n\nExit-focused logic only — the bot does not place new entries in `trade_1`\nand only liquidates any existing position when either trigger fires:\n\n- `remaining_time_ratio > trade_1.exit_time_ratio`, or\n- `up_price_ratio    > trade_1.exit_price_ratio`\n\nOn trigger, the currently held side (UP or DOWN) is sold via `sellUpToken()` \u002F\n`sellDownToken()`.\n\n> Note: the schema (`src\u002Fconfig\u002Ftoml.ts`) also requires `entry_price_range`,\n> `swap_price_range`, `take_profit`, and `stop_loss` for `trade_1`. These keys\n> are reserved for future entry logic and are not consumed by the current\n> decision engine — leave them present so config validation passes.\n\n### `trade_2` (entry \u002F exit ranges with emergency swap)\n\n- **Entry** (only fires once per market via `hasBought`): when no position is\n  held, `remaining_time_ratio > trade_2.entry_time_ratio`, and `up_price_ratio`\n  is inside `trade_2.entry_price_ratio = [min, max]`. The bot buys whichever\n  side (UP or DOWN) currently has the higher buy price.\n- **Exit**: if `up_price_ratio` falls into ANY of the\n  `trade_2.exit_price_ratio_range` tuples, the held side is sold.\n- **Emergency swap** (optional): if the sell succeeds AND `up_price_ratio` is\n  inside `trade_2.emergency_swap_price = [min, max]`, the bot immediately buys\n  the opposite token to flip exposure.\n\n## Requirements\n\n- Node.js `>= 20.6.0`\n- Polymarket signer private key (EOA that signs orders)\n- Polymarket proxy wallet address (Gnosis Safe that actually holds funds)\n- USDC funded on the proxy wallet on Polygon (chain id 137)\n\n## Quick start\n\n1. Install dependencies:\n\n```bash\nnpm install\n```\n\n2. Create `.env` in the project root (see `.env.example`):\n\n```env\nPOLYMARKET_PRIVATE_KEY=your_private_key\nPROXY_WALLET_ADDRESS=your_proxy_wallet_address\n```\n\n3. Configure runtime behavior in `trade.toml`:\n\n- `strategy`: `\"trade_1\"` or `\"trade_2\"`\n- `trade_usd`: order size in USD per entry\n- `max_retries`: retry count for failed order posts (default `3`)\n- `[market].market_coin`: `\"btc\" | \"eth\" | \"sol\" | \"xrp\"`\n- `[market].market_period`: `\"5\" | \"15\" | \"60\" | \"240\" | \"1440\"` (minutes)\n  - The `5` (5-minute) bucket is currently only wired up for BTC slugs;\n    ETH \u002F SOL \u002F XRP support `15 \u002F 60 \u002F 240 \u002F 1440` only.\n\n4. Start the bot:\n\n```bash\nnpm run dev\n```\n\n## Runtime output legend\n\n- Trend (price drift on UP token over the last 2 ticks):\n  - `UP 🟢`\n  - `DOWN 🔴`\n  - `FLAT ⚪`\n- Position (current on-chain holding):\n  - `UP 🟩`\n  - `DOWN 🟥`\n  - `NONE ⬛`\n- Engine: `BUSY` while an order is in flight, `IDLE` otherwise.\n\nThe startup header prints:\n\n- Signer public key\n- Active strategy\n- Selected market (coin + window in minutes)\n- Configured `trade_usd`\n\nEvery ~3 seconds the bot logs a market line\n(`tMinus`, `up`, `down`, spreads, `upRatio`, `timeRatio`, `score`, `trend`,\n`position`, `engine`) and a portfolio line\n(`cash`, `shares`, `position`, `shareValue`, `total`, `engine`, `trend`).\n\n## Scripts\n\n| Command | Description |\n| --- | --- |\n| `npm run dev` | Run bot in dev mode (`tsx src\u002Findex.ts`) |\n| `npm run build` | Compile TypeScript to `dist\u002F` |\n| `npm start` | Run compiled output (`node dist\u002Findex.js`) |\n\n## Project structure\n\n- `src\u002Findex.ts` — startup flow, CLOB client bootstrap, per-market loop\n- `src\u002Ftypes.ts` — shared types (`Coin`, `Minutes`, `MarketConfig`, `Market`)\n- `src\u002Fconfig\u002F` — environment + TOML loading & validation\n  - `env.ts` — required `.env` retrieval\n  - `toml.ts` — Zod-validated `trade.toml` loader (exposes `globalThis.__CONFIG__`)\n  - `slug.ts` — coin\u002Fminute → Polymarket market slug + window timestamps\n  - `market.ts` — coin\u002Fminute validation helpers\n- `src\u002Fservices\u002F` — external API integrations\n  - `clob.ts` — CLOB signer\u002Ffunder setup and `\u002Fprices` polling\n  - `gamma.ts` — Gamma API market lookup by slug\n- `src\u002Ftrade\u002F` — strategy + order execution\n  - `index.ts` — `Trade` class definition + prototype mixins\n  - `prices.ts` — price tick ingestion, trend, portfolio logging\n  - `decision.ts` — `trade_1` \u002F `trade_2` decision logic\n  - `trade.ts` — buy \u002F sell flows, balance polling, retry wiring\n- `src\u002Fconstant\u002Findex.ts` — global tx-process state (`GLOBAL_TX_PROCESS`)\n- `src\u002Futils\u002F` — `time` helpers (`getCurrentTime`, `sleep`) and `retry.ts`\n- `trade.toml` — strategy + market configuration (Zod-validated at startup)\n\n## Keywords\n\nCommon search terms this repo targets:\n\n\u003Cp>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20trading%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket trading bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20btc%20arbitrage%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket btc arbitrage bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20btc%205min%20arbitrage%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket btc 5min arbitrage bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20btc%2015min%20arbitrage%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket btc 15min arbitrage bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20arbitrage%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket arbitrage bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20btc%20trading%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket btc trading bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20clob%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket clob bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20clob%20trading%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket clob trading bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20orderbook%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket orderbook bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F%40polymarket%2Fclob--client--v2-2E5CFF?style=for-the-badge\" alt=\"@polymarket\u002Fclob-client-v2\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20api%20key-2E5CFF?style=for-the-badge\" alt=\"polymarket api key\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20market%20making%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket market making bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20up%20down%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket up down bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%205%20minute%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket 5 minute bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%205m%20btc-2E5CFF?style=for-the-badge\" alt=\"polymarket 5m btc\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%2015%20minute%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket 15 minute bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%2015m%20btc-2E5CFF?style=for-the-badge\" alt=\"polymarket 15m btc\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20typescript%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket typescript bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpolymarket%20nodejs%20bot-2E5CFF?style=for-the-badge\" alt=\"polymarket nodejs bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fprediction%20market%20trading%20bot-2E5CFF?style=for-the-badge\" alt=\"prediction market trading bot\"\u002F>\n  \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fcrypto%20prediction%20market%20bot-2E5CFF?style=for-the-badge\" alt=\"crypto prediction market bot\"\u002F>\n\u003C\u002Fp>\n\n## Security and operations\n\n- Never commit `.env` or wallet keys.\n- Use a dedicated signer wallet and risk-limited proxy balance.\n- Test with a low `trade_usd` (e.g. `$1–$3`) before scaling up.\n- The bot uses `SIGNATURE_TYPE = 2` (Gnosis Safe \u002F proxy) — confirm your\n  `PROXY_WALLET_ADDRESS` actually holds funds, otherwise orders will fail.\n","该项目是一个基于TypeScript的Polymarket自动交易机器人，专为加密货币预测市场的UP\u002FDOWN交易设计。它利用`@polymarket\u002Fclob-client-v2`库实现实时市场数据流处理、策略执行及FAK订单提交等功能。该机器人支持自定义交易策略（如`trade_1`和`trade_2`），能够根据设定的时间窗口与价格比例自动进行买卖操作，并确保所有交易均在链上完成以维持真实的资金状态。适用于希望实现自动化Polymarket交易而无需人工干预的场景。用户可以通过简单配置后运行项目，或基于现有代码进一步开发定制化功能。",2,"2026-05-24 02:30:14","CREATED_QUERY"]