Back to Search
dexorynlabs

dexorynlabs/polymarket-trading-bot-ts

polymarket bot polymarket bot polymarket bot polymarket bot polymarket bot polymarket bot polymarket bot polymarket bot

380stars
367forks
380watchers
MIT License
Updated 1/20/2026

README.md

πŸ‹ Polymarket Trading Bot (Copy Trading)

πŸ“¬ Contact

For the latest, more effective version of the bot or help running it, please contact the links above.

Advanced Polymarket trading bot for copy trading in prediction markets. Monitors whale wallets and copies their trades with intelligent position sizing, adaptive take-profit, and trailing stop-loss protection.

SEO keywords: polymarket bot, polymarket trading bot, polymarket copy trading bot, prediction market bot

✨ Features

Core Trading

  • 🎯 Smart Copy Trading β€” Real-time monitoring of whale wallets with instant trade replication
  • πŸ“Š Proportional Sizing β€” Automatically scales trade sizes based on your balance vs whale's
  • πŸ”„ Position Limits β€” Configurable max buys per token to prevent overexposure
  • ⏱️ Cooldown System β€” Prevents rapid rebuying of the same position
  • ⏸️ Auto-Pause β€” Stops buying when balance drops below minimum stake

Advanced Take-Profit System

  • πŸ“ˆ Adaptive Trailing Stop β€” Dynamic stop-loss that tracks peak prices
    • Default: 15% trailing stop from peak
    • Sports markets: 25% trailing stop (higher volatility tolerance)
  • πŸ’° Profit Triggers β€” Automatically activates at +15% profit
  • πŸ”„ Smart Order Updates β€” Repositions orders as market moves up
  • 🚨 Emergency Exit β€” Aggressive market sells when stop-loss triggered
  • πŸ’Ύ State Persistence β€” Saves tracking state for recovery after restart
  • ⚑ Fast Monitoring β€” 3-second checks for volatile markets

Risk Management

  • πŸ›‘οΈ Position-Based Stops β€” Protects profits without closing at a loss
  • πŸ“‰ Stop-Loss Protection β€” Configurable stop-loss percentage (can be disabled)
  • πŸ€ Sports Market Detection β€” Wider stops for high-volatility sports markets
  • πŸ”’ Decimal Precision β€” Proper rounding for API compliance (SELL: 2 decimals, BUY: 4 decimals)

Session Tracking

  • πŸ“Š Real-Time P&L β€” Live session profit/loss tracking
  • πŸ† Win/Loss Stats β€” Track winning and losing trades
  • πŸ’΅ Balance Monitoring β€” Real-time USDC and position value display

πŸš€ Quick Start

# Install dependencies
npm install

# Setup environment
cp env.example .env
# Edit .env with your private key and wallet address

# Configure tracking (edit config.json)
# Add whale wallets, adjust stake sizes, set limits
cp config.example.json config.json

# Build and run
npm run build
npm run bot

βš™οΈ Configuration

Environment Variables (.env)

PRIVATE_KEY=0xYourPrivateKey        # MetaMask/Wallet private key
FUNDER_ADDRESS=0xYourTradingWallet  # Polymarket wallet address
TAKE_PROFIT_PERCENT=15              # Profit trigger threshold (%)
DEBUG=false                         # Enable verbose logging

Trading Settings (config.json)

{
  "wallets_to_track": [
    "0x33f6d97080e5215eb2cf679531496ace0330e0de"
  ],
  "mode": "proportional",           // Sizing mode
  "min_stake": 7,                   // Minimum trade size (USDC)
  "max_stake": 300,                 // Maximum trade size (USDC)
  "max_buys_per_token": 3,          // Max positions per token
  "cooldown_minutes": 30,           // Rebuy cooldown period
  "stop_loss_percent": 15,          // Trailing stop % (default)
  "stop_loss_enabled": true,        // Enable/disable stop-loss
  "skip_sports": false              // Skip sports markets
}

Configuration Parameters

ParameterDefaultDescription
min_stake7Minimum trade size in USDC
max_stake300Maximum trade size in USDC
max_buys_per_token3Max number of buys for same token
cooldown_minutes30Minutes before allowing rebuy
stop_loss_percent15Trailing stop % from peak (default markets)
stop_loss_enabledtrueEnable automatic stop-loss exits
skip_sportsfalseSkip sports markets entirely

