[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-75885":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":24,"readmeContent":25,"aiSummary":26,"trendingCount":15,"starSnapshotCount":15,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},75885,"polymarket-trading-bot","Multichain-Bot-Lab\u002Fpolymarket-trading-bot","Multichain-Bot-Lab","polymarket trading bot polymarket arbitrage trading bot polymarket arbitrage bot polymarket trading bot polymarket arbitrage trading bot polymarket arbitrage bot polymarket trading bot polymarket arbitrage trading bot polymarket arbitrage bot polymarket trading bot polymarket arbitrage trading bot polymarket arbitrage bot polymarket trading bot","https:\u002F\u002Fpolymarket.com\u002Fcrypto\u002F15M",null,"TypeScript",202,4500,108,0,75,54.5,false,"main",true,[22,23,5],"polymarket-arbitrage-bot","polymarket-arbitrage-trading-bot","2026-06-12 04:01:19","# Polymarket Arbitrage Trading Bot (TypeScript) \n\nA Polymarket Trading bot that trades on [Polymarket](https:\u002F\u002Fpolymarket.com) **binary crypto markets** (e.g. “Bitcoin up or down in the next 15 minutes”). It connects to Polymarket’s CLOB and real-time data, subscribes to a market by coin and period, and can run configurable strategies.\n\n\n## What kind of bot is this?\n\n**Not classic arbitrage.** The codebase supports two styles of logic:\n\n1. **Trend-following (`trade_1` in `decision.ts`)**  \n   Detects short-term “trend” from order-book price changes and would buy the **UP** or **DOWN** token when the market is trending that way, within a configurable price range. This is **directional trading**, not arbitrage.\n\n2. **Binary “arbitrage” (`trade_1` in `ws_clob.ts`)**  \n   When real-time price velocity exceeds a threshold, it computes prices such that UP + DOWN &lt; 1 − `min_arb_price_difference`, and would buy **both** UP and DOWN to lock in a margin. That’s **binary market arbitrage** (buying both sides when they’re cheap relative to $1).  \n\n**Current state:** Order placement for both strategies is **commented out**. The bot runs as a **framework**: it connects, subscribes to markets and RTDS, updates prices, and logs signals; it does not send live orders unless you uncomment and enable the trade calls.\n\n## Features\n\n- **Market selection**: Coin (`btc`, `eth`, `sol`, `xrp`) and period (15, 60, 240, 1440 minutes).\n- **Live data**: CLOB WebSocket (order book) and RTDS (e.g. BTCUSDT \u002F Chainlink) for price velocity.\n- **Strategies**: `trade_1` (time\u002Fprice exit), `trade_2` (entry\u002Fexit ranges + optional emergency swap).\n- **Config**: TOML config (`trade.toml`) for strategy, market, trading range, thresholds, simulation.\n- **Simulation**: Optional `simulation = true` to skip sending orders.\n\n## Change the market(`trade.toml`)\n\n   You can change crypto market \n   ** [market]\n      market_coin = \"btc\"  # btc \u002F eth \u002F sol \u002F xrp\n      market_period = \"5\" # 5 \u002F 15 \u002F 60 \u002F 240 \u002F 1440 **\n\n## Strategy logic (`decision.ts`)\n\n### trade_1 — Time \u002F price exit\n\n- **Goal**: Hold a position (UP or DOWN) and exit when either time or price threshold is reached.\n- **Exit**: If **remaining time ratio** (elapsed time \u002F market duration) &gt; `trade_1.exit_time_ratio` **or** **up-price ratio** (distance of UP bid from 0.5) &gt; `trade_1.exit_price_ratio`, the bot sells the currently held token:\n  - Holding **UP** → `sellUpToken()`\n  - Holding **DOWN** → `sellDownToken()`\n- **Config** (`[trade_1]` in `trade.toml`): `exit_time_ratio`, `exit_price_ratio`, plus `entry_price_range`, `swap_price_range`, `take_profit`, `stop_loss` for future entry\u002Frisk logic.\n\n### trade_2 — Entry\u002Fexit ranges + emergency swap\n\n- **Goal**: Enter when price and time are in range; exit when price is in an exit band; optionally flip to the opposite side in an “emergency” price band.\n- **Entry** (when not holding): If `remaining_time_ratio` &gt; `trade_2.entry_time_ratio` and **up-price ratio** is inside `trade_2.entry_price_ratio` `[min, max]`, buy the cheaper side (UP if `upBuyPrice` &gt; `downBuyPrice`, else DOWN).\n- **Exit**: If up-price ratio falls inside any of the `trade_2.exit_price_ratio_range` intervals:\n  - Holding **UP** → `sellUpToken()`; if sell succeeds and up-price ratio is in `trade_2.emergency_swap_price`, then `buyDownToken()`.\n  - Holding **DOWN** → `sellDownToken()`; if sell succeeds and up-price ratio is in `trade_2.emergency_swap_price`, then `buyUpToken()`.\n- **Config** (`[trade_2]`): `entry_price_ratio`, `entry_time_ratio`, `exit_price_ratio_range`, `emergency_swap_price` (optional).\n\n### trade_3 — Arbitrage Strategy ( Private )\n\n[![Watch the video](https:\u002F\u002Fimg.youtube.com\u002Fvi\u002FkOf64hqhbjE\u002Fmaxresdefault.jpg)](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=kOf64hqhbjE)\n\n\n\n## Requirements\n\n- **Node.js** ≥ 20.6.0\n- **Wallet**: Polymarket proxy wallet and signer (private key) for the CLOB.\n\n## Setup\n\n1. **Clone and install**\n\n   Ubuntu\n   ```bash\n   git clone https:\u002F\u002Fgithub.com\u002FMultichain-Bot-Lab\u002Fpolymarket-trading-bot\n   cd polymarket-trading-bot\n   \n   npm install\n   ```\n\n2. **Environment**\n\n   Create a `.env` in the project root (see `.gitignore`; do not commit secrets):\n\n   - `POLYMARKET_PRIVATE_KEY` – EOA private key that signs for the proxy wallet.\n   - `PROXY_WALLET_ADDRESS` – Proxy wallet address used with Polymarket CLOB.\n\n3. **Config**\n\n   Edit `trade.toml`:\n\n   - `strategy`: `\"trade_1\"` or `\"trade_2\"`.\n   - `trade_usd`, `max_retries`, `simulation`.\n   - `[market]`: `market_coin`, `market_period`.\n   - `[trade_1]`: `trading_range`, `price_change_threshold`, `min_arb_price_difference`, etc.\n\n## Scripts\n\n| Command   | Description                          |\n|----------|--------------------------------------|\n| `npm run dev`   | Run bot: `tsx src\u002Findex.ts`          |\n| `npm run log`   | Run and log stdout\u002Fstderr to `log.txt` |\n| `npm run check` | Run inspector: `tsx src\u002Finspect.ts`  |\n| `npm run build` | Compile: `tsc`                       |\n| `npm start`     | Run compiled: `node dist\u002Findex.js`   |\n\n## Project layout\n\n- `src\u002Findex.ts` – Entry: load config, create CLOB client, resolve market slug, connect WebSockets, instantiate `Trade`, main loop.\n- `src\u002Fconfig\u002F` – Env, TOML config, market\u002Fslug helpers.\n- `src\u002Fservices\u002F` – CLOB client, Gamma API, WebSockets (CLOB + RTDS).\n- `src\u002Ftrade\u002F` – `Trade` class: decision logic, prices\u002Ftrending, order placement (buy\u002Fsell UP\u002FDOWN).\n- `trade.toml` – Strategy and market configuration.\n\n## Contact\n\n[t.me\u002F@mshrieve](https:\u002F\u002Ft.me\u002F@mshrieve)\n","这是一个用于Polymarket平台上的二元加密货币市场交易的机器人，支持趋势跟随和二元市场套利两种策略。项目使用TypeScript编写，通过连接到Polymarket的CLOB（中央限价订单簿）并订阅实时数据来运行配置化的交易策略。其核心功能包括市场选择、实时数据分析以及基于时间与价格条件的交易决策逻辑。此外，还提供了模拟模式以测试策略而不实际下单。适用于希望在Polymarket上自动化执行交易策略的个人或机构投资者。",2,"2026-05-18 11:13:05","CREATED_QUERY"]