Enterprise-grade automated copy trading system for Polymarket. Automatically replicate trades from top-performing traders with intelligent position sizing, risk management, and real-time execution.
- Overview
- Key Features
- Architecture
- Prerequisites
- Installation
- Configuration
- Usage
- Deployment
- Documentation
- Security
- Contributing
- License
The Polymarket Copy Trading Bot is a production-ready TypeScript application that enables automated replication of trading strategies from successful Polymarket traders. The system monitors trader activity in real-time, calculates optimal position sizes based on your capital allocation, and executes matching orders with built-in risk management and slippage protection.
- Trader Selection - Identify top performers using Polymarket leaderboard analytics
- Continuous Monitoring - Real-time polling of trader positions via Polymarket Data API
- Intelligent Sizing - Dynamic position sizing based on capital ratios and risk parameters
- Order Execution - Automated order placement through Polymarket CLOB API
- Performance Tracking - Comprehensive trade history and analytics stored in MongoDB
- Multi-Trader Support - Simultaneously track and replicate trades from multiple traders
- Advanced Position Sizing - Three strategies: Percentage-based, Fixed amount, and Adaptive scaling
- Tiered Multipliers - Apply different risk multipliers based on trade size ranges
- Trade Aggregation - Intelligent batching of small trades to optimize execution and reduce fees
- Real-Time Execution - Sub-second trade detection and execution latency
- Slippage Protection - Automatic price validation before order execution
- Position Limits - Configurable maximum order size and position size constraints
- Balance Protection - Automatic order size reduction when insufficient funds
- Minimum Order Validation - Prevents execution of orders below exchange minimums
- MongoDB Integration - Persistent storage of all trades, positions, and historical data
- Position Tracking - Accurate tracking of purchases and sales across balance changes
- Performance Analytics - Built-in scripts for profitability analysis and trader evaluation
- Health Monitoring - Comprehensive health check system for system validation
┌─────────────────┐
│ Trade Monitor │ → Polls Polymarket Data API
└────────┬────────┘
│
▼
┌─────────────────┐
│ Trade Executor │ → Calculates positions & executes orders
└────────┬────────┘
│
▼
┌─────────────────┐
│ MongoDB Store │ → Persistent data storage
└─────────────────┘
- Runtime: Node.js 18+ with TypeScript
- Blockchain: Polygon Network (Ethereum-compatible)
- Database: MongoDB with Mongoose ODM
- APIs: Polymarket CLOB Client, Polymarket Data API
- Web3: ethers.js v5 for blockchain interactions
Before installation, ensure you have:
- Node.js v18.0.0 or higher
- MongoDB database (local or MongoDB Atlas free tier)
- Polygon Wallet with:
- USDC balance for trading
- POL/MATIC for gas fees
- RPC Endpoint for Polygon network:
# Clone the repository
git clone https://github.com/0xRustPro/polymarket-copy-trading-bot.git
cd polymarket-trading-bot
# Install dependencies
npm install
# Run interactive setup wizard
npm run setup
# Build the application
npm run build
# Verify configuration
npm run health-check
# Start the bot
npm startIf you prefer manual configuration, create a .env file in the root directory:
# Trader Configuration
USER_ADDRESSES='0xABC...,0xDEF...'
# Wallet Configuration
PROXY_WALLET='0x123...'
PRIVATE_KEY='your_private_key_without_0x_prefix'
# Database
MONGO_URI='mongodb+srv://user:pass@cluster.mongodb.net/database'
# Network
RPC_URL='https://polygon-mainnet.infura.io/v3/YOUR_PROJECT_ID'
USDC_CONTRACT_ADDRESS='0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'
# Polymarket API
CLOB_HTTP_URL='https://clob.polymarket.com/'
CLOB_WS_URL='wss://ws-subscriptions-clob.polymarket.com/ws'
# Trading Strategy
COPY_STRATEGY='PERCENTAGE'
COPY_SIZE='10.0'
MAX_ORDER_SIZE_USD='100.0'
MIN_ORDER_SIZE_USD='1.0'
# Monitoring
FETCH_INTERVAL='1'
RETRY_LIMIT='3'For complete configuration options, see Configuration Guide.
The bot supports three copy trading strategies:
Replicates a fixed percentage of each trader's order size.
COPY_STRATEGY='PERCENTAGE'
COPY_SIZE='10.0' # Copy 10% of trader's orderExecutes a fixed dollar amount per trade, regardless of trader's order size.
COPY_STRATEGY='FIXED'
COPY_SIZE='50.0' # Always trade $50Dynamically adjusts percentage based on trade size (higher % for small trades, lower % for large trades).
COPY_STRATEGY='ADAPTIVE'
COPY_SIZE='10.0'
ADAPTIVE_MIN_PERCENT='5.0'
ADAPTIVE_MAX_PERCENT='15.0'
ADAPTIVE_THRESHOLD_USD='300.0'Apply different risk multipliers based on trade size:
TIERED_MULTIPLIERS='1-10:2.0,10-100:1.0,100-500:0.2,500+:0.1'This configuration:
- Trades $1-$10: 2.0x multiplier
- Trades $10-$100: 1.0x multiplier
- Trades $100-$500: 0.2x multiplier
- Trades $500+: 0.1x multiplier
- Visit Polymarket Leaderboard
- Identify traders with:
- Positive P&L over extended periods
- Win rate >55%
- Active trading history
- Consistent performance metrics
- Verify detailed analytics on Predictfolio
- Add wallet addresses to
USER_ADDRESSES(comma-separated)
# Development mode
npm run dev
# Production mode
npm run build
npm startThe bot includes comprehensive utility scripts:
npm run manual-sell # Manually sell positions
npm run sell-large # Sell large positions
npm run close-stale # Close stale positions
npm run close-resolved # Close resolved markets
npm run redeem-resolved # Redeem resolved positionsnpm run simulate # Simulate profitability
npm run find-traders # Find best traders
npm run find-low-risk # Find low-risk traders
npm run check-stats # Check your trading stats
npm run check-pnl # Check P&L discrepanciesnpm run setup # Interactive setup wizard
npm run health-check # Verify system configuration
npm run check-allowance # Check token allowances
npm run set-token-allowance # Set token allowancesDeploy using Docker Compose for production environments:
# Copy environment template
cp .env.example .env
# Edit .env with your configuration
# Start services
docker-compose up -d
# View logs
docker-compose logs -f polymarket
# Stop services
docker-compose downFor detailed Docker deployment instructions, see Docker Guide.
- Use environment-specific configuration files
- Implement proper secret management (AWS Secrets Manager, HashiCorp Vault)
- Set up monitoring and alerting
- Configure log rotation
- Use process managers (PM2, systemd) for reliability
- Implement backup strategies for MongoDB
- Getting Started Guide - Comprehensive setup instructions for beginners
- Quick Start Guide - Fast setup for experienced developers
- Multi-Trader Guide - Managing multiple traders
- Tiered Multipliers - Advanced risk management
- Simulation Guide - Backtesting and analysis
- Position Tracking - Understanding position management
- Docker Guide - Container deployment
- Deployment Guide - Production deployment strategies
- Never commit
.envfiles - Already excluded in.gitignore - Use dedicated trading wallets - Never use wallets with significant holdings
- Rotate API keys regularly - Change Polymarket API credentials periodically
- Monitor wallet activity - Set up alerts for unexpected transactions
- Use read-only database users - Limit MongoDB permissions when possible
- Keep dependencies updated - Regularly update npm packages
- Environment variable validation
- Input sanitization for addresses and configuration
- Error handling to prevent information leakage
- Secure private key handling (never logged or transmitted)
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install dependencies
npm install
# Run tests
npm test
# Run linter
npm run lint
# Format code
npm run formatThis project is licensed under the ISC License - see the LICENSE file for details.
- Built on Polymarket CLOB Client
- Trader analytics powered by Predictfolio
- Deployed on Polygon network
IMPORTANT: This software is provided for educational and research purposes only. Trading cryptocurrencies and prediction markets involves substantial risk of loss. The developers and contributors are not responsible for any financial losses incurred while using this bot. Always:
- Trade with funds you can afford to lose
- Understand the risks involved
- Test thoroughly before deploying real capital
- Monitor your bot's activity regularly
- Use appropriate risk management strategies
Support: For questions, issues, or contributions, please open an issue on GitHub or contact the maintainers.
contact: https://t.me/Rust0x_726