This is a Rust Version for Polymarket Copy Trading Bot. It maintains all functionalities with high speed.
This Rust version requires a fully implemented Polymarket CLOB client. The TypeScript version uses the official @polymarket/clob-client package, but there is no official Rust equivalent. You will need to:
-
Implement the CLOB client - The
src/utils/create_clob_client.rsfile 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 Rust wrapper for the CLOB client (if available)
- Implement direct HTTP API calls to Polymarket CLOB endpoints
- Use a bridge service that calls the client
- Rust 1.70+ (stable or nightly)
- Cargo (comes with Rust)
- MongoDB (running and accessible)
- Ethereum wallet with private key
Windows:
# Run the installation helper
.\install_rust.ps1
# Or install manually from https://rustup.rs/Linux/Mac:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shrustc --version
cargo --versionWindows (PowerShell):
cd RustVersion
cargo buildLinux/Mac (Bash):
cd RustVersion
./install_dependencies.sh
# Or manually: cargo buildcreate 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.0RustVersion/
├── 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.rs # Entry point
├── logs/ # Log files (created automatically)
├── Cargo.toml # Rust project configuration
└── README.md # This file
Before running, ensure:
- MongoDB is running and accessible
- CLOB client is fully implemented (see
src/utils/create_clob_client.rs) - All environment variables are set correctly
Run the bot:
Windows:
.\run.batLinux/Mac:
./run.shOr directly with Cargo:
cargo run --release✅ Fully implemented:
- Trade monitoring and execution
- Copy strategy system (PERCENTAGE, FIXED, ADAPTIVE)
- Tiered multipliers
- Trade aggregation
- Position tracking
- Comprehensive logging
- Health checks
- Graceful shutdown
✅ Same logic and results:
- Identical trade detection
- Same order size calculations
- Same position management
- Same error handling
- CLOB Client: Requires manual implementation (see above)
- Async Runtime: Uses
tokioinstead of Promise-based async - Type System: Uses Rust's strong type system with ownership
- MongoDB: Uses
mongodbcrate instead ofmongoose - Ethereum: Uses
ethers-rsorweb3crate instead ofethers.js - Error Handling: Uses
Result<T, E>andanyhow/thiserrorfor error handling - Memory Safety: Rust's ownership system ensures memory safety
- ✅ Project structure
- ✅ Cargo configuration
⚠️ Configuration system (needs implementation)⚠️ Database models and connection (needs implementation)⚠️ Logger utility (needs implementation)⚠️ Trade monitoring service (needs implementation)⚠️ Trade executor service (needs implementation)⚠️ Copy strategy calculations (needs implementation)⚠️ Health checks (needs implementation)⚠️ Error handling (needs implementation)⚠️ CLOB client (needs implementation)⚠️ Order signing (needs implementation)
-
Implement Core Modules:
- Configuration loading from
.env - MongoDB connection and models
- Logger with colored output
- Error types and handling
- Configuration loading from
-
Implement CLOB Client:
- Study the TypeScript
@polymarket/clob-clientpackage - Implement HTTP API calls to Polymarket CLOB endpoints
- Implement order signing using
ethers-rsor similar - Test with small orders first
- Study the TypeScript
-
Implement Services:
- Trade monitoring service
- Trade executor service
- Copy strategy calculations
- Health checks
-
Testing:
- Unit tests for each module
- Integration tests
- Verify calculations
-
Production Readiness:
- Add comprehensive error handling
- Add retry logic for API calls
- Add monitoring and alerts
- Performance optimization
Debug build:
cargo buildRelease build (optimized):
cargo build --releaseRun tests:
cargo testRust offers significant performance advantages:
- Zero-cost abstractions: No runtime overhead
- Memory safety: No garbage collection pauses
- Concurrency: Excellent async/await support with tokio
- Compile-time checks: Catches errors before runtime
For issues or questions:
- Check the documentation
- Review the Polymarket CLOB API documentation
- Check the code comments for implementation hints
- Refer to Rust documentation: https://doc.rust-lang.org/