Copy any Polymarket trader automatically. This bot monitors a chosen wallet and mirrors their prediction market orders on your wallet in real time.
- What You Get
- What's New in Version 2
- Key Features (This Version)
- How It Works
- Prerequisites
- Installation
- Configuration
- Usage
- Geographic Restrictions
- Contributing
- License
- Contact
- One trader, one config — Set the wallet you want to copy; the bot does the rest.
- Real-time monitoring — Polls Polymarket for the target’s activity at an interval you choose (default 1 second).
- Automated execution — New trades are detected, then placed on your wallet via the official CLOB.
- Persistence & retries — MongoDB stores activity and pending trades; failed copies are retried up to a limit you set.
- Full control — Adjust poll interval, order age cutoff, and retry count via environment variables.
Version 2 is a step up from a basic copy-trading script. Here’s what’s advanced and added in this release.
The bot runs on a simple loop:
| Step | What it does |
|---|---|
| Monitor | Scans the target wallet’s activity every FETCH_INTERVAL seconds (default 1 s). |
| Analyze | Compares the target’s positions with yours and finds trades to copy. |
| Execute | Places buy/sell orders on your wallet to mirror the target’s positions. |
| Persist | Saves activity and pending trades in MongoDB so the bot can resume and retry. |
| Feature | Description |
|---|---|
| Real-time trade monitoring | Continuously polls Polymarket for the target’s activity and keeps MongoDB in sync so you don’t miss trades after a restart. |
| Automated trade execution | Reads pending trades from MongoDB, compares positions and balances, then places orders on your wallet via the official CLOB client. |
| MongoDB integration | Stores user activities and positions per wallet. Enables resume-after-restart and a clear history of what was copied. |
| Retry logic | Failed executions (e.g. network errors) are retried up to RETRY_LIMIT times so temporary issues don’t drop trades. |
| Order age filter | Ignores trades older than TOO_OLD_TIMESTAMP (hours) so you only copy recent, relevant orders. |
| Configurable timing | FETCH_INTERVAL (seconds) lets you balance speed vs API load; default is 1 second for near real-time copying. |
| Official CLOB client | Uses @polymarket/clob-client for signing and submitting orders correctly on Polymarket. |
| Balance & position checks | Before placing orders, the bot checks your USDC balance and compares your positions to the target’s so execution is consistent. |
- Single target — Copy one wallet at a time (one
USER_ADDRESS). - Standard wallet — Uses your own wallet and private key (e.g. MetaMask/Phantom); no multi-sig or Safe wallet in this version.
- Simple config — No RPC rotation, blacklist, or auto-redemption in v2; those may appear in later versions.
Start small, monitor your positions, and keep your private key secure.
| Feature | What it does |
|---|---|
| Trade monitor | Fetches the target wallet’s activity on a timer, keeps your MongoDB in sync so you don’t miss trades after restarts. |
| Trade executor | Reads pending trades from MongoDB, compares your positions vs the target’s, checks balances, and places orders on your wallet. |
| MongoDB history | Stores activities and positions per wallet so the bot can resume and retry without re-fetching everything. |
| Retry logic | Copies that fail (e.g. network) are retried up to RETRY_LIMIT times so temporary errors don’t drop trades. |
| Order age filter | Ignores trades older than TOO_OLD_TIMESTAMP (hours) so you only copy recent, relevant orders. |
| Official CLOB client | Uses @polymarket/clob-client and your private key to sign and submit orders correctly. |
| Configurable timing | FETCH_INTERVAL (seconds) controls how often the monitor runs; tune for speed vs API load. |
- Start the bot — It connects to MongoDB and the Polymarket CLOB using your
.env. - Monitor — On a loop, it fetches the target wallet’s activity and updates MongoDB.
- Execute — In parallel, it reads pending trades from MongoDB and places matching orders on your wallet (with balance and position checks).
- Retry — Failed executions are retried according to
RETRY_LIMIT.
You need: the target wallet address to copy, your Polymarket wallet (and its private key), MongoDB, and a Polygon RPC URL. Your wallet must hold USDC on Polygon to place orders.
- Node.js 18+ and npm
- MongoDB — Local or MongoDB Atlas
- Polygon RPC — e.g. Infura, Alchemy
- Wallets — The Polymarket wallet you want to copy, and your own wallet (with USDC on Polygon) that will execute copies
-
Clone and enter the project
git clone https://github.com/OnChainMee/polymarket-copy-trading-bot.git cd polymarket-copy-trading-bot -
Install dependencies
npm install
-
Create a
.envfile in the project root (see Configuration). -
Build and run
npm run build npm start
Development (with ts-node):
npm run devCreate a .env file in the project root. Do not commit .env or share keys.
| Variable | Required | Description | Example / default |
|---|---|---|---|
USER_ADDRESS |
Yes | Polymarket wallet address to copy | 0x... |
PROXY_WALLET |
Yes | Your Polymarket wallet (executes copies) | 0x... |
PRIVATE_KEY |
Yes | Private key for PROXY_WALLET (no 0x prefix) |
— |
CLOB_HTTP_URL |
Yes | Polymarket CLOB API base URL | https://clob.polymarket.com/ |
CLOB_WS_URL |
Yes | Polymarket CLOB WebSocket URL | wss://ws-subscriptions-clob.polymarket.com/ws |
MONGO_URI |
Yes | MongoDB connection string | mongodb+srv://user:pass@cluster.mongodb.net/dbname |
RPC_URL |
Yes | Polygon mainnet RPC URL | https://polygon-mainnet.g.alchemy.com/v2/YOUR_KEY |
USDC_CONTRACT_ADDRESS |
Yes | USDC on Polygon | 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 |
FETCH_INTERVAL |
No | Poll interval in seconds | 1 |
TOO_OLD_TIMESTAMP |
No | Ignore orders older than this (hours) | 24 |
RETRY_LIMIT |
No | Max retries per execution | 3 |
Example .env (replace placeholders; never commit real keys):
USER_ADDRESS=0xTargetTraderAddress
PROXY_WALLET=0xYourPolymarketWallet
PRIVATE_KEY=your_private_key_no_0x_prefix
CLOB_HTTP_URL=https://clob.polymarket.com/
CLOB_WS_URL=wss://ws-subscriptions-clob.polymarket.com/ws
MONGO_URI=mongodb+srv://user:password@cluster.mongodb.net/your_db
RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/YOUR_ALCHEMY_KEY
USDC_CONTRACT_ADDRESS=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
FETCH_INTERVAL=1
TOO_OLD_TIMESTAMP=24
RETRY_LIMIT=3- Production:
npm run buildthennpm start - Development:
npm run dev
On startup the bot connects to MongoDB, then starts the trade monitor (target wallet) and trade executor (your wallet). Ensure your proxy wallet has USDC on Polygon so orders can be placed.
Polymarket may restrict access from some regions. If you hit IP-based blocks:
- Run the bot from a supported region (e.g. VPS in the Netherlands or another allowed location).
- Use a low-latency provider close to Polymarket’s infrastructure if you care about execution speed.
This project does not endorse any specific VPS provider. Choose a host that meets your legal and performance needs.
Contributions are welcome. Open an issue to discuss larger changes, then submit a pull request. If you find the project useful, consider giving it a star.
ISC — see package.json for details.
For questions or updates: Telegram.