polymarket-copy-trading-bot

TypeScript bot that monitors a Polymarket wallet and mirrors BUY trades to your own account via the Polymarket CLOB API on Polygon.

22 stars

Best use case

polymarket-copy-trading-bot is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

TypeScript bot that monitors a Polymarket wallet and mirrors BUY trades to your own account via the Polymarket CLOB API on Polygon.

Teams using polymarket-copy-trading-bot should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/polymarket-copy-trading-bot/SKILL.md --create-dirs "https://raw.githubusercontent.com/Aradotso/trending-skills/main/skills/polymarket-copy-trading-bot/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/polymarket-copy-trading-bot/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How polymarket-copy-trading-bot Compares

Feature / Agentpolymarket-copy-trading-botStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

TypeScript bot that monitors a Polymarket wallet and mirrors BUY trades to your own account via the Polymarket CLOB API on Polygon.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Polymarket Copy Trading Bot

> Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection.

A TypeScript bot that continuously monitors a target Polymarket wallet, detects trades in real time via REST polling and/or WebSocket, and mirrors BUY orders to your own account using the Polymarket CLOB SDK on Polygon mainnet.

---

## What It Does

- **Monitors** a target wallet via Polymarket Data API (REST polling every ~2s) and optionally WebSocket
- **Mirrors BUY trades only** — SELL trades are detected but skipped by default
- **Sizes copies** using a configurable `POSITION_MULTIPLIER` (default 10%) with min/max caps
- **Submits orders** as FOK, FAK, or LIMIT via the Polymarket CLOB client
- **Enforces risk limits** — per-session and per-market notional caps
- **Supports three auth modes** — EOA (`SIG_TYPE=0`), Poly Proxy (`SIG_TYPE=1`), Poly Polymorphic (`SIG_TYPE=2`)

---

## Installation

```bash
git clone https://github.com/Neron888/Polymarket-copy-trading-bot.git
cd Polymarket-copy-trading-bot
npm install
```

Requires Node.js v18+. The CLOB SDK requires **ethers v5** (already pinned in `package.json`).

---

## Configuration

```bash
cp .env.example .env
```

Edit `.env`:

```env
# Required
TARGET_WALLET=0xTargetWalletAddressToMonitor
WALLET_PRIVATE_KEY=0xYourPrivateKey
RPC_URL=https://your-quicknode-polygon-endpoint.quiknode.pro/your-key/

# Auth mode (0=EOA default, 1=Poly Proxy, 2=Poly Polymorphic)
SIG_TYPE=0
# Required only for SIG_TYPE=1 or 2
PROXY_WALLET_ADDRESS=

# Sizing
POSITION_MULTIPLIER=0.1      # 10% of target's trade size
MAX_TRADE_SIZE=100            # Max USDC per copied trade
MIN_TRADE_SIZE=1              # Min USDC per copied trade

# Order behavior
ORDER_TYPE=FOK                # FOK | FAK | LIMIT
SLIPPAGE_TOLERANCE=0.02       # 2%

# Risk caps (0 = disabled)
MAX_SESSION_NOTIONAL=500      # Total USDC for entire session
MAX_PER_MARKET_NOTIONAL=100   # Per market USDC cap

# Monitoring
USE_WEBSOCKET=true
POLL_INTERVAL=2000            # ms between REST polls
USE_USER_CHANNEL=false        # true = user WS channel, false = market channel

# Optional
POLYMARKET_GEO_TOKEN=
WS_ASSET_IDS=                 # comma-separated asset IDs for market WS
WS_MARKET_IDS=                # comma-separated condition IDs for user channel
MIN_PRIORITY_FEE_GWEI=30
MIN_MAX_FEE_GWEI=60
```

---

## Key Commands

```bash
# Start the bot (development mode with ts-node)
npm start

# Generate and persist API credentials to .polymarket-api-creds
npm run generate-api-creds

# Validate existing API credentials
npm run test-api-creds

# Compile TypeScript to dist/
npm run build

# Run compiled production build
npm run start:prod
```

---

## Architecture Overview

```
index.ts
  └── TradeMonitor      — REST polls Polymarket Data API for new target trades
  └── WebSocketMonitor  — Optional low-latency WS subscription (market or user channel)
  └── TradeExecutor     — Sizes trade, checks balance/allowance, submits CLOB order
  └── PositionTracker   — In-memory positions updated on fills
  └── RiskManager       — Session + per-market notional enforcement
```

Execution flow:
```
detect trade → BUY? → subscribe WS if needed → compute copy size
  → risk check → execute order (FOK/FAK/LIMIT) → record fill → update stats
```

---

## Code Examples

### Starting the bot programmatically

