A sophisticated automated trading bot that mirrors the positions of a target trader on Polymarket. The bot continuously monitors a specified wallet address and replicates their trading positions in real-time with customizable risk management parameters.
The bot operates on a simple yet powerful principle:
- Monitor: Continuously scans the target user's positions every 4 seconds (configurable)
- Analyze: Compares target positions with your current positions
- Execute: Automatically places buy/sell orders to match the target's portfolio allocation
- Auto Redeemption Automatically redeem resolved positions every 2 hours
- Risk Management: Applies position limits and portfolio constraints to protect your capital
- Real-time Position Mirroring: Instantly replicates target trader's positions
- Risk Management: Built-in position size limits and portfolio protection
- Gas Optimization: Smart gas price management for cost-effective trading
- RPC Rotation: Automatic RPC endpoint rotation for reliability
- Blacklist Support: Exclude specific assets from copying
- Safe Wallet Integration: Secure multi-signature wallet support. (This bot is for safe wallet, you need to create polyaccount with third party wallet like metamask or phantom)
- MongoDB Integration: Position tracking and trade history storage
Before installing the bot, ensure you have:
- Node.js (v16 or higher)
- npm or yarn package manager
- MongoDB database (local or cloud)
- Polygon RPC endpoint (Infura, Alchemy, or similar)
- Private key of your trading wallet
- USDC balance on Polygon network for trading
git clone https://github.com/Trust412/polymarket-copy-trading-bot-v3.git
cd polymarket-copy-trading-bot-v3npm installCreate a .env file in the root directory and configure the following variables:
# Target Configuration
TARGET_USER_ADDRESS = '0xf5201...'
MY_PROXY_WALLET_ADDRESS = '0xf6d01...'
# Wallet Configuration
PRIVATE_KEY = '0x35c57...'
# Smart Contract Addresses (Polygon Mainnet)
PROXY_WALLET_FACTORY_ADDRESS = '0x56C79347e95530c01A2FC76E732f9566dA16E113'
NEG_RISK_ADAPTER_ADDRESS = '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296'
CONDITIONAL_TOKENS_FRAMEWORK_ADDRESS = '0x4d97dcd97ec945f40cf65f87097ace5ea0476045'
USDC_CONTRACT_ADDRESS = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'
SAFE_MULTISEND_ADDRESS = '0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761'
# API Endpoints
CLOB_HTTP_URL = 'https://clob.polymarket.com/'
CLOB_WS_URL = 'wss://ws-subscriptions-clob.polymarket.com/ws'
GAMMA_API_URL = 'https://gamma-api.polymarket.com'
# Gas Configuration
GAS_LIMIT = 5000
GAS_PRICE_LIMIT = 110000000000
# Bot Configuration
WAITING_TIME = 4 # Scan interval in seconds
MAX_POSITION_LIMIT = 0.2 # Maximum 20% per position
# Infrastructure
RPC_URL = 'https://polygon-mainnet.infura.io/v3/YOUR_PROJECT_ID'
MONGO_URI = 'mongodb+srv://username:password@cluster.mongodb.net/database'You can find rpcRotator.ts file in the root directory. This is a tool to rotate your RPC URL. You can use it to rotate your RPC URL. You have to create rpcUrls.json file in the polygon/private directory.
{
"rpcUrls": [
"https://polygon-mainnet.infura.io/v3/your_project_id1",
"https://polygon-mainnet.infura.io/v3/your_project_id2",
"https://polygon-mainnet.infura.io/v3/your_project_id3"
...
]
}
More 5 RPC URL is recommended to overcome the RPC URL limit. If you use unlimited version of infura, you can ignore this step. Plz delete rpcRotator.ts file and related line in codebase.
| Variable | Description | Example | Required |
|---|---|---|---|
TARGET_USER_ADDRESS |
Wallet address of the trader you want to copy | 0xf52015... |
β |
MY_PROXY_WALLET_ADDRESS |
Your proxy wallet address for trading | 0xf6d01b... |
β |
PRIVATE_KEY |
Private key of your trading wallet (keep secure! MetaMask or Phantom) | 0x35c57d... |
β |
| Variable | Description | Default | Recommended |
|---|---|---|---|
MAX_POSITION_LIMIT |
Maximum percentage of portfolio per position | 0.2 (20%) |
0.1-0.3 |
WAITING_TIME |
Seconds between position scans | 4 |
3-10 |
GAS_PRICE_LIMIT |
Maximum gas price in wei | 110000000000 |
Adjust based on network |
| Variable | Description | How to Get |
|---|---|---|
RPC_URL |
Polygon RPC endpoint | Get from Infura or Alchemy |
MONGO_URI |
MongoDB connection string | Create at MongoDB Atlas |
These are pre-configured for Polygon mainnet. Do not change unless you know what you're doing.
- Create account at MongoDB Atlas
- Create a new cluster
- Create database user with read/write permissions
- Get connection string and add to
MONGO_URI
# Install MongoDB locally
brew install mongodb/brew/mongodb-community # macOS
# or
sudo apt-get install mongodb # Ubuntu
# Start MongoDB service
brew services start mongodb/brew/mongodb-community- Sign up at Infura.io
- Create new project
- Select Polygon network
- Copy project ID
- Use:
https://polygon-mainnet.infura.io/v3/YOUR_PROJECT_ID
- Sign up at Alchemy.com
- Create new app on Polygon
- Copy HTTP URL
- Use the provided URL
npm run devnpm run build
npm start# Install PM2 globally
npm install -g pm2
# Start bot with PM2
pm2 start dist/index.js --name "polymarket-bot"
# Monitor logs
pm2 logs polymarket-bot
# Restart bot
pm2 restart polymarket-bot
# Stop bot
pm2 stop polymarket-bot-
Choose a VPS Provider
- DigitalOcean, AWS EC2, Google Cloud, or Vultr
- Minimum: 1GB RAM, 1 CPU core
- Choose the location carefully as many of locations are banned from polymarket.
Choose your vps carefully! I highly recommend tradingvps.io) (German IP), ping speed was under 1ms.

