[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-1150":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":16,"stars90d":16,"forks30d":16,"starsTrendScore":16,"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":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},1150,"Polymarket-Copytrading-Bot","PoDev-rahulrajasekhar\u002FPolymarket-Copytrading-Bot","PoDev-rahulrajasekhar","Polymarket copy trading bot Polymarket copy trading bot Polymarket copy trading bot Polymarket copy trading bot Polymarket copy trading bot Polymarket copy trading bot  Polymarket copy trading bot Polymarket copy trading bot  Polymarket copy trading bot Polymarket copy trading bot  Polymarket copy trading bot Polymarket copy trading bot copytrading","",null,"TypeScript",339,196,183,1,0,43.88,false,"main",true,[22,23],"polymarket-copy-trading-bot","polymarket-copytraidng-bot","2026-06-12 04:00:08","# Polymarket Copy Trading Bot\n\nA copy trading bot for Polymarket that mirrors trades from target wallets in real time. Built with TypeScript: WebSocket or API polling for trade detection, Polymarket CLOB for execution, with risk controls and optional auto-redemption.\n\n---\n\n## Overview\n\n- **Real-time trade mirroring** – Monitors target wallets via WebSocket or API and copies their trades.\n- **Configurable sizing** – Per-wallet order size in `src\u002Fconfig\u002Fconfig.json` (USDC or token amount).\n- **Risk management** – Buy threshold, stop-loss (SELL_PRICE), take-profit (PROFIT_SELL_THRESHOLD).\n- **Auto-redemption** – Optional scheduled redemption of resolved positions.\n- **Telegram** – Optional notifications when target wallets trade.\n\n---\n\n![Copytrading demo ](public\u002Fcopytrading.png)\n\n---\n\nhttps:\u002F\u002Fgithub.com\u002Fuser-attachments\u002Fassets\u002F81999b03-4bb6-4a44-9d4d-9a1ae964f441\n\n---\n\n## Prerequisites\n\nBefore you start, ensure you have:\n\n| Requirement | Details |\n|-------------|---------|\n| **Node.js** | Version 18 or higher. Check with `node -v`. |\n| **npm** | Comes with Node.js. Check with `npm -v`. |\n| **Polygon wallet** | A wallet (e.g. MetaMask) on Polygon with some USDC for trading. |\n| **Polymarket account** | You need your **proxy (smart) wallet** address from Polymarket (see [Finding your proxy wallet](#finding-your-proxy-wallet)). |\n\n---\n\n## Quick start: run the bot in 5 steps\n\n1. **Clone and install**\n   ```bash\n   cd Polymarket-Copytrading-Bot\n   npm install\n   ```\n\n2. **Create your `.env` file**\n   ```bash\n   cp .env.example .env\n   ```\n\n3. **Edit `.env` – set these required values**\n   - `PRIVATE_KEY` – Your wallet private key (e.g. from MetaMask: Account → three dots → Account details → Export Private Key). Must start with `0x`.\n   - `PROXY_WALLET_ADDRESS` – Your Polymarket proxy wallet address (see [Finding your proxy wallet](#finding-your-proxy-wallet)).\n   - `DRY_RUN=false` – So the bot places real orders (set `true` to only log, no orders).\n\n4. **Edit `src\u002Fconfig\u002Fconfig.json` – add target wallets**\n   - Add the Polymarket wallet addresses you want to copy. The number is the order size (tokens or USDC depending on `ORDER_SIZE_IN_TOKENS`).\n   ```json\n   {\n       \"0xAddressOfTrader1\": 1,\n       \"0xAddressOfTrader2\": 5\n   }\n   ```\n\n5. **Run the bot**\n   ```bash\n   npm start\n   ```\n   Or use API polling instead: `npm run copytrade`.\n\nOn first run, the bot will create `src\u002Fdata\u002Fcredential.json` (Polymarket API credentials). Keep that file and `.env` secret and never commit them.\n\n---\n\n## How to run the bot\n\n### Two ways to run copy trading\n\n| Mode | Command | When to use |\n|------|---------|-------------|\n| **WebSocket** | `npm start` | Real-time; uses Polymarket’s live feed. Best for low latency. |\n| **API polling** | `npm run copytrade` | Fetches trades on an interval (default 30s). Simpler, no WebSocket. |\n\nBoth use the same `.env` and `src\u002Fconfig\u002Fconfig.json`. Use one at a time.\n\n### Step-by-step: first run\n\n1. **Install dependencies** (once)\n   ```bash\n   npm install\n   ```\n\n2. **Copy and fill `.env`**\n   ```bash\n   cp .env.example .env\n   ```\n   Open `.env` and set at least:\n   - `PRIVATE_KEY=0x...` (your EOA private key)\n   - `PROXY_WALLET_ADDRESS=0x...` (your Polymarket proxy)\n   - `DRY_RUN=false` (to allow real buy\u002Fsell)\n\n3. **Add target wallets** in `src\u002Fconfig\u002Fconfig.json`  \n   Format: `\"0xWalletAddress\": number`. The number is the size per copy-trade (see [Target wallets](#target-wallets-configjson)).\n\n4. **Optional: test without placing orders**  \n   Set `DRY_RUN=true` in `.env`, then run the bot. It will log what it would do but not send orders.\n\n5. **Start the bot**\n   ```bash\n   npm start\n   ```\n   or\n   ```bash\n   npm run copytrade\n   ```\n\n6. **First-run behaviour**\n   - If `src\u002Fdata\u002Fcredential.json` is missing, the bot creates it (Polymarket API key).\n   - It may prompt or run allowance\u002Fbalance checks. Ensure your proxy wallet has USDC and approvals on Polygon.\n\n### Other useful commands\n\n- **Check wallet and balance** (no trading):\n  ```bash\n  npm run balance\n  ```\n- **Monitor one wallet** (log trades only, no copying):\n  ```bash\n  npm run monitor\n  ```\n- **Auto-redeem** resolved positions:\n  ```bash\n  npm run auto-redeem\n  ```\n- **Clear copy-trade history** (e.g. to reprocess old trades):\n  ```bash\n  npm run clear-history\n  ```\n\n---\n\n## How to set environment variables (.env)\n\nThe bot reads configuration from a `.env` file in the project root. Never commit `.env` or share it.\n\n### Creating `.env`\n\n```bash\ncp .env.example .env\n```\n\nThen open `.env` in a text editor and replace the placeholder values.\n\n### Required variables (must set)\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `PRIVATE_KEY` | `0xabc123...` | Your wallet (EOA) private key. Used to sign every order. Export from MetaMask (Account → ⋮ → Account details → Export Private Key). **Keep secret.** |\n| `PROXY_WALLET_ADDRESS` | `0x875058B4...` | Your Polymarket proxy (smart) wallet address. This is where the exchange holds your positions. Required for the CLOB client. |\n\n#### Finding your proxy wallet\n\n- **Option A:** In the Polymarket app or website, go to your profile \u002F account or deposit\u002Fwithdraw. The proxy address is often shown there (it’s the “smart wallet” or “proxy” address).\n- **Option B:** Set only `PRIVATE_KEY` in `.env`, run `npm run balance`. The script can derive and print the proxy address for your EOA; then copy it into `PROXY_WALLET_ADDRESS` in `.env`.\n\n### Enabling real buy\u002Fsell orders\n\n| Variable | Value | Effect |\n|----------|--------|--------|\n| `DRY_RUN` | `false` | Bot **places real orders** (buy\u002Fsell). |\n| `DRY_RUN` | `true` or unset | Bot **only logs**; no orders are sent. Safe for testing. |\n\nSet `DRY_RUN=false` in `.env` when you want the bot to actually trade.\n\n### Copy-trading switch\n\n| Variable | Value | Effect |\n|----------|--------|--------|\n| `ENABLE_COPY_TRADING` | `true` or unset | Copy trading is **on** (bot will copy target wallets). |\n| `ENABLE_COPY_TRADING` | `false` | Copy trading is **off** (e.g. only monitor or redeem). |\n\n### Chain and RPC\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `CHAIN_ID` | `137` | `137` = Polygon mainnet (production). `80002` = Amoy testnet. |\n| `RPC_URL` | `https:\u002F\u002Fpolygon-mainnet.g.alchemy.com\u002Fv2\u002FYOUR_KEY` | Full RPC URL. Use `https` (not `wss`). If set, `RPC_TOKEN` is ignored. |\n| `RPC_TOKEN` | `your_alchemy_key` | If `RPC_URL` is not set, the bot builds the RPC URL using this (e.g. Alchemy API key). |\n\nYou can leave RPC unset; the bot has default endpoints (rate limits may apply).\n\n### Trading behaviour\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `ORDER_TYPE` | `FAK` | `FAK` (fill-and-kill) or `FOK` (fill-or-kill). |\n| `TICK_SIZE` | `0.01` | Price step: `0.1`, `0.01`, `0.001`, or `0.0001`. |\n| `ORDER_SIZE_IN_TOKENS` | `true` | If `true`, numbers in `config.json` = **token count**. If `false`, they’re treated as **USDC** (or balance-based). |\n| `ORDER_SIZE_IN_USDC` | `true` | If `true`, `config.json` numbers = fixed **USDC** amount (no price fetch). |\n\n### Risk and thresholds\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `BUY_THRESHOLD` | `0.45` | Only copy a **BUY** when the token’s price is **above** this (e.g. 0.45 = 45¢). |\n| `SELL_PRICE` | `0.35` | **Stop-loss:** sell when token price goes **below** this. |\n| `PROFIT_SELL_THRESHOLD` | `0.99` | **Take-profit:** sell when token price reaches this (e.g. 0.99). |\n| `PENDING_BUY_TIME_THRESHOLD_SECONDS` | `160` | For “pending” buys: only buy after this many seconds past the 5m boundary. |\n\n### Slippage and retries\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `BUY_SLIPPAGE_BPS` | `200` | Buy slippage in basis points (200 = 2%). |\n| `SELL_SLIPPAGE_BPS` | `100` | Sell slippage in basis points (100 = 1%). |\n| `ORDER_RETRY_ATTEMPTS` | `5` | How many times to retry placing an order. |\n| `ORDER_RETRY_DELAY_MS` | `200` | Delay between retries (ms). |\n\n### API polling (for `npm run copytrade`)\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `POLL_INTERVAL_MS` | `30000` | How often to fetch new trades (ms). 30000 = 30 seconds. |\n| `WALLET_FETCH_DELAY_MS` | `800` | Delay between each target wallet request (rate limiting). |\n\n### Optional: Telegram\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `TELEGRAM_BOT_TOKEN` | `123456:ABC...` | Bot token from [@BotFather](https:\u002F\u002Ft.me\u002FBotFather). Leave empty to disable. |\n| `TELEGRAM_CHAT_ID` | `7744299798` | Chat ID to receive alerts. Leave empty to disable. |\n\nWhen both are set, the bot can send a notification when a target wallet trades.\n\n### Optional: auto-redeem and CLOB\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `REDEEM_DURATION` | `120` | Run auto-redeem every N minutes. Empty or 0 = disabled. |\n| `CLOB_API_URL` | `https:\u002F\u002Fclob.polymarket.com` | CLOB API base URL. Default is production. |\n\n### Debug\n\n| Variable | Example | Description |\n|----------|---------|-------------|\n| `DEBUG` | `true` | Enable extra debug logging. |\n\n### Minimal `.env` example (real orders)\n\n```env\nPRIVATE_KEY=0xYourPrivateKeyHere\nPROXY_WALLET_ADDRESS=0xYourPolymarketProxyAddress\nDRY_RUN=false\nENABLE_COPY_TRADING=true\n```\n\nEverything else can be omitted to use defaults, or copy from `.env.example` and adjust.\n\n---\n\n## Target wallets (config.json)\n\n**Target wallets are not in `.env`.** They are configured in **`src\u002Fconfig\u002Fconfig.json`**.\n\n### Format\n\n```json\n{\n    \"0xWalletAddressToCopy1\": 1,\n    \"0xWalletAddressToCopy2\": 5\n}\n```\n\n- **Key** – Polymarket wallet address (proxy or EOA) of the trader you want to copy.\n- **Value** – Number: order size per copy-trade.\n  - If `ORDER_SIZE_IN_TOKENS=true` (default): size = **number of tokens** to buy\u002Fsell.\n  - If `ORDER_SIZE_IN_TOKENS=false`: size = **USDC** amount (or balance-based depending on config).\n\n### Where to get target addresses\n\nUse the Polymarket profile or activity URL of the trader; the address shown there (often the proxy) is what you put in `config.json`. The bot matches trades by this address.\n\n### Example\n\nCopy two traders: one with 1 token per trade, one with 5 tokens per trade:\n\n```json\n{\n    \"0xaac8e98e05cf679616dec6c47755748b4cb0bff1\": 1,\n    \"0x4c353dd347c2e7d8bcdc5cd6ee569de7baf23e2f\": 5\n}\n```\n\nSave the file; the bot reads it on startup. No need to restart for every edit if you only change config occasionally (restart after editing for changes to apply).\n\n---\n\n## Environment variable reference\n\nQuick reference for all supported variables. See [How to set environment variables](#how-to-set-environment-variables-env) for details.\n\n| Variable | Required | Default | Description |\n|----------|----------|--------|-------------|\n| `PRIVATE_KEY` | Yes | — | EOA private key. |\n| `PROXY_WALLET_ADDRESS` | Yes | — | Polymarket proxy wallet. |\n| `DRY_RUN` | No | `true` | `false` = place orders; `true` = log only. |\n| `ENABLE_COPY_TRADING` | No | `true` | `false` = disable copy trading. |\n| `CHAIN_ID` | No | `137` | `137` = Polygon mainnet, `80002` = Amoy. |\n| `RPC_URL` | No | — | Full RPC URL (https). |\n| `RPC_TOKEN` | No | — | e.g. Alchemy key to build RPC URL. |\n| `CLOB_API_URL` | No | `https:\u002F\u002Fclob.polymarket.com` | CLOB API base. |\n| `ORDER_TYPE` | No | `FAK` | `FAK` or `FOK`. |\n| `TICK_SIZE` | No | `0.01` | `0.1`, `0.01`, `0.001`, `0.0001`. |\n| `NEG_RISK` | No | `false` | Negative-risk exchange. |\n| `ORDER_SIZE_IN_TOKENS` | No | `true` | config.json = token count. |\n| `ORDER_SIZE_IN_USDC` | No | `false` | config.json = fixed USDC. |\n| `BUY_THRESHOLD` | No | `0.5` | Min price to copy a BUY. |\n| `SELL_PRICE` | No | `0.45` | Sell when price below this. |\n| `PROFIT_SELL_THRESHOLD` | No | `0.98` | Sell when price ≥ this. |\n| `PENDING_BUY_TIME_THRESHOLD_SECONDS` | No | `210` | Pending buy delay (seconds). |\n| `BUY_SLIPPAGE_BPS` | No | `200` | Buy slippage (bps). |\n| `SELL_SLIPPAGE_BPS` | No | `100` | Sell slippage (bps). |\n| `ORDER_RETRY_ATTEMPTS` | No | `5` | Order retries. |\n| `ORDER_RETRY_DELAY_MS` | No | `200` | Retry delay (ms). |\n| `POLL_INTERVAL_MS` | No | `30000` | API poll interval (ms). |\n| `WALLET_FETCH_DELAY_MS` | No | `800` | Delay between wallet fetches (ms). |\n| `USER_REAL_TIME_DATA_URL` | No | `wss:\u002F\u002Fws-live-data.polymarket.com` | WebSocket URL. |\n| `TELEGRAM_BOT_TOKEN` | No | — | Telegram bot token. |\n| `TELEGRAM_CHAT_ID` | No | — | Telegram chat ID. |\n| `REDEEM_DURATION` | No | — | Auto-redeem interval (minutes). |\n| `DEBUG` | No | `false` | Extra logging. |\n\n---\n\n## Scripts reference\n\n| Command | Description |\n|---------|-------------|\n| `npm start` | WebSocket copy-trade bot (real-time). |\n| `npm run copytrade` | API polling copy-trade bot. |\n| `npm run monitor` | Monitor one wallet (no copying). |\n| `npm run balance` | Show EOA, proxy, and USDC balances. |\n| `npm run auto-redeem` | Auto-redeem resolved positions. |\n| `npm run clear-history` | Clear processed-trades \u002F bought\u002Fsold history. |\n| `npm run redeem` | Manual redeem (CONDITION_ID \u002F INDEX_SETS in script or env). |\n| `npm run manual-add-holdings` | Add holdings to token-holding.json. |\n| `npm run sync-holdings` | Sync holdings from wallet. |\n\n---\n\n## Project structure\n\n```\npolymarket-copytrading-bot-ts\u002F\n├── .env                    # Your secrets (create from .env.example)\n├── .env.example            # Template for .env\n├── package.json\n├── src\u002F\n│   ├── index.ts            # WebSocket copy-trade entry (npm start)\n│   ├── copytrade.ts    # API copy-trade entry (npm run copytrade)\n│   ├── auto-redeem-copytrade.ts\n│   ├── config\u002F\n│   │   ├── env.ts          # Reads .env\n│   │   └── config.json     # Target wallets + sizes\n│   ├── copy-trade\u002F\n│   │   ├── core.ts         # processTrade() – shared copy logic\n│   │   └── risk-manager.ts\n│   ├── data\u002F\n│   │   ├── credential.json # API credentials (auto-created)\n│   │   └── token-holding.json\n│   ├── providers\u002F\n│   │   ├── clobclient.ts   # CLOB (uses PRIVATE_KEY + PROXY_WALLET_ADDRESS)\n│   │   └── wssProvider.ts\n│   ├── security\u002F\n│   │   ├── createCredential.ts\n│   │   └── allowance.ts\n│   ├── other\u002F\n│   │   ├── redeem.ts\n│   │   ├── monitor-wallet.ts\n│   │   └── wallet-balance.ts\n│   └── utils\u002F\n│       ├── proxyWallet.ts\n│       ├── balance.ts\n│       └── redeem.ts\n└── README.md\n```\n\n---\n","这是一个用于Polymarket平台的跟单交易机器人，能够实时镜像目标钱包的交易。项目使用TypeScript编写，通过WebSocket或API轮询检测交易，并利用Polymarket的CLOB（中央限价订单簿）执行交易，同时具备风险控制和可选的自动赎回功能。用户可以配置每笔订单的大小、设置买入阈值、止损和止盈点，以及启用Telegram通知等功能。此工具适合希望跟随专业交易者操作的投资者，特别是那些活跃于Polymarket并希望通过自动化手段提高交易效率的人士。",2,"2026-05-06 17:30:41","CREATED_QUERY"]