```typescript
import { startBot } from './src/index';

// The bot reads all config from process.env / .env
startBot();
```

### TradeMonitor — polling pattern

```typescript
import { TradeMonitor } from './src/TradeMonitor';

const monitor = new TradeMonitor({
  targetWallet: process.env.TARGET_WALLET!,
  pollInterval: Number(process.env.POLL_INTERVAL ?? 2000),
});

monitor.on('trade', (trade) => {
  console.log('New trade detected:', trade);
  // trade.side: 'BUY' | 'SELL'
  // trade.asset: token ID (outcome token address)
  // trade.size: USDC size
  // trade.price: fill price (0–1)
});

monitor.start();
```

### TradeExecutor — placing a copy order

```typescript
import { TradeExecutor } from './src/TradeExecutor';
import { ClobClient } from '@polymarket/clob-client';
import { ethers } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const signer = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY!, provider);

const clobClient = new ClobClient(
  'https://clob.polymarket.com',
  137, // Polygon chainId
  signer,
  apiCreds,          // loaded from .polymarket-api-creds
  Number(process.env.SIG_TYPE ?? 0),
  process.env.PROXY_WALLET_ADDRESS || undefined,
);

const executor = new TradeExecutor({
  client: clobClient,
  positionMultiplier: Number(process.env.POSITION_MULTIPLIER ?? 0.1),
  maxTradeSize: Number(process.env.MAX_TRADE_SIZE ?? 100),
  minTradeSize: Number(process.env.MIN_TRADE_SIZE ?? 1),
  orderType: (process.env.ORDER_TYPE ?? 'FOK') as 'FOK' | 'FAK' | 'LIMIT',
  slippageTolerance: Number(process.env.SLIPPAGE_TOLERANCE ?? 0.02),
});

// Copy a detected trade
await executor.copyTrade({
  side: 'BUY',
  tokenId: '0xAssetId...',
  originalSize: 12.5,   // USDC from target's trade
  price: 0.62,
});
```

### RiskManager — checking before execution

```typescript
import { RiskManager } from './src/RiskManager';

const riskManager = new RiskManager({
  maxSessionNotional: Number(process.env.MAX_SESSION_NOTIONAL ?? 0),
  maxPerMarketNotional: Number(process.env.MAX_PER_MARKET_NOTIONAL ?? 0),
});

const allowed = riskManager.checkTrade({
  marketId: '0xConditionId...',
  notional: copySize,
});

if (!allowed) {
  console.log('Trade blocked by risk limits');
}
```

### WebSocket monitor — low-latency subscription

```typescript
import { WebSocketMonitor } from './src/WebSocketMonitor';

const wsMonitor = new WebSocketMonitor({
  useUserChannel: process.env.USE_USER_CHANNEL === 'true',
  assetIds: process.env.WS_ASSET_IDS?.split(',').filter(Boolean) ?? [],
  marketIds: process.env.WS_MARKET_IDS?.split(',').filter(Boolean) ?? [],
});

wsMonitor.on('orderFilled', (fill) => {
  console.log('Fill received via WS:', fill);
});

wsMonitor.connect();
```

---

## Authentication Modes

### EOA (default — `SIG_TYPE=0`)

```env
SIG_TYPE=0
WALLET_PRIVATE_KEY=0xYourKey
# PROXY_WALLET_ADDRESS — leave empty
```

On first run, the bot auto-submits USDC.e/CTF approval transactions. Wallet needs POL for gas.

### Poly Proxy (`SIG_TYPE=1`)

```env
SIG_TYPE=1
WALLET_PRIVATE_KEY=0xSignerKey
PROXY_WALLET_ADDRESS=0xYourPolymarketProxyAddress
```

### Poly Polymorphic (`SIG_TYPE=2`)

```env
SIG_TYPE=2
WALLET_PRIVATE_KEY=0xSignerKey
PROXY_WALLET_ADDRESS=0xYourPolymorphicSafeAddress
```

---

## Generating API Credentials

```bash
npm run generate-api-creds
```

This derives API keys from your wallet signature and writes them to `.polymarket-api-creds`. Run once before `npm start` if you want to pre-generate credentials. The bot also auto-generates them on first start in EOA mode.

Validate credentials:

```bash
npm run test-api-creds
```

---

## Common Patterns

### Conservative testing setup

```env
POSITION_MULTIPLIER=0.05
MAX_TRADE_SIZE=5
MIN_TRADE_SIZE=1
MAX_SESSION_NOTIONAL=20
ORDER_TYPE=FOK
USE_WEBSOCKET=false
```

### WebSocket-only market channel (lower latency)

```env
USE_WEBSOCKET=true
USE_USER_CHANNEL=false
WS_ASSET_IDS=0xTokenId1,0xTokenId2
```