Note: Sports markets automatically use 25% trailing stop regardless of stop_loss_percent setting.

πŸ“– How It Works

Trading Flow

  1. Monitor β€” Bot polls tracked wallets every 5 seconds for new trades
  2. Analyze β€” Validates trade against position limits and cooldown rules
  3. Size β€” Calculates proportional stake based on balance ratio
  4. Execute β€” Places market order matching whale's side (BUY/SELL)
  5. Track β€” Monitors position for take-profit opportunities
  6. Exit β€” Automatically sells when profit target or stop-loss triggers

Take-Profit Logic

1. Position reaches +15% profit β†’ Start tracking
2. Price continues up β†’ Update trailing stop to track new peaks
3. If price drops 15% from peak β†’ Trigger stop-loss
4. Place limit order 2% below current price
5. If order not filled β†’ Update price or emergency exit

Position Management

  • Multiple Buys: Bot can buy same token up to 3 times (configurable)
  • Cooldown Protection: 30-minute cooldown prevents rapid rebuying
  • Per-Wallet Tracking: Sells only match specific wallet's position
  • State Persistence: Tracking survives bot restarts

πŸ” Finding Whale Wallets

Top Traders

Tips

  • Look for consistent profit over volume
  • Track multiple whales for diversification
  • Monitor their sports vs politics preferences
  • Check average position sizes vs your budget

πŸ“œ Commands

CommandDescription
npm run botStart the trading bot
npm run balanceCheck wallet balance and positions
npm run buildCompile TypeScript to JavaScript
npm run devDevelopment mode with hot reload
npm run cleanRemove compiled files

πŸ—οΈ Architecture

src/
β”œβ”€β”€ main.ts           # CLI entry point
β”œβ”€β”€ bot.ts            # Main bot orchestrator
β”œβ”€β”€ watcher.ts        # Wallet monitoring
β”œβ”€β”€ trader.ts         # Trade execution (CLOB API)
β”œβ”€β”€ executor.ts       # Position management
β”œβ”€β”€ take-profit.ts    # Adaptive take-profit system
β”œβ”€β”€ sizing.ts         # Proportional sizing logic
β”œβ”€β”€ risk.ts           # Risk management rules
β”œβ”€β”€ pnl-tracker.ts    # P&L and stats tracking
β”œβ”€β”€ wallet.ts         # Wallet and balance management
β”œβ”€β”€ api.ts            # Polymarket REST API
└── config.ts         # Configuration loading

πŸ“‹ Requirements

  • Node.js 18+ (with ESM support)
  • Polymarket Account with USDC funded
  • MetaMask Wallet linked to Polymarket
  • Private Key exported from MetaMask

πŸ› Troubleshooting

Common Issues

"Order failed: invalid amounts"

  • Fixed in latest version with proper decimal rounding
  • Rebuild: npm run build

"Not enough balance"

  • Check balance: npm run balance
  • Deposit more USDC to Polymarket
  • Lower min_stake in config.json

"Position likely closed"

  • Take-profit already executed by smart contract
  • Position was manually closed on Polymarket
  • Bot will auto-cleanup tracking

"502/503 CLOB errors"

  • Automatic retry logic handles temporary API issues
  • If persistent, check Polymarket API status

⚠️ Risk Warning

This bot is for educational purposes. Trading prediction markets involves substantial risk of loss.

  • Start with small stakes to test
  • Never trade more than you can afford to lose
  • Whale wallets can be wrong
  • Markets can gap against you
  • API issues can prevent exits
  • Test thoroughly before scaling up

πŸ“„ License

MIT License - see LICENSE file for details

🀝 Contributing

Issues and pull requests welcome! Please test thoroughly before submitting.

πŸ’‘ Tips

  • Start with min_stake: 7 and max_stake: 50 until comfortable
  • Enable stop-loss initially: stop_loss_enabled: true
  • Track 2-3 whales maximum to start
  • Monitor first few days closely
  • Keep at least 2x max_stake in balance for opportunities
  • Sports markets are more volatile β€” use with caution

πŸ“ˆ Roadmap

  • Web dashboard for monitoring
  • Multi-wallet support (multiple trading accounts)
  • Advanced analytics and backtesting
  • Discord/Telegram notifications
  • Custom strategy scripts
  • Paper trading mode

Built with TypeScript + Polymarket CLOB API