[ CONCURRENCY: MULTI-WALLET ] [ ENGINE: ORDER-AGGREGATION ]
Industrial-Grade Quantitative Execution Node
Engineered for Account Abstraction (AA) proxy routing, multi-wallet concurrency, and dynamic order aggregation.
In the high-frequency battlefield of Polymarket, top traders ("Smart Money") often execute via numerous micro-trades (snipes). Blind 1:1 mimicking leads to massive gas attrition and extreme slippage. Furthermore, Polymarket's updated API enforces an Account Abstraction-based Deposit Wallet flow, causing traditional EOA calls to be blocked with a maker address not allowed error.
Polymarket Mimic Trading Bot is not just a simple API wrapper. It is a fully-fledged automated execution node featuring state persistence, an order aggregator, a dynamic risk control engine, and full compatibility with Polymarket's new Relayer routing mechanism.
- Trade Aggregation Engine: Establishes an in-memory time-window (e.g., 5 seconds) to aggregate fragmented snipes on the same market/outcome within a price threshold into clean batch orders, avoiding rate limits and boosting execution efficiency.
- Dynamic Risk & Precision Scaling: A fine-grained JSON strategy matrix that dynamically calculates execution size based on your capital ratio, automatically handles exchange-specific Tick Size requirements, and enforces strict slippage caps.
- AA Proxy Routing (Deposit Wallet Flow): Natively implements the
POLY_1271signature protocol and Relayer interaction logic. Strict validation mechanisms ensure the runtime mode, on-chain contract state, and environment variables are perfectly aligned to prevent asset loss. - State Machine & Resilience: The entire lifecycle (positions, order metadata, execution history) is persisted in real-time to MongoDB. Built-in network retry mechanisms utilize Exponential Backoff algorithms to handle RPC jitters.
- Continuous Monitoring: Polls the target addresses' activity stream via the Polymarket Data API.
- Aggregation & Cleansing: Merges high-frequency noise within a time window into executable batch orders.
- Risk Control & Scaling: Calculates the true order size dynamically based on account balance and the strategy matrix.
- Routing & Validation: Switches underlying signature logic automatically based on
WALLET_MODE, broadcasting orders via Relayer or native RPC. - Persistence: Logs the full state lifecycle to MongoDB for seamless recovery.
- Node.js v18+
- MongoDB database (MongoDB Atlas recommended)
- Polygon wallet funded with USDC and POL/MATIC for Gas
- Polygon RPC endpoint (e.g., Infura, Alchemy)
# Clone the repository
git clone https://github.com/ChiryanOY/MimicPolymarket.git
cd MimicPolymarket
# Install dependencies
npm install
# Initialize configuration
cp .env.docker.example .env
# (Recommended) Run the interactive setup wizard
# npm run setup
# If your account requires the Deposit Wallet flow, run:
# npm run setup-deposit-wallet
# Build and run health checks
npm run build
npm run health-check
# Spin up the execution engine
npm startThe runtime environment relies on the .env file (see /.env.docker.example).
USER_ADDRESSES: Target wallets to monitor (comma-separated).TRADING_WALLET: The execution address (EOA/Safe forLEGACY; derived Deposit Wallet forDEPOSIT).WALLET_MODE: Routing mode (LEGACYorDEPOSIT).PRIVATE_KEY: Private key of the Owner or Signer.CLOB_HTTP_URL/CLOB_WS_URL: Polymarket API endpoints.MONGO_URI: MongoDB state machine connection string.RPC_URL/USDC_CONTRACT_ADDRESS: Polygon network configuration.
Designed for early EOA or Safe multi-sig direct signature calls. The engine strictly validates whether the TRADING_WALLET matches the Signer derived from the PRIVATE_KEY.
Required when Polymarket intercepts calls with maker address not allowed, please use the deposit wallet flow.
- Configure Relayer credentials like
POLY_BUILDER_API_KEY. - Run
npm run setup-deposit-walletto dynamically derive the Deposit Wallet, and set it asTRADING_WALLET. - The engine strictly verifies the on-chain contract deployment status of this address upon startup.
⚠️ Safety Interception: If theWALLET_MODEmismatches the on-chain reality, the engine throws a Fatal Error during initialization and halts to protect your funds.
Fine-grained control is achieved via TRADER_STRATEGIES, which must be a valid JSON string:
[
{
"address": "0xabc...",
"mimicSize": 1.0,
"maxOrderSizeUSD": 500,
"maxPositionSizeUSD": 2000,
"tradeAggregationEnabled": true,
"tradeAggregationWindowSeconds": 5
}
]The default strategy utilizes a PERCENTAGE based proportional scaling algorithm.
To ensure the quantitative execution is both efficient and highly secure, the bot employs two distinctly different risk-control pipelines for buying and selling. Here is a breakdown of the core mechanics:
When the engine detects a "Smart Money" buy operation, it triggers a rigorous sequence of conditional checks:
- Base Size Calculation: Computes the target token amount based on your configured
mimicSizepercentage:Trader Tokens * (mimicSize / 100). - Multi-Threshold Scaling:
- Max Order Size: If the calculated token value exceeds
maxOrderSizeUSD, it is strictly capped at this limit. - Max Position Size: The engine evaluates your current position cost plus the incoming order cost. If this exceeds
maxPositionSizeUSD, the order is trimmed to fit the remaining allowance. If the allowance translates to less than 5 tokens, the order is rejected. - Balance Protection: Checks your current USDC balance and caps the order at
99%of your available funds to preventINSUFFICIENT_BALANCEerrors due to minor price fluctuations or fees.
- Max Order Size: If the calculated token value exceeds
- Slippage & Limit Order Execution: It takes the trader's execution price and adds the configured
buySlippageThreshold. A strict Limit Order is then generated. This ensures that even during extreme market volatility, your entry cost will never exceed your safety threshold.
Selling usually indicates that "Smart Money" is taking profits or cutting losses. Therefore, execution priority and liquidity capturing are paramount. The engine adopts a "Clear & Market Snipe" strategy:
- Clear Pending Buy Orders: Before executing a sell, the engine actively cancels all your pending BUY orders for that specific asset to free up capital and avoid conflicting trades.
- Dynamic Proportional Selling:
- The system compares the trader's sell size against their historical position size to calculate the true Sell Percentage.
- It then multiplies your real CLOB token balance by this percentage to determine your sell amount. If the trader dumps their entire position (or if their historical position cannot be tracked), the engine will trigger a 100% full liquidation of your holdings.
- FOK (Fill-or-Kill) Execution:
- The engine fetches the real-time Order Book to locate the highest buyer (Best Bid).
- It subtracts your configured
sellSlippageThresholdto establish a safety floor price. - The order is then broadcasted using the FOK (Fill-or-Kill) order type. FOK ensures the order is either fully filled immediately or entirely canceled, preventing fragmented partial fills from hanging on the order book.
- In case of liquidity shifts causing FOK rejections or network issues, the engine triggers an exponential backoff retry mechanism (up to
RETRY_LIMIT), aggressively chasing liquidity until the position is cleared.
We provide an out-of-the-box docker-compose.yml to spin up both the Bot and a MongoDB instance with a single command, achieving a pure Local Daemon execution.
# Initialize environment
cp .env.docker.example .env
# We recommend setting this in .env: MONGO_URI='mongodb://mongodb:27017/polymarket_mimictrading'
# Start services
docker-compose up -d
# Tail engine logs
docker-compose logs -f bot- Analyze the Polymarket Leaderboard.
- Filter for traders with positive P&L, >55% win rate, and recent activity.
- Cross-validate deep stats using Predictfolio.
- Inject the selected addresses into
USER_ADDRESSESand let the engine take over.
ISC License - See LICENSE for details.
- Core dependencies built on Polymarket CLOB Client V2.
- Data analytics powered by Predictfolio.
Disclaimer: This software is provided strictly for technical research, code study, and educational purposes. It does not constitute financial or investment advice. Prediction markets carry extreme risks, and automated execution can result in the total loss of capital. The developers bear no responsibility for any financial losses. Deploy this system at your own risk only after fully understanding the source code logic.
