A production-ready, enterprise-grade Python implementation of the Polymarket Copy Trading Bot. This independent implementation is designed from the ground up to leverage Python's strengths for trading automation, data analysis, and system integration.
This Python implementation requires a fully implemented Polymarket CLOB client. There is no official Python CLOB client package available. You will need to:
-
Implement the CLOB client - The
src/utils/create_clob_client.pyfile contains a placeholder structure. You need to implement:get_order_book(asset)- Fetch order book from Polymarket CLOB APIcreate_market_order(order_args)- Create and sign orders using your Ethereum walletpost_order(signed_order, order_type)- Submit orders to Polymarket CLOB API- API key creation/derivation
-
Alternative approaches:
- Use a Python wrapper for existing CLOB clients (if available)
- Implement direct HTTP API calls to Polymarket CLOB endpoints
- Use a bridge service that interfaces with CLOB APIs
PythonVersion/
├── src/
│ ├── config/ # Configuration (env, copy strategy, database)
│ ├── interfaces/ # Type definitions
│ ├── models/ # MongoDB models
│ ├── services/ # Core services (trade monitor, executor)
│ ├── utils/ # Utilities (logger, fetch data, etc.)
│ └── main.py # Entry point
├── logs/ # Log files (created automatically)
├── requirements.txt # Python dependencies
└── README.md # This file
-
Install Python 3.9+
-
Install dependencies:
pip install -r requirements.txt
-
Create
.envfile (use the example below or create new):USER_ADDRESSES=0x... # Comma-separated trader addresses PROXY_WALLET=0x... # Your wallet address PRIVATE_KEY=0x... # Your private key CLOB_HTTP_URL=https://clob.polymarket.com/ CLOB_WS_URL=wss://ws-subscriptions-clob.polymarket.com/ws MONGO_URI=mongodb://... RPC_URL=https://polygon-rpc.com USDC_CONTRACT_ADDRESS=0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174 FETCH_INTERVAL=1 TOO_OLD_TIMESTAMP=24 RETRY_LIMIT=3 COPY_STRATEGY=PERCENTAGE COPY_SIZE=10.0 MAX_ORDER_SIZE_USD=100.0 MIN_ORDER_SIZE_USD=1.0
Before running, ensure:
- MongoDB is running and accessible
- CLOB client is fully implemented (see
src/utils/create_clob_client.py) - All environment variables are set correctly
Run the bot:
python -m src.main✅ Complete Feature Set:
- Trade monitoring and execution
- Copy strategy system (PERCENTAGE, FIXED, ADAPTIVE)
- Tiered multipliers
- Trade aggregation
- Position tracking
- Comprehensive logging
- Health checks
- Graceful shutdown
✅ Production-Ready Implementation:
- Advanced trade detection algorithms
- Intelligent order size calculations
- Comprehensive position management
- Robust error handling and recovery
- Async Runtime: Python's native
asynciofor concurrent operations - Type System: Python type hints for type safety and IDE support
- MongoDB:
pymongofor database integration with async support - Ethereum:
web3.pyfor blockchain interactions - Logging:
coloramaandrichfor enhanced terminal output - HTTP:
httpxandrequestsfor API interactions
- ✅ Configuration system
- ✅ Database models and connection
- ✅ Logger utility
- ✅ Trade monitoring service
- ✅ Trade executor service
- ✅ Copy strategy calculations
- ✅ Health checks
- ✅ Error handling
⚠️ CLOB client (needs implementation)⚠️ Order signing (needs implementation)
-
Implement CLOB Client:
- Review the Polymarket CLOB API documentation
- Implement HTTP API calls to Polymarket CLOB endpoints
- Implement order signing using
eth_accountor similar - Test with small orders first
-
Testing:
- Test database connections
- Test trade monitoring
- Test order execution (once CLOB client is ready)
- Verify calculations and trade execution logic
-
Production Readiness:
- Comprehensive error handling (already implemented)
- Retry logic for API calls (already implemented)
- Add monitoring and alerts
- Performance optimization
For issues or questions:
- Review the Polymarket CLOB API documentation
- Check the code comments for implementation hints
- Review the main project README for general information
- Open an issue on GitHub for bugs or feature requests
ISC License - See LICENSE file for details