A production-grade, real-time copy trading system for Polymarket, designed to automatically mirror trades from selected wallets with high reliability, low latency, and robust risk controls. Built in TypeScript with Node.js, the bot integrates directly with Polymarket's Central Limit Order Book (CLOB) API for institutional-level execution.
If you find this bot helpful and profitable, we'd greatly appreciate your support! Consider sending 10% of your profits to help maintain and improve this project:
Wallet Address: 4GNqE1cn7wRZyGsv8MHHMf8C6QSc3Mk3fWYkLdTNf7EX
Your support helps us continue developing and maintaining this tool. Thank you! 🙏
The Polymarket Copy Trading Bot continuously monitors target wallets and replicates their trading activity according to configurable risk parameters. It is designed for professional deployment, supporting automated trade execution, precise order handling, and comprehensive logging.
- Real-Time Trade Monitoring – Continuously fetches and processes trades from target wallets
- Automatic Trade Execution – Mirrors buy/sell/merge operations with intelligent position matching
- Advanced Risk Management – Balance-based position sizing and retry mechanisms
- Flexible Order Execution – Supports FOK (Fill-or-Kill) order types
- MongoDB Integration – Persistent tracking of trades and positions
- Multi-Outcome Compatibility – Works seamlessly with binary and multi-outcome markets
⚠️ Past performance does not guarantee future results. Trading prediction markets involves significant risk. Use responsibly and only with capital you can afford to lose.
target address : https://polymarket.com/@k9Q2mX4L8A7ZP3R
The bot has demonstrated profitable performance in testing. Below is a screenshot showing the profit/loss progression over a test period:
Test Results Summary:
- Initial Profit: $28.08 (Dec 20, 2025 6:00 PM)
- Final Profit: $923.41 (Dec 22, 2025 6:00 AM)
- Time Period: ~36 hours
- Performance: Consistent upward trend with significant profit accumulation
- Growth: Over 3,200% increase in profit during the test period
Note: These results are from a test environment. Real-world performance may vary based on market conditions, wallet selection, and configuration parameters.
- Runtime: Node.js 18+
- Language: TypeScript (v5.7+)
- Blockchain: Polygon (Ethereum-compatible L2)
- Web3: Ethers.js v5
- Database: MongoDB
- APIs:
@polymarket/clob-client- Polymarket CLOB trading client- Polymarket Data API - For fetching activities and positions
- Utilities: Axios, Mongoose, Ora (spinners)
Polymarket Data API (HTTP Polling)
↓
Trade Monitor (Fetches & Validates Trades)
↓
MongoDB (Stores Trade History)
↓
Trade Executor (Reads Pending Trades)
↓
Position Analysis (Compares Wallets)
↓
CLOB Client (Executes Orders)
↓
Order Execution (Buy/Sell/Merge Strategies)
- Node.js 18+ and npm
- MongoDB (running locally or remote)
- Polygon Wallet funded with USDC
- Polymarket Account with API access
- Clone the repository:
git clone https://github.com/BlackSkyorg/polymarket-copytrading-bot.git
cd Polymarket-copy-trading-bot-2025-12- Install dependencies:
npm install- Create environment configuration:
Create a .env file in the root directory:
# Target user wallet address to copy trades from
USER_ADDRESS=0xYourTargetWalletAddress
# Your wallet address (proxy wallet) that will execute trades
PROXY_WALLET=0xYourProxyWalletAddress
# Private key of your proxy wallet (64 hex characters, NO 0x prefix)
PRIVATE_KEY=your_private_key_here
# Polymarket CLOB API URLs
CLOB_HTTP_URL=https://clob.polymarket.com
CLOB_WS_URL=wss://clob-ws.polymarket.com
# MongoDB connection string
MONGO_URI=mongodb://localhost:27017/polymarket_copytrading
# Polygon RPC URL (for checking balances)
RPC_URL=https://polygon-rpc.com
# USDC contract address on Polygon
USDC_CONTRACT_ADDRESS=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174
# Optional: Configuration defaults
FETCH_INTERVAL=1
TOO_OLD_TIMESTAMP=24
RETRY_LIMIT=3- Start MongoDB:
# Windows
net start MongoDB
# Linux/Mac
sudo systemctl start mongod
# or
mongod- Start the bot:
# Development mode (with ts-node)
npm run dev
# Or build and run
npm run build
npm startOn first launch, API credentials are automatically created/derived from your wallet.
| Variable | Description | Required |
|---|---|---|
USER_ADDRESS |
Target wallet address to copy trades from | Yes |
PROXY_WALLET |
Your wallet address that executes trades | Yes |
PRIVATE_KEY |
Your wallet private key (64 hex, no 0x) | Yes |
CLOB_HTTP_URL |
Polymarket CLOB HTTP API endpoint | Yes |
CLOB_WS_URL |
Polymarket WebSocket endpoint | Yes |
MONGO_URI |
MongoDB connection string | Yes |
RPC_URL |
Polygon RPC endpoint | Yes |
USDC_CONTRACT_ADDRESS |
USDC token contract on Polygon | Yes |
FETCH_INTERVAL |
Trade monitoring interval (seconds) | No (default: 1) |
TOO_OLD_TIMESTAMP |
Ignore trades older than X hours | No (default: 24) |
RETRY_LIMIT |
Maximum retry attempts for failed trades | No (default: 3) |
npm run devThe bot will:
- Connect to MongoDB
- Initialize CLOB client and create/derive API keys
- Start trade monitor (fetches trades every X seconds)
- Start trade executor (processes pending trades)
- Monitor target wallet and execute copy trades automatically
When running successfully, you should see:
MongoDB connected
Target User Wallet address is: 0x...
My Wallet address is: 0x...
API Key created/derived
Trade Monitor is running every 1 seconds
Executing Copy Trading
Waiting for new transactions...
- Monitor: Fetches user activities from Polymarket API
- Filter: Identifies new TRADE type activities
- Store: Saves new trades to MongoDB
- Execute: Reads pending trades and determines action (buy/sell/merge)
- Match: Compares positions between target wallet and your wallet
- Trade: Executes orders via CLOB client
- Update: Marks trades as processed in database
- Fetch Activities: Monitor target wallet via Polymarket Data API
- Filter Trades: Identify TRADE type activities only
- Check Duplicates: Verify trade hasn't been processed before
- Validate Timestamp: Ignore trades older than configured threshold
- Save to Database: Store new trades in MongoDB
- Read Pending Trades: Query database for unprocessed trades
- Fetch Positions: Get current positions for both wallets
- Get Balances: Check USDC balances for both wallets
- Determine Condition: Decide on buy/sell/merge based on positions
- Execute Order: Place order via CLOB client using appropriate strategy
- Update Status: Mark trade as processed in database
- Buy Strategy: When target wallet buys, calculate position size based on balance ratio
- Sell Strategy: When target wallet sells, match the sell proportionally
- Merge Strategy: When target wallet closes position but you still hold, sell your position
- Error Handling: Retry failed orders up to RETRY_LIMIT, then mark as failed
src/
├── index.ts # Main entry point
├── config/
│ ├── db.ts # MongoDB connection
│ └── env.ts # Environment variables
├── services/
│ ├── tradeMonitor.ts # Monitors target wallet trades
│ ├── tradeExecutor.ts # Executes copy trades
│ └── createClobClient.ts # Alternative CLOB client (unused)
├── utils/
│ ├── createClobClient.ts # CLOB client initialization
│ ├── fetchData.ts # HTTP data fetching
│ ├── getMyBalance.ts # USDC balance checker
│ ├── postOrder.ts # Order execution logic
│ └── spinner.ts # Terminal spinner
├── models/
│ └── userHistory.ts # MongoDB schemas
├── interfaces/
│ └── User.ts # TypeScript interfaces
└── test/
└── test.ts # Test utilities
- Trade detection and execution
- Balance and allowance checks
- Redemption outcomes
- Structured logs for debugging and audits
Log levels: info, success, warning, error
- Copy trading amplifies both profits and losses
- Liquidity and slippage risks apply
- Gas fees incurred on every transaction
- WebSocket or API outages may impact execution
Best Practices:
- Start with low multipliers
- Enforce strict max order sizes
- Monitor balances regularly
- Test using dry-run modes
# Type check
npm run build
# Run in development mode
npm run dev
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run formatThis copy trading bot was developed as part of a comprehensive Polymarket trading strategy system. Development began in December 2025, focusing on automated trade execution and position management.
- Real-time trade monitoring and execution
- Intelligent position matching and sizing
- Automatic retry mechanisms for failed orders
- MongoDB-based trade history tracking
- Support for multiple market types
-
"USER_ADDRESS is not defined"
- Check your
.envfile exists and has all required variables
- Check your
-
"MongoDB connection error"
- Ensure MongoDB is running
- Verify
MONGO_URIis correct
-
"Cannot find module '@polymarket/clob-client'"
- Run
npm installto install dependencies
- Run
-
"invalid hexlify value"
- Check
PRIVATE_KEYis 64 hex characters without0xprefix
- Check
-
"API Key creation failed"
- Verify
PRIVATE_KEYmatchesPROXY_WALLET - Ensure wallet has proper permissions
- Verify
Before running in production:
- Monitor first few trades carefully
- Verify MongoDB is storing trades correctly
- Check order execution logs
ISC
Disclaimer: This software is provided as-is without warranties. Trading prediction markets involves substantial risk. Use responsibly and only with capital you can afford to lose. Past performance does not guarantee future results.
