Skip to content

Polymarket bot trading bot is a Polymarket trading bot designed to automatically copy the trading of top Polymarket traders across all active markets. This tool continuously monitors Polymarket trading activity, identifies high-performing wallets, and copies their trading strategies in real time.

Notifications You must be signed in to change notification settings

CryptomSol/polymarket-copy-trading-bot

Repository files navigation

Polymarket Trading Bot - CopyTrading Bot & Arbitrage Bot

Polymarket Trading Bot(Polymarket Copytrading & Polymarket Arbitrage bot) with full credential management, order execution, market analysis, and automated copytrading & arbitrage trading capabilities.

Contact

If you have any question or need help, contact here: Telegram | Twitter

Features

  • πŸ” Credential Management: Secure private key handling and API authentication
  • πŸ’° Allowance Control: Manage USDC token allowances for trading
  • πŸ“Š Market Analysis: Real-time bid/ask spreads and price data
  • 🎯 Order Execution: Place market and limit orders
  • πŸ” Market Discovery: Auto-detect current Bitcoin markets
  • πŸ“ˆ Price Tracking: Get real-time price updates from order books
  • πŸ€– Auto Trading Bot: Automated arbitrage trading with risk management Screenshot

Screenshot

Two Modes of Operation

1. Manual Trading (Interactive CLI)

Use the interactive menu to manually place trades, check prices, and manage your account.

2. Automated Trading Bot

Fully automated bot that:

  • Monitors price differences between software oracle and market
  • Executes trades when profitable opportunities detected
  • Automatically sets take profit and stop loss orders
  • Manages risk with configurable parameters

Installation

# Install dependencies
npm install

# Create .env file
# Edit with your private key and configuration

Configuration

Edit .env file:

PRIVATE_KEY=your_private_key_here
CLOB_API_URL=https://clob.polymarket.com
POLYGON_CHAIN_ID=137

# Auto Trading Parameters
SOFTWARE_WS_URL=ws://172.16.52.93:5001
PRICE_DIFFERENCE_THRESHOLD=0.015
STOP_LOSS_AMOUNT=0.005
TAKE_PROFIT_AMOUNT=0.01
DEFAULT_TRADE_AMOUNT=5.0
TRADE_COOLDOWN=30

Usage

Generate CLOB Credentials (First Time Setup)

npm run gen-creds

Run Auto Trading Bot

npm run auto-trade

This starts the fully automated arbitrage trading bot that:

  1. Connects to Data Feeds:

    • Software price oracle (WebSocket) for real-time probability calculations
    • Polymarket market feed (WebSocket) for current market prices
  2. Monitors Price Differences:

    • Continuously compares software oracle prices vs. market prices
    • Detects when price difference exceeds threshold (default: $0.015)
  3. Executes Automated Trades:

    • Places market BUY order when opportunity detected
    • Sets take profit limit SELL order (+$0.01 above buy price)
    • Sets stop loss limit SELL order (-$0.005 below buy price)
    • Waits for cooldown period (default: 30 seconds) before next trade
  4. Risk Management:

    • Automatic stop loss protection
    • Take profit locking in gains
    • Configurable trade amounts and thresholds

What You'll See:

Starting Auto Trading Bot...
Wallet: 0xYourAddress...
Finding current Bitcoin market...
βœ… Market found: Bitcoin Up or Down - November 22, 9AM ET
βœ… Software WebSocket connected
βœ… Polymarket WebSocket connected
βœ… Bot started successfully!
Monitoring for trade opportunities...

🎯 Trade opportunity detected!
Software Price: $0.7500 | Market Price: $0.7300 | Difference: $0.0200
πŸ“Š Executing trade...
βœ… Buy order placed
βœ… Take Profit order placed at $0.7400
βœ… Stop Loss order placed at $0.7250
βœ… Trade execution complete!

Prerequisites:

  • Private key configured in .env
  • API credentials generated (npm run gen-creds)
  • Sufficient USDC balance (minimum $5, recommended $50+)
  • Sufficient MATIC for gas fees (minimum 0.05, recommended 0.5+)

To Stop: Press Ctrl+C to stop the bot gracefully.

See PROFIT_STRATEGY.md for detailed explanation of the trading logic and QUICK_START.md for step-by-step setup guide.

Run Manual Interactive Bot

npm run dev

Individual Scripts

# Check credentials
npm run credentials

# Check allowance
npm run allowance

# Find current Bitcoin market
npm run market

# Get bid/ask prices (requires token ID as argument)
npm run bid-ask <token_id>

# Place orders (interactive)
npm run order

Build for Production

# Compile TypeScript
npm run build

# Run compiled version
npm start

Project Structure

