An automated trade mirroring system for Polymarket prediction markets. Monitors specified trader addresses and replicates their market positions with configurable sizing logic, risk controls, and optional order aggregation. Implemented in TypeScript using the official Polymarket CLOB client.
This system provides a modular architecture for trade replication on Polymarket. Core features include proportional position sizing relative to tracked traders, real-time activity polling with retry and backoff handling, and basic risk guards such as minimum order size and slippage constraints. The codebase is organized for extension and integration with container orchestration and cloud environments.
- Monitor: Periodic polling of Polymarket activity for configured trader addresses.
- Detect: On new buy or sell activity, a trade signal is generated with market, outcome, price, and size.
- Size: Proportional USD allocation is computed from your balance and configured multiplier.
- Execute: Market orders are submitted through the Polymarket CLOB client.
- Track: Optional persistence of fills and PnL for reporting and proportional exit logic.
This repository provides a compile-ready scaffold. Real activity sources and order submission must be wired at the indicated integration points.
- Language: TypeScript (strict mode)
- Runtime: Node.js 18+
- Trading API:
@polymarket/clob-client - Blockchain:
ethersfor wallet and provider - HTTP/Data:
axios - Logging:
chalk,ora - Optional Storage:
mongoose(MongoDB) - Tooling: ESLint, Prettier, Docker
| Path | Purpose |
|---|---|
config/env.ts |
Environment loading and validation |
config/copyStrategy.ts |
Proportional sizing configuration |
services/createClobClient.ts |
Polymarket client factory |
services/tradeMonitor.ts |
Polling loop and signal generation |
services/tradeExecutor.ts |
Sizing and order submission |
utils/logger.ts |
Structured logging |
utils/fetchData.ts, postOrder.ts, getMyBalance.ts, spinner.ts |
Shared helpers |
- Node.js 18 or newer
- Polygon wallet with USDC and POL/MATIC for gas
- MongoDB (optional, for persistent history)
git clone https://github.com/your-org/polymarket-copy-trading-bot.git
cd polymarket-copy-trading-bot
npm installCreate an .env file in the project root:
USER_ADDRESSES='0xabc...,0xdef...'
PROXY_WALLET='0xyour_wallet'
PRIVATE_KEY='your_private_key_no_0x'
RPC_URL='https://polygon-mainnet.infura.io/v3/YOUR_PROJECT_ID'
FETCH_INTERVAL=1
TRADE_MULTIPLIER=1.0
RETRY_LIMIT=3
TRADE_AGGREGATION_ENABLED=false
TRADE_AGGREGATION_WINDOW_SECONDS=300npm run build
npm start| Command | Description |
|---|---|
npm run dev |
Run in development mode (ts-node) |
npm run start |
Run compiled build |
npm run check-allowance |
Allowance utility (scaffold) |
npm run simulate |
Simulation placeholder |
| Variable | Description | Example |
|---|---|---|
USER_ADDRESSES |
Trader addresses to monitor (comma or JSON) | "0xabc...,0xdef..." |
PROXY_WALLET |
Polygon wallet address | "0x123..." |
PRIVATE_KEY |
Private key (no 0x prefix) | "abcd..." |
RPC_URL |
Polygon RPC endpoint | "https://polygon-mainnet.infura.io/v3/..." |
FETCH_INTERVAL |
Poll interval (seconds) | 1 |
TRADE_MULTIPLIER |
Position size multiplier | 2.0 |
RETRY_LIMIT |
Max retries on failure | 3 |
TRADE_AGGREGATION_ENABLED |
Aggregate small buys | true |
TRADE_AGGREGATION_WINDOW_SECONDS |
Aggregation window (seconds) | 300 |
- Local:
npm run build && npm start - Docker:
docker build -t polymarket-replication-engine . && docker run --env-file .env polymarket-replication-engine - Docker Compose:
docker-compose up -d
Pass configuration via .env or your deployment platform.
- Full integration with Polymarket activity feeds
- Order routing with price limits and minimum size checks
- MongoDB-backed position and PnL tracking
- Simulation and backtesting utilities
- Web-based monitoring dashboard
This software is provided for educational and informational purposes only. Do not run this project in production or with real funds. Trading prediction markets involves substantial risk of loss. Past performance does not indicate future results. The authors and contributors assume no liability for any financial losses or damages arising from the use of this software. Use at your own risk.