### LIMIT orders with slippage buffer

```env
ORDER_TYPE=LIMIT
SLIPPAGE_TOLERANCE=0.03
```

---

## Troubleshooting

**Bot starts but no trades detected**
- Verify `TARGET_WALLET` is a valid Polymarket wallet with recent activity
- Check `POLL_INTERVAL` — default 2000ms; lower means more API calls
- Confirm the target wallet trades on Polymarket (not just holds positions)

**`ethers` version conflicts**
- The project pins ethers v5. Do not upgrade to v6 — the CLOB SDK requires v5
- Run `npm ls ethers` to check for duplicate versions

**Approval transactions failing**
- Ensure the wallet has sufficient POL (MATIC) for gas on Polygon mainnet
- Try increasing `MIN_PRIORITY_FEE_GWEI` and `MIN_MAX_FEE_GWEI` if transactions stall

**`generate-api-creds` fails**
- Confirm `WALLET_PRIVATE_KEY` is correct and 0x-prefixed
- For `SIG_TYPE=1/2`, ensure `PROXY_WALLET_ADDRESS` matches your Polymarket account

**Orders rejected by CLOB**
- FOK orders fail if insufficient liquidity — try `ORDER_TYPE=FAK` or `LIMIT`
- Check `SLIPPAGE_TOLERANCE` isn't too tight for illiquid markets

**Session notional cap hit immediately**
- `MAX_SESSION_NOTIONAL` resets per process run; restart the bot to reset
- Set `MAX_SESSION_NOTIONAL=0` to disable the cap entirely

---

## Wallet Requirements

- **USDC.e** on Polygon mainnet (collateral for trades)
- **POL** (formerly MATIC) for gas fees
- Approve USDC.e for Polymarket CTF Exchange and CLOB contracts (bot does this automatically on first EOA run)

---

## References

- [QuickNode Guide — Building a Polymarket Copy Trading Bot](https://www.quicknode.com/guides/defi/polymarket-copy-trading-bot)
- [Polymarket CLOB Client SDK](https://github.com/Polymarket/clob-client)
- [Polymarket](https://polymarket.com/)
- [Polymarket CLOB API Docs](https://docs.polymarket.com/)

Related Skills

polymarket-arbitrage-trading-bot

22
from Aradotso/trending-skills

Automated dump-and-hedge arbitrage trading bot for Polymarket's 15-minute crypto Up/Down markets, supporting BTC, ETH, SOL, and XRP.

polymarket-arbitrage-bot

22
from Aradotso/trending-skills

TypeScript bot implementing dump-and-hedge arbitrage strategy on Polymarket 15-minute Up/Down prediction markets with CLOB order execution and simulation mode.

nothing-ever-happens-polymarket-bot

22
from Aradotso/trending-skills

Async Python bot for Polymarket that buys "No" on all standalone non-sports yes/no markets using the "nothing ever happens" strategy.

hyperliquid-trading-bot

22
from Aradotso/trending-skills

Configurable grid trading bot for Hyperliquid DEX with TypeScript/Node.js primary implementation, supporting perpetuals and spot markets with risk management features.

hyperliquid-grid-trading-bot

22
from Aradotso/trending-skills

Configure and run an automated grid trading bot on Hyperliquid DEX with TypeScript/Node.js, supporting perpetuals and spot markets with risk management.

cve-2026-31431-copy-fail

22
from Aradotso/trending-skills

Detector and proof-of-concept LPE toolkit for CVE-2026-31431 ("Copy Fail"), a Linux kernel algif_aead page-cache scratch-write vulnerability enabling local privilege escalation.

copyfail-go-lpe

22
from Aradotso/trending-skills

Go implementation of CVE-2026-31431 (CopyFail), a Linux local privilege escalation exploit targeting the AF_ALG iov_iter kernel vulnerability affecting kernels v4.14–April 2026.

aster-bot-trading

22
from Aradotso/trending-skills

Automated perpetual futures trading bot for AsterDEX with dual strategies, risk management, and TypeScript/Node.js stack

```markdown

22
from Aradotso/trending-skills

---

zeroboot-vm-sandbox

22
from Aradotso/trending-skills

Sub-millisecond VM sandboxes for AI agents using copy-on-write KVM forking via Zeroboot

yourvpndead-vpn-detection

22
from Aradotso/trending-skills

Android app that detects VPN/proxy servers (VLESS/xray/sing-box) via local SOCKS5 vulnerability, exposing exit IPs and server configs without root

xata-postgres-platform

22
from Aradotso/trending-skills

Expert skill for Xata open-source cloud-native Postgres platform with copy-on-write branching, scale-to-zero, and Kubernetes deployment