polymarket-ts-bot/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.ts                  # Interactive CLI trading interface
β”‚   β”œβ”€β”€ auto_trading_bot.ts      # Automated arbitrage bot
β”‚   β”œβ”€β”€ _gen_credential.ts       # Credential management
β”‚   β”œβ”€β”€ allowance.ts             # Token allowance management
β”‚   β”œβ”€β”€ bid_asker.ts             # Bid/ask price fetching
β”‚   β”œβ”€β”€ market_order.ts          # Order execution
β”‚   β”œβ”€β”€ market_finder.ts         # Market discovery
β”‚   └── generate_credentials.ts  # Credential generation utility
β”œβ”€β”€ .env                         # Environment variables (private)
β”œβ”€β”€ .credentials.json            # Generated API credentials
β”œβ”€β”€ package.json                 # Dependencies and scripts
β”œβ”€β”€ PROFIT_STRATEGY.md          # Detailed trading strategy guide
└── CREDENTIALS_GUIDE.md        # How to generate credentials

Auto Trading Bot Logic

The automated bot implements a price arbitrage strategy:

  1. Price Monitoring: Compares software oracle prices with Polymarket market prices
  2. Opportunity Detection: Triggers trade when price difference exceeds threshold
  3. Three-Order Execution:
    • Market Buy: Buys tokens at current price
    • Take Profit Limit Sell: Sells when price rises
    • Stop Loss Limit Sell: Sells when price falls
  4. Risk Management: Configurable stop loss and take profit levels

Read PROFIT_STRATEGY.md for complete explanation of how the bot makes profit.

Trading Strategy Overview

How It Works

Software Oracle calculates UP token worth: $0.75
Market selling UP token at: $0.70
Difference: $0.05 (above $0.015 threshold)

Bot executes:
1. BUY @ $0.70 (market order)
2. SELL @ $0.71 (take profit +$0.01)
3. SELL @ $0.695 (stop loss -$0.005)

Expected outcome:
- 70% chance: Take profit hits β†’ +$0.01 profit
- 30% chance: Stop loss hits β†’ -$0.005 loss
- Net expectation: Positive

Configuration Parameters

Parameter Default Description
PRICE_DIFFERENCE_THRESHOLD 0.015 Minimum price difference to trigger trade
TAKE_PROFIT_AMOUNT 0.01 Profit target above buy price
STOP_LOSS_AMOUNT 0.005 Maximum loss below buy price
DEFAULT_TRADE_AMOUNT 5.0 USDC amount per trade
TRADE_COOLDOWN 30 Seconds between trades

Modules

1. Credential Generator (_gen_credential.ts)

Manages wallet credentials and API authentication.

import { CredentialGenerator } from './_gen_credential';

const generator = new CredentialGenerator();
generator.displayInfo();

2. Allowance Manager (allowance.ts)

Control USDC token allowances for trading.

import { AllowanceManager } from './allowance';

const manager = new AllowanceManager();
await manager.checkAllowance();
await manager.setAllowance('1000'); // Set 1000 USDC allowance

3. Bid/Ask Pricer (bid_asker.ts)

Get real-time order book data.

import { BidAsker } from './bid_asker';

const bidAsker = new BidAsker();
const data = await bidAsker.getPriceData(tokenId);
console.log(data.bidAsk.midpoint);

4. Market Order Executor (market_order.ts)

Place and manage orders.

import { MarketOrderExecutor } from './market_order';

const executor = new MarketOrderExecutor();
await executor.placeMarketOrder({
    tokenId: 'TOKEN_ID',
    side: 'BUY',
    amount: 10 // 10 USDC
});

5. Market Finder (market_finder.ts)

Auto-detect and search for markets.

import { MarketFinder } from './market_finder';

const finder = new MarketFinder();
const market = await finder.findCurrentBitcoinMarket();
console.log(market.tokens); // UP and DOWN tokens

Safety Features

  • βœ… Confirmation prompts before placing orders
  • βœ… Price validation and sanity checks
  • βœ… Automatic market price buffers
  • βœ… Private key never exposed in logs
  • βœ… Error handling and recovery

Development

start-bot.ps1

```bash
# Watch mode (auto-reload)
npm run dev

# Type checking
npx tsc --noEmit

# Lint
npx eslint src/

Security Notes

⚠️ IMPORTANT:

  • Never commit your .env file
  • Keep your private key secure
  • Test with small amounts first
  • Review all transactions before confirming

Dependencies

  • @polymarket/clob-client - Official Polymarket CLOB client
  • ethers - Ethereum wallet and cryptography
  • axios - HTTP requests
  • dotenv - Environment variable management
  • typescript - Type safety and modern JavaScript

License

ISC

Support

For issues or questions, please refer to:


Disclaimer: Use at your own risk. This software is provided as-is without warranties. Always test with small amounts first.

About

Polymarket bot trading bot is a Polymarket trading bot designed to automatically copy the trading of top Polymarket traders across all active markets. This tool continuously monitors Polymarket trading activity, identifies high-performing wallets, and copies their trading strategies in real time.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published