[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-75800":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":42,"readmeContent":43,"aiSummary":44,"trendingCount":15,"starSnapshotCount":15,"syncStatus":45,"lastSyncTime":46,"discoverSource":47},75800,"Polymarket-trading-bot","POLYMARKET-SPORTS\u002FPolymarket-trading-bot","POLYMARKET-SPORTS","polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket  bot, ","https:\u002F\u002Fgithub.com\u002FPOLYMARKET-SPORTS\u002FPolymarket-trading-bot",null,"JavaScript",174,410,116,0,67,7.84,false,"main",true,[22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41],"arbitrage-bot","automated-trading","btc-updown","clob","copy-trading","crypto-trading","defi","market-data","mirror-trading","nodejs","open-source","polygon","polymarket","polymarket-bot","polymarket-copy-trading","prediction-markets","trading-bot","typescript","wallet-tracking","web3","2026-06-12 02:03:36","\u003Cdiv align=\"center\">\n\n# Polymarket BTC Up\u002FDown Trading Bot\n\n### BTC 5m Up\u002FDown · CLOB arbitrage · copy-trading · Polygon\n\nA production-oriented **Node.js** trading bot for **Polymarket** short-duration **Up\u002FDown** markets on **Polygon**, with both **arbitrage** and **copy-trading** workflows.\n\n\u003Cp>\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002FPOLYMARKET-SPORTS\u002FPolymarket-trading-bot\">\u003Cb>GitHub · POLYMARKET-SPORTS\u002FPolymarket-trading-bot\u003C\u002Fb>\u003C\u002Fa>\n  &nbsp;·&nbsp;\n  \u003Ca href=\"https:\u002F\u002Fpolymarket.com\">\u003Cb>Polymarket.com\u003C\u002Fb>\u003C\u002Fa>\n\u003C\u002Fp>\n\n[![Node.js](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNode.js-18+-green.svg)](https:\u002F\u002Fnodejs.org\u002F)\n[![Polymarket](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FPolymarket-polymarket.com-5D3FD3)](https:\u002F\u002Fpolymarket.com)\n[![GitHub](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FGitHub-POLYMARKET--SPORTS%2FPolymarket--trading--bot-181717?logo=github)](https:\u002F\u002Fgithub.com\u002FPOLYMARKET-SPORTS\u002FPolymarket-trading-bot)\n\n\u003C\u002Fdiv>\n\n\u003Csub>\n\n**Keywords:** polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket arbitrage bot, polymarket copy trading bot polymarket  bot,\n\n\u003C\u002Fsub>\n\n---\n\n### Contents\n\n- [Why this repository](#why-this-repository)\n- [Overview](#overview)\n- [Screenshots](#screenshots)\n- [Detailed Runbook](#detailed-runbook)\n- [Key Features](#key-features)\n- [Repository Modes](#repository-modes)\n- [Strategy Summary](#strategy-summary)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Configuration](#configuration)\n- [Quick Start](#quick-start)\n- [Logging and Output](#logging-and-output)\n- [Project Structure](#project-structure)\n- [File Guide](#file-guide)\n- [Practical Safety Notes](#practical-safety-notes)\n- [Troubleshooting](#troubleshooting)\n- [Recommended First Run](#recommended-first-run)\n- [Disclaimer](#disclaimer)\n\n---\n\n## Why this repository\n\nThis project is built for users who need an operational trading runtime instead of a toy script:\n\n- Real CLOB authentication and order execution on Polymarket\n- On-chain approvals, merge, and redeem transaction flows\n- Real-time order-book monitoring via WebSocket with fallback logic\n- Configurable risk limits, circuit breakers, and graceful shutdown behavior\n- Dedicated copy-trading path for mirroring selected wallet activity\n\nThis repository contains:\n\n- A **5-minute BTC Up\u002FDown arbitrage bot** that posts both sides of the market, takes mispriced liquidity, merges matched pairs, and redeems after resolution.\n- An **integrated wallet-following module** that can mirror future buys from a target wallet during the main runtime.\n- A **dedicated buy-only copy trader** under `src\u002Fcopy\u002F` that polls Polymarket's public trade feed and reacts to fresh target-wallet buys.\n\nThe codebase is structured for real trading: on-chain approvals, Polymarket CLOB authentication, WebSocket order-book tracking, risk caps, circuit breakers, structured logging, and graceful shutdown handling are all included.\n\n> Important: This software places live blockchain and market orders. Use it only if you fully understand the strategy, the wallet setup, the gas implications, and the market risks.\n\n## Overview\n\nThis bot is designed around **Polymarket complementary-token markets**, especially the recurring `btc-updown-5m-*` markets.\n\nAt a high level, the main arbitrage engine:\n\n1. Loads your signer and Polymarket proxy wallet configuration.\n2. Ensures the required Polygon approvals are in place.\n3. Derives or refreshes Polymarket CLOB API credentials automatically.\n4. Discovers the next 5-minute BTC Up\u002FDown market before it opens.\n5. Posts a symmetric buy ladder on both `Up` and `Down`.\n6. Aggressively buys both sides when the combined ask becomes favorable.\n7. Merges matched pairs back into USDC when economically sensible.\n8. Cancels open orders at market close.\n9. Waits for resolution and redeems winning positions.\n\nThe repository also supports copy-trading workflows for users who want to follow a target Polymarket wallet with configurable sizing and risk caps.\n\n## Screenshots\n\nThe following screenshots show the workflow this bot targets.\n\n### Performance\n\n![1D performance view](img\u002FScreenshot_3.png)\n\n![Past week performance view](img\u002FScreenshot_1.png)\n\n![All-time performance view](img\u002FScreenshot_2.png)\n\n### Activity Snapshot\n\n![Trading activity snapshot](img\u002FG7o1D49WcAErNMi.png)\n\n## Detailed Runbook\n\n1. Install dependencies:\n\n```bash\nnpm install\n```\n\n2. Create your local environment file:\n\n```powershell\nCopy-Item .env.example .env\n```\n\nor:\n\n```bash\ncp .env.example .env\n```\n\n3. Configure at minimum:\n- `PRIVATE_KEY`\n- `PROXY_WALLET`\n- `POLYGON_RPC` (strongly recommended)\n\n4. Start with conservative limits and run:\n\n```bash\nnpm start\n```\n\n## Key Features\n\n- **Dual-sided ladder execution** for recurring BTC 5-minute markets.\n- **Taker arbitrage logic** when combined best ask drops below the configured edge threshold.\n- **On-chain merge and redeem support** for Polymarket negative-risk markets.\n- **Session and per-market risk controls** including spend caps and circuit breakers.\n- **Automatic CLOB credential derivation** through Polymarket's documented L1-to-L2 auth flow.\n- **Live WebSocket order-book tracking** for low-latency price updates.\n- **Optional wallet mirroring** for follow-trading workflows.\n- **Dedicated copy-trading engine** with filters for stale trades, price bounds, slippage, and cumulative spend.\n- **Structured console and file logging** through `winston`.\n- **Graceful shutdown** on `SIGINT` \u002F `SIGTERM`.\n\n## Repository Modes\n\nThere are two primary ways to use this repository.\n\n### 1. Main Arbitrage Engine\n\nThe main runtime lives in `src\u002Findex.js`.\n\nIt is focused on:\n\n- Discovering the next `btc-updown-5m` market\n- Posting both-sided ladders at the open\n- Executing taker arb when the market offers enough edge\n- Merging matched pairs back into USDC\n- Redeeming after oracle resolution\n\nThis is the core strategy described by the main `package.json` metadata.\n\n### 2. Copy-Trading Workflows\n\nThe repo currently contains **two copy-related paths**:\n\n- **Integrated copy watcher** in `src\u002Fcopy-trader.js`  \n  If `TARGET_WALLET` is set, the main runtime snapshots that wallet's current positions and then mirrors future increases in `totalBought`.\n\n- **Dedicated buy-only copy trader** in `src\u002Fcopy\u002F`  \n  This path uses `src\u002Fcopy\u002FactivityFeed.js` plus `src\u002Fcopy\u002FcopyTrader.js` to detect fresh public trade activity from one or more target wallets and submit capped buy orders quickly.\n\nIf your goal is to use the dedicated copy system, read the copy-trading section below carefully and prefer the explicit `src\u002Fcopy\u002Findex.js` entrypoint.\n\n## Strategy Summary\n\n### Main Arb Logic\n\nThe core `Trader` class in `src\u002Ftrader.js` implements a market lifecycle roughly like this:\n\n1. **Wait for market open**  \n   The bot discovers the next market before open, then waits until the trading window is live.\n\n2. **Post the ladder**  \n   It places buy orders across many configured price levels on both outcomes.\n\n3. **Monitor live best asks**  \n   A WebSocket feed keeps the current top-of-book available with REST fallback when needed.\n\n4. **Fire taker arb orders**  \n   When `bestAskUp + bestAskDown \u003C 1 - TARGET_EDGE`, the bot submits paired buy orders.\n\n5. **Merge matched pairs**  \n   If both outcomes have been accumulated in sufficient size, the bot merges them back into USDC.\n\n6. **Stop buying near market close**  \n   It stops adding risk before the window ends, then cancels remaining open orders.\n\n7. **Wait for resolution and redeem**  \n   After the market resolves, the bot redeems any winning positions.\n\n### Built-In Risk Controls\n\nThe main strategy includes multiple safety mechanisms:\n\n- `MAX_SPEND_PER_MARKET`\n- `MAX_TAKER_FILL_USDC`\n- `MAX_INVENTORY_IMBALANCE_USDC`\n- `COMBINED_ASK_STOP`\n- `MAX_LOSS_PER_HOUR_USDC`\n- `STOP_BUYING_BEFORE_CLOSE`\n- `MERGE_THRESHOLD_USDC`\n\nThese controls are not optional decoration. They define how aggressively the bot is allowed to trade and when it must stop.\n\n## Requirements\n\nBefore running the bot, make sure you have:\n\n- **Node.js 18+**\n- A **Polymarket account**\n- Your **Polygon EOA private key**\n- Your **Polymarket proxy wallet address**\n- **USDC on Polygon**\n- Enough native MATIC for gas\n- Access to a reliable Polygon RPC endpoint\n\nRecommended:\n\n- Use a dedicated wallet for bot operation\n- Start with small size caps\n- Use a private RPC provider instead of the default public endpoint\n- Test copy workflows with `COPY_DRY_RUN=true` first\n\n## Installation\n\nClone this repository (canonical URL):\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FPOLYMARKET-SPORTS\u002FPolymarket-trading-bot.git\ncd Polymarket-trading-bot\n```\n\nThen install dependencies:\n\n```bash\nnpm install\n```\n\nThe repo already includes a `package-lock.json`, so a normal `npm install` is the intended setup path.\n\n## Configuration\n\nCopy the example environment file.\n\nPowerShell:\n\n```powershell\nCopy-Item .env.example .env\n```\n\nBash:\n\n```bash\ncp .env.example .env\n```\n\nThen edit `.env` with your real wallet and risk settings.\n\n### Minimum Required Settings\n\nThese values are essential for almost every real run:\n\n| Variable | Required | Purpose |\n| --- | --- | --- |\n| `PRIVATE_KEY` | Yes | Your Polygon signer used for approvals and order signing |\n| `PROXY_WALLET` | Yes | The Polymarket proxy wallet tied to your account |\n| `POLYGON_RPC` | Strongly recommended | Polygon RPC endpoint used by `ethers` |\n| `LOG_LEVEL` | No | Console\u002Ffile logging verbosity |\n\n### Main Arbitrage Settings\n\nThese parameters shape the main strategy:\n\n| Variable | What it controls |\n| --- | --- |\n| `MAX_SPEND_PER_MARKET` | Total buy-side budget for one 5-minute market |\n| `TARGET_EDGE` | Minimum combined-price edge before firing arb buys |\n| `MERGE_THRESHOLD_USDC` | Minimum matched pair size before merge |\n| `MAX_TAKER_FILL_USDC` | Maximum size for a single taker action |\n| `MAX_INVENTORY_IMBALANCE_USDC` | Inventory imbalance guardrail |\n| `COMBINED_ASK_STOP` | Hard stop if the market becomes too expensive |\n| `MAX_LOSS_PER_HOUR_USDC` | Rolling session loss circuit breaker |\n| `LADDER_LEVELS` | Ladder prices posted on both sides |\n| `LADDER_SIZE_PER_LEVEL_USDC` | Size allocated to each ladder level |\n\n### Copy-Trading Settings\n\nThe repo exposes two different copy-trading parameter groups.\n\n#### Integrated Copy Watcher\n\n| Variable | Purpose |\n| --- | --- |\n| `TARGET_WALLET` | Single target Polymarket wallet to mirror during main runtime |\n| `COPY_TRADE_BUY_PERCENT` | Percent of target spend to mirror |\n| `COPY_TRADE_POLL_MS` | Poll interval for the target positions API |\n\n#### Dedicated Buy-Only Copy Trader\n\n| Variable | Purpose |\n| --- | --- |\n| `COPY_TARGETS` | Comma-separated list of target wallets |\n| `COPY_SIZE_MODE` | `FIXED`, `MIRROR`, or `RATIO` |\n| `COPY_FIXED_USDC` | Fixed spend per copied trade |\n| `COPY_RATIO` | Spend multiplier when `COPY_SIZE_MODE=RATIO` |\n| `COPY_MAX_USDC_PER_TRADE` | Hard cap per copied trade |\n| `COPY_MAX_USDC_PER_MARKET` | Hard cap per market |\n| `COPY_MAX_USDC_PER_HOUR` | Rolling hourly cap |\n| `COPY_MAX_USDC_TOTAL` | Session-wide cap |\n| `COPY_MAX_SLIPPAGE` | Maximum price premium above target fill |\n| `COPY_MAX_PRICE` | Upper price filter |\n| `COPY_MIN_PRICE` | Lower price filter |\n| `COPY_STALE_MS` | Reject stale signals |\n| `COPY_POLL_MS` | Poll frequency for target trades |\n| `COPY_ALLOWED_CONDITIONS` | Optional allow-list |\n| `COPY_BLOCKED_CONDITIONS` | Optional block-list |\n| `COPY_DRY_RUN` | Log-only mode without real orders |\n\n### CLOB Credentials\n\nThe example file includes:\n\n- `POLY_API_KEY`\n- `POLY_API_SECRET`\n- `POLY_API_PASSPHRASE`\n\nThese can be left blank on first run. The client in `src\u002Fclob.js` attempts to derive valid credentials automatically from your signer. If cached credentials become invalid, the client also attempts a refresh flow.\n\n## Quick Start\n\n### Main Arbitrage Bot\n\n1. Install dependencies with `npm install`.\n2. Copy `.env.example` to `.env`.\n3. Fill in `PRIVATE_KEY`, `PROXY_WALLET`, and a reliable `POLYGON_RPC`.\n4. Start with conservative values such as a smaller `MAX_SPEND_PER_MARKET`.\n5. Run the bot.\n\n```bash\nnpm start\n```\n\nYou can also run the explicit arb script:\n\n```bash\nnpm run arb\n```\n\nFor development mode with Node's file watcher:\n\n```bash\nnpm run dev\n```\n\nor\n\n```bash\nnpm run arb:dev\n```\n\n### Integrated Wallet Mirroring\n\nIf you want the main runtime to also mirror future buys from a specific target wallet:\n\n1. Set `TARGET_WALLET` in `.env`.\n2. Optionally tune `COPY_TRADE_BUY_PERCENT` and `COPY_TRADE_POLL_MS`.\n3. Launch the main bot as normal.\n\nThe bot will snapshot existing positions first, then only react to **new buy increases** observed after startup.\n\n### Dedicated Buy-Only Copy Trader\n\nIf you want the dedicated `src\u002Fcopy\u002F` implementation:\n\n1. Configure `COPY_TARGETS`.\n2. Set conservative caps.\n3. Prefer starting with `COPY_DRY_RUN=true`.\n4. Run the dedicated entrypoint directly.\n\n```bash\nnode src\u002Fcopy\u002Findex.js\n```\n\nThis path is useful when your focus is low-latency buy-following rather than the BTC 5-minute arbitrage lifecycle.\n\n## Logging and Output\n\nThe logger writes:\n\n- Colored structured logs to the console\n- JSON logs to `bot.log`\n\nThis is useful for:\n\n- Live monitoring\n- Post-session debugging\n- Reviewing order failures\n- Investigating market timing and slippage\n\n## Project Structure\n\n```text\n.\n|-- .env.example\n|-- package.json\n|-- img\u002F\n|-- src\u002F\n|   |-- index.js\n|   |-- trader.js\n|   |-- copy-trader.js\n|   |-- market.js\n|   |-- clob.js\n|   |-- onchain.js\n|   |-- pnl.js\n|   |-- logger.js\n|   `-- copy\u002F\n|       |-- index.js\n|       |-- activityFeed.js\n|       |-- copyTrader.js\n|       `-- config.js\n`-- README.md\n```\n\n## File Guide\n\n- `src\u002Findex.js`  \n  Main bot lifecycle, startup, market loop, graceful shutdown, and optional integrated copy watcher.\n\n- `src\u002Ftrader.js`  \n  Per-market state machine for ladder posting, taker arb, merge logic, order cancellation, and redeem flow.\n\n- `src\u002Fmarket.js`  \n  Polymarket Gamma\u002FData API helpers for market discovery, wallet positions, and resolution polling.\n\n- `src\u002Fclob.js`  \n  CLOB REST and WebSocket client, auth handling, order signing, and order posting utilities.\n\n- `src\u002Fonchain.js`  \n  Polygon approvals, token balances, merge transactions, and redeem transactions.\n\n- `src\u002Fcopy-trader.js`  \n  Integrated target-wallet mirroring based on changes in target positions.\n\n- `src\u002Fcopy\u002FactivityFeed.js`  \n  High-frequency polling of public trade data for specific wallets.\n\n- `src\u002Fcopy\u002FcopyTrader.js`  \n  Dedicated copy-trading execution engine with filters and spend accounting.\n\n## Practical Safety Notes\n\n- Do **not** start with large sizing.\n- Do **not** run with a wallet you use for unrelated funds.\n- Do **not** assume public RPC endpoints are stable enough for serious production usage.\n- Do **not** skip reading the `.env.example` comments; they explain the intended meaning of most controls.\n- Do start with `COPY_DRY_RUN=true` for copy trading.\n- Do verify your proxy wallet address carefully.\n- Do keep enough MATIC available for approvals, merges, and redeems.\n\n## Troubleshooting\n\n### The bot exits immediately with a missing env var error\n\nCheck `.env` and confirm the required fields are actually populated:\n\n- `PRIVATE_KEY`\n- `PROXY_WALLET`\n\nFor dedicated copy trading, also confirm:\n\n- `COPY_TARGETS`\n\n### Orders fail or the bot cannot authenticate\n\n- Confirm your signer matches the intended Polymarket account.\n- Confirm `PROXY_WALLET` is the correct proxy wallet for that signer.\n- Try a stable private Polygon RPC endpoint.\n- Leave `POLY_API_*` blank if you want the bot to derive fresh credentials automatically.\n\n### Copy trades are not firing\n\n- Make sure your target wallet address is lowercased correctly in the copy settings.\n- Check that the target is placing fresh **BUY** trades, not only sells or old fills.\n- Verify your caps are not too restrictive.\n- For dedicated copy mode, make sure `COPY_DRY_RUN` is set the way you expect.\n\n### Merge or redeem transactions fail\n\n- Confirm approvals were granted successfully.\n- Confirm you hold enough matched positions to merge.\n- Confirm the market is actually resolved before expecting redeem payout.\n- Check `bot.log` for the underlying error payload.\n\n## Recommended First Run\n\nIf you are launching this repo for the first time, the safest path is:\n\n1. Fill `.env` with real wallet values.\n2. Use a private RPC endpoint.\n3. Lower your spend caps materially.\n4. Run the main bot in observation mode with small sizing.\n5. If testing copy logic, enable `COPY_DRY_RUN=true` first.\n6. Review `bot.log` after a short session before scaling up.\n\n## Disclaimer\n\nThis repository is provided for research and operational use by experienced users. It is **not financial advice**, and it does not guarantee profit. Real-money trading on Polymarket and Polygon involves market risk, execution risk, smart contract risk, RPC reliability risk, and operational risk. You are fully responsible for how you configure and use this software.\n","Polymarket-trading-bot 是一个针对 Polymarket 平台上短期 Up\u002FDown 市场的自动化交易机器人，支持套利和跟单交易。该项目使用 Node.js 开发，核心功能包括通过 WebSocket 实时监控订单簿、自动执行订单、处理链上批准及交易流程等，并且具备风险管理和优雅关闭机制。适用于希望在 Polymarket 上进行高效自动化交易的用户，尤其是那些对 BTC 5分钟涨跌预测市场感兴趣的投资者。此外，它还提供了一个专门的模块来跟踪并复制指定钱包的交易活动，非常适合需要快速响应市场变化或模仿成功交易策略的场景。",2,"2026-05-18 11:12:49","CREATED_QUERY"]