[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-79251":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":26,"readmeContent":27,"aiSummary":28,"trendingCount":15,"starSnapshotCount":15,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},79251,"trading-bot","Outcome-Signal-Forge\u002Ftrading-bot","Outcome-Signal-Forge","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","",null,"TypeScript",340,6391,1,0,95,10,false,"main",true,[22,23,24,25,5],"arbitrage-trading-bot","polymarket-arbitrage-bot","polymarket-arbitrage-trading-bot","polymarket-trading-bot","2026-06-12 02:03:50","# Polymarket Trading Bot · Polymarket Arbitrage Bot\n\n[![Node.js](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fnode-%3E%3D20.6.0-339933?logo=node.js&logoColor=white)](https:\u002F\u002Fnodejs.org\u002F)\n[![TypeScript](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FTypeScript-5.3-3178C6?logo=typescript&logoColor=white)](https:\u002F\u002Fwww.typescriptlang.org\u002F)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-ISC-blue)](LICENSE)\n\n**Open-source TypeScript bot for Polymarket crypto UP\u002FDOWN markets** — automate entries, exits, and emergency swaps on BTC, ETH, SOL, and XRP windows (5m–24h) using live CLOB prices and real on-chain balances.\n\n> Looking for a **Polymarket trading bot** or **Polymarket arbitrage bot** on GitHub? This repo is a production-oriented starter: configurable strategies in `trade.toml`, FAK orders via `@polymarket\u002Fclob-client-v2`, and no simulated PnL.\n\n---\n\n## Table of contents\n\n- [Features](#features)\n- [Supported markets](#supported-markets)\n- [How it works](#how-it-works)\n- [Strategies](#strategies)\n- [Requirements](#requirements)\n- [Quick start](#quick-start)\n- [Configuration](#configuration)\n- [Runtime output](#runtime-output)\n- [Scripts](#scripts)\n- [Project structure](#project-structure)\n- [Security](#security)\n- [Disclaimer](#disclaimer)\n- [Keywords & GitHub topics](#keywords--github-topics)\n\n---\n\n## Features\n\n| Capability | Description |\n| --- | --- |\n| **Market discovery** | Resolves the live Polymarket slug for your coin + window and tracks UP\u002FDOWN `clobTokenIds` until expiry |\n| **Live pricing** | Polls bid\u002Fask every second from `https:\u002F\u002Fclob.polymarket.com\u002Fprices` |\n| **Real balances** | Reads `CONDITIONAL` and `COLLATERAL` via `getBalanceAllowance` — no in-memory PnL guessing |\n| **Rule-based strategies** | `trade_1` (time\u002Fprice exits) or `trade_2` (entry, exit ranges, optional emergency swap) |\n| **Order execution** | FAK (Fill-and-Kill) orders with retries and post-trade balance polling |\n| **Operator visibility** | Periodic market + portfolio logs with trend and position legend |\n\n---\n\n## Supported markets\n\n| Coin | Periods (minutes) |\n| --- | --- |\n| **BTC** | `5`, `15`, `60`, `240`, `1440` |\n| **ETH**, **SOL**, **XRP** | `15`, `60`, `240`, `1440` |\n\n> **Note:** The 5-minute window is currently wired for **BTC** slugs only. Other coins use 15m and longer buckets.\n\n---\n\n## How it works\n\n```mermaid\nflowchart LR\n  A[trade.toml + .env] --> B[Bootstrap CLOB client]\n  B --> C[Resolve market slug]\n  C --> D[Poll UP\u002FDOWN prices]\n  D --> E[Strategy decision]\n  E --> F[FAK buy \u002F sell]\n  F --> G[Balance confirmation]\n  G --> D\n```\n\n1. Load and validate `trade.toml` (Zod) and environment variables.\n2. Connect signer + proxy (Gnosis Safe) wallet on Polygon.\n3. Lock onto the active UP\u002FDOWN market for the configured coin and period.\n4. On each tick (~1s), run `trade_1` or `trade_2` rules against live ratios.\n5. Post orders when rules fire; wait for settlement before the next action.\n\n---\n\n## Strategies\n\nBoth strategies share the same signals:\n\n- **`remaining_time_ratio`** — `(marketTime - remainingTime) \u002F marketTime` (0 at open → 1 at close)\n- **`up_price_ratio`** — `|upBuyPrice - 0.5| \u002F 0.5` (0 at $0.50 → 1 at $0.00 or $1.00)\n\n### `trade_1` — exit-only\n\nNo new entries. Liquidates an existing UP or DOWN position when either threshold is hit:\n\n- `remaining_time_ratio > trade_1.exit_time_ratio`, or\n- `up_price_ratio > trade_1.exit_price_ratio`\n\nUses `sellUpToken()` \u002F `sellDownToken()` on trigger.\n\n> `entry_price_range`, `swap_price_range`, `take_profit`, and `stop_loss` are required in config for validation but **not used yet** — reserved for future entry logic.\n\n### `trade_2` — entry, exit, and emergency swap\n\n| Phase | Behavior |\n| --- | --- |\n| **Entry** | Once per market (`hasBought`): when flat, `remaining_time_ratio > entry_time_ratio`, and `up_price_ratio` is inside `entry_price_ratio`, buy the side with the higher buy price |\n| **Exit** | If `up_price_ratio` matches any `exit_price_ratio_range` tuple, sell the held side |\n| **Emergency swap** | After a successful sell, if `up_price_ratio` is inside `emergency_swap_price`, immediately buy the opposite token |\n\n---\n\n## Requirements\n\n- **Node.js** `>= 20.6.0`\n- **Polymarket signer** private key (EOA that signs orders)\n- **Proxy \u002F funder wallet** (Gnosis Safe that holds USDC on Polygon, chain id `137`)\n- **USDC** on the proxy wallet for trading\n\n---\n\n## Quick start\n\n### 1. Clone and install\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FYOUR_USERNAME\u002Fpolymarket-trading-bot.git\ncd polymarket-trading-bot\nnpm install\n```\n\n### 2. Environment variables\n\nCopy `.env.example` to `.env` and fill in:\n\n```env\nPOLYMARKET_PRIVATE_KEY=your_signer_private_key\nPOLYMARKET_FUNDER_ADDRESS=your_proxy_wallet_address\n```\n\n`PROXY_WALLET_ADDRESS` is also accepted as an alias for `POLYMARKET_FUNDER_ADDRESS`.\n\n### 3. Strategy and market\n\nEdit `trade.toml` (see [Configuration](#configuration)). Defaults in the repo use `trade_2` on BTC 5m.\n\n### 4. Run\n\n```bash\nnpm run dev\n```\n\nFor production:\n\n```bash\nnpm run build\nnpm start\n```\n\nStart with a small `trade_usd` (e.g. `$1–$3`) until you trust the behavior.\n\n---\n\n## Configuration\n\n### `trade.toml` (main settings)\n\n| Key | Description |\n| --- | --- |\n| `strategy` | `\"trade_1\"` or `\"trade_2\"` |\n| `trade_usd` | USD size per entry order |\n| `max_retries` | Retries on failed order posts (default `3`) |\n| `[market].market_coin` | `\"btc\"` \\| `\"eth\"` \\| `\"sol\"` \\| `\"xrp\"` |\n| `[market].market_period` | `\"5\"` \\| `\"15\"` \\| `\"60\"` \\| `\"240\"` \\| `\"1440\"` (minutes) |\n\nStrategy blocks `[trade_1]` and `[trade_2]` hold thresholds described in [Strategies](#strategies). Example:\n\n```toml\nstrategy = \"trade_2\"\ntrade_usd = 3\nmax_retries = 3\n\n[market]\nmarket_coin = \"btc\"\nmarket_period = \"5\"\n\n[trade_2]\nentry_price_ratio = [0.4, 0.95]\nentry_time_ratio = 0.7\nexit_price_ratio_range = [[0.0, 0.01], [1.0, 1.0]]\nemergency_swap_price = [0.0, 0.5]\n```\n\n### Wallet signature type\n\nThe bot uses **`SIGNATURE_TYPE = 2`** (Gnosis Safe \u002F proxy). Orders are signed by your EOA but funds must sit in the **funder \u002F proxy** address you configure.\n\n---\n\n## Runtime output\n\n**Trend** (UP token, last 2 ticks): `UP 🟢` · `DOWN 🔴` · `FLAT ⚪`\n\n**Position** (on-chain): `UP 🟩` · `DOWN 🟥` · `NONE ⬛`\n\n**Engine:** `BUSY` (order in flight) · `IDLE`\n\nStartup logs signer, strategy, market, and `trade_usd`. Every ~3 seconds:\n\n- **Market line** — `tMinus`, `up`, `down`, spreads, `upRatio`, `timeRatio`, `score`, `trend`, `position`, `engine`\n- **Portfolio line** — `cash`, `shares`, `position`, `shareValue`, `total`, `engine`, `trend`\n\n---\n\n## Scripts\n\n| Command | Description |\n| --- | --- |\n| `npm run dev` | Run with `tsx` (`src\u002Findex.ts`) |\n| `npm run build` | Compile to `dist\u002F` |\n| `npm start` | Run compiled `dist\u002Findex.js` |\n\n---\n\n## Project structure\n\n```\nsrc\u002F\n├── index.ts              # Startup, CLOB bootstrap, market loop\n├── types.ts              # Coin, Minutes, MarketConfig, Market\n├── config\u002F               # env, TOML (Zod), slug, market helpers\n├── services\u002F             # clob.ts (prices, signer), gamma.ts (slug lookup)\n├── trade\u002F                # Trade class: prices, decision, buy\u002Fsell\n├── constant\u002F             # Global tx-in-flight state\n└── utils\u002F                # time, retry, logging\ntrade.toml                # Strategy + market config (validated at boot)\n```\n\n---\n\n## Security\n\n- Never commit `.env` or private keys.\n- Use a dedicated signer and a proxy wallet funded only with risk capital.\n- Confirm `POLYMARKET_FUNDER_ADDRESS` \u002F `PROXY_WALLET_ADDRESS` holds USDC before scaling `trade_usd`.\n- Review strategy thresholds; automated trading can lose funds quickly.\n\n---\n\n## Disclaimer\n\nThis software is for **education and research**. Prediction markets and automated trading carry **financial and regulatory risk**. You are responsible for compliance, taxes, and capital loss. No warranty is provided; use at your own risk.\n\n---\n\n## Keywords & GitHub topics\n\nThis repository is commonly searched as:\n\n**Polymarket trading bot** · **Polymarket arbitrage bot** · Polymarket CLOB bot · Polymarket UP\u002FDOWN bot · BTC 5m \u002F 15m prediction market bot · TypeScript Polymarket automation\n\nSuggested [GitHub topics](https:\u002F\u002Fdocs.github.com\u002Fen\u002Frepositories\u002Fmanaging-your-repositorys-settings-and-features\u002Fcustomizing-your-repository\u002Fclassifying-your-repository-with-topics) for discoverability:\n\n`polymarket` `polymarket-trading-bot` `polymarket-arbitrage-bot` `prediction-markets` `clob` `typescript` `trading-bot` `crypto` `automation`\n\nBuilt with [`@polymarket\u002Fclob-client-v2`](https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002F@polymarket\u002Fclob-client-v2).\n","Outcome-Signal-Forge\u002Ftrading-bot 是一个用于 Polymarket 加密货币市场的自动化交易机器人。它使用 TypeScript 编写，支持 BTC、ETH、SOL 和 XRP 的 UP\u002FDOWN 市场（5 分钟至 24 小时窗口），通过实时 CLOB 价格和真实的链上余额来实现自动化的进入、退出及紧急交换操作。该机器人具备市场发现、实时定价、真实余额查询等功能，并提供了基于规则的交易策略，如时间\u002F价格退出或指定范围内的进出操作。项目适合希望在 Polymarket 平台上进行量化交易或套利活动的开发者和投资者使用。",2,"2026-05-29 04:08:02","CREATED_QUERY"]