-
Server Setup
# Update system sudo apt update && sudo apt upgrade -y # Install Node.js curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt-get install -y nodejs # Install PM2 sudo npm install -g pm2 # Clone and setup project git clone https://github.com/Trust412/polymarket-copy-trading-bot-v3.git cd polymarket-copy-trading-bot-v3 npm install
-
Configure Environment
# Create .env file nano .env # Add your configuration # Build and start npm run build pm2 start dist/index.js --name "polymarket-bot" pm2 startup pm2 save
# Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
CMD ["npm", "start"]# Build and run
docker build -t polymarket-bot .
docker run -d --name polymarket-bot --env-file .env polymarket-bot# PM2 logs
pm2 logs polymarket-bot
# Real-time monitoring
pm2 monitThe bot includes built-in health monitoring:
- RPC connection status
- MongoDB connection
- Trading balance checks
- Gas price monitoring
-
Regular Balance Checks
- Monitor USDC balance
- Check gas token (MATIC) balance
-
Update Dependencies
npm update npm audit fix
-
Database Cleanup
- Archive old trade data
- Monitor database size
- Never share your private key
- Use environment variables only
- Consider hardware wallet integration for large amounts
- Regularly rotate keys
- Use HTTPS RPC endpoints only
- Enable firewall on your server
- Use VPN for additional security
- Monitor for unusual activity
- Start with small amounts
- Monitor positions regularly
- Set up alerts for large losses
-
"Insufficient Balance" Error
- Check USDC balance in your wallet
- Ensure gas token (MATIC) balance
-
RPC Connection Issues
- Verify RPC URL is correct
- Check rate limits
- Try different RPC provider
-
MongoDB Connection Failed
- Verify connection string
- Check network access
- Ensure database user permissions
# Enable debug logging
DEBUG=* npm startWAITING_TIME: 4-6 seconds (balance between speed and API limits)MAX_POSITION_LIMIT: 0.1-0.2 (10-20% per position)- Use multiple RPC endpoints for redundancy
- Monitor API rate limits
- Consider multiple bot instances for different targets
- Implement position size scaling based on portfolio size
- Check logs first:
pm2 logs polymarket-bot - Review configuration settings
- Test with small amounts first
- Fork the repository
- Create feature branch
- Submit pull request
Users are responsible for:
- Compliance with local regulations
- Understanding trading risks
- Proper risk management
- Securing private keys
Trading involves significant risk. Never invest more than you can afford to lose.
MIT License - see LICENSE file for details.
Happy Trading! π
Remember: Start small, monitor closely, and always prioritize security over profits.
- If you have any questions or need support, feel free to contact me via Telegram.