[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-78387":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":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":16,"stars30d":17,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":18,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":10,"pushedAt":10,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":16,"starSnapshotCount":16,"syncStatus":33,"lastSyncTime":34,"discoverSource":35},78387,"trading-bot","judithsulfan\u002Ftrading-bot","judithsulfan","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",287,3182,82,1,0,71,10,false,"main",true,[23,24,25,26,27,28,29,5],"arbitrage-bot","arbitrage-trading-bot","betting-strategy","bot","polymarket-arbitrage-trading-bot","polymarket-bot","polymarket-trading-bot","2026-06-12 02:03:47","# 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","该项目是一个针对Polymarket加密货币UP\u002FDOWN市场的开源TypeScript交易机器人，用于自动化交易和套利操作。核心功能包括市场发现、实时定价、真实余额管理、基于规则的策略执行以及FAK订单处理。它支持BTC、ETH、SOL和XRP在不同时间窗口（5分钟至24小时）内的交易。适用于希望自动执行交易策略并进行套利操作的加密货币投资者或开发者。通过配置`trade.toml`文件，用户可以灵活设定交易参数，并利用真实的链上余额而非模拟盈亏来提高交易准确性。",2,"2026-05-24 02:30:08","CREATED_QUERY"]