Automated trading bot for Polymarket with copy trading and frontrunning capabilities
- Copy Trading - Automatically mirror trades from successful traders
- Frontrunning - Execute trades before target transactions with priority gas
- Mempool Monitoring - Real-time detection of pending transactions
- Risk Management - Position tracking, slippage protection, exposure limits
- Performance Optimized - Parallel processing, connection pooling, smart caching
- Production Ready - Health monitoring, MongoDB persistence, graceful shutdown
src/
├── app/ # Application entry point
├── cli/ # CLI commands
├── config/ # Configuration management
├── core/ # Core constants, types, errors
├── domain/ # Domain models and types
├── infrastructure/ # External services (MongoDB, CLOB client)
├── services/ # Business logic services
└── utils/ # Utility functions
- Monitor target addresses via Polymarket API
- Detect new trades in real-time
- Validate trade (size, limits, balance)
- Execute proportional trade
- Track position
- Monitor Polygon mempool for pending transactions
- Poll Polymarket API for recent trades
- Extract trade details and gas price from pending transaction
- Calculate frontrun gas:
target_gas × multiplier - Execute with priority gas price
- Track position
| Command | Description |
|---|---|
npm run dev |
Run in development mode |
npm run build |
Compile TypeScript |
npm start |
Run compiled code |
npm run lint |
Run linter |
npm run check-allowance |
Check USDC allowance |
npm run set-token-allowance |
Set token allowance |
npm run manual-sell |
Manually sell positions |
# Install dependencies
npm install
# Configure environment
cp .env.example .env # Edit with your settings
# Run in development
npm run dev
# Or build and run in production
npm run build && npm startCreate a .env file with these required settings:
# Required
TARGET_ADDRESSES=0xabc...,0xdef... # Trader addresses to follow
PUBLIC_KEY=your_wallet_address # Your Polygon wallet
PRIVATE_KEY=your_private_key # Your wallet private key
RPC_URL=https://polygon-rpc-endpoint # Polygon RPC URL
# Optional
MONGO_URI=mongodb://localhost:27017/polymarket-bot
HEALTH_CHECK_PORT=3000
MIN_TRADE_SIZE_USD=100
FRONTRUN_SIZE_MULTIPLIER=0.5
GAS_PRICE_MULTIPLIER=1.2
MAX_SLIPPAGE_PERCENT=2.0The bot exposes HTTP endpoints for monitoring:
# Health check
curl http://localhost:3000/health
# Detailed metrics
curl http://localhost:3000/metricsMetrics include:
- Uptime
- Trades executed/failed
- Wallet balances (POL/USDC)
- Error history
- Health status
# Build
docker build -t polymarket-bot .
# Run
docker run --env-file .env -d --name polymarket-bot polymarket-bot
# View logs
docker logs -f polymarket-bot- Node.js 18+
- Polygon Wallet with USDC balance
- POL/MATIC for gas fees (recommended: 0.5+ POL)
- MongoDB (optional, for persistence)
- RPC Endpoint that supports pending transaction monitoring
- Parallel Processing - Multiple addresses monitored concurrently
- Connection Pooling - Optimized HTTP connections (50 max sockets)
- Smart Caching - Order book caching with automatic cleanup
- Batch Operations - Database batch writes for efficiency
- Rate Limiting - Burst-aware rate limiting with reservoirs
Bot not detecting trades:
- Verify
TARGET_ADDRESSESare correct - Check RPC URL supports pending transactions
- Ensure
MIN_TRADE_SIZE_USDthreshold isn't too high
Orders failing:
- Check USDC balance
- Verify POL balance for gas (>0.2 POL recommended)
- Confirm market is still active
High gas costs:
- Lower
GAS_PRICE_MULTIPLIER(e.g., 1.1 instead of 1.2) - Increase
MIN_TRADE_SIZE_USDto only frontrun larger trades
- Never commit
.envfile - Use environment variables for secrets
- Rotate private keys regularly
- Monitor balances for unusual activity
- Use minimum required wallet permissions
- Example Trade #1 - $0.1 on Market X
- Example Trade #2 - $0.06 on Market Y
This software is provided "as-is" for educational purposes only. Trading cryptocurrencies involves substantial risk. Use at your own risk. The authors are not responsible for any financial losses.
Apache License 2.0 - see LICENSE file for details.
Contributions welcome! Please feel free to submit a Pull Request.
If you have any questions or would like more strategies like arbitrage and farming bot, please feel free to contact us at the contact information below.
- E-Mail: admin@hyperbuildx.com
- Telegram: @0xAlche