Skip to content

WSOL12/Polymarket-Copy-Trading-Bot

Repository files navigation

Polymarket Trade Replication Engine

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.

TypeScript Node.js Polymarket CLOB Docker ESLint Prettier

Overview

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.

System Flow

  1. Monitor: Periodic polling of Polymarket activity for configured trader addresses.
  2. Detect: On new buy or sell activity, a trade signal is generated with market, outcome, price, and size.
  3. Size: Proportional USD allocation is computed from your balance and configured multiplier.
  4. Execute: Market orders are submitted through the Polymarket CLOB client.
  5. 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.

Technology Stack

  • Language: TypeScript (strict mode)
  • Runtime: Node.js 18+
  • Trading API: @polymarket/clob-client
  • Blockchain: ethers for wallet and provider
  • HTTP/Data: axios
  • Logging: chalk, ora
  • Optional Storage: mongoose (MongoDB)
  • Tooling: ESLint, Prettier, Docker

Module Layout

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

Getting Started

Requirements

  • Node.js 18 or newer
  • Polygon wallet with USDC and POL/MATIC for gas
  • MongoDB (optional, for persistent history)

Installation

git clone https://github.com/your-org/polymarket-copy-trading-bot.git
cd polymarket-copy-trading-bot
npm install

Environment Configuration

Create 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=300

Build and Execution

npm run build
npm start

Available Scripts

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

Configuration

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

Deployment

  • 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.

Planned Development

  • 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

Disclaimer

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.

About

Automated copy trading bot for Polymarket prediction markets. Monitors specified traders and mirrors their positions with configurable sizing and risk controls. TypeScript, Node.js 18+

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors