Skip to content

abocchi1/polymarket-trading-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polymarket BTC Up/Down Trading Bot

Production-grade automated trading bot for Polymarket 5-minute BTC Up/Down prediction markets.

Built with Node.js, this bot combines:

  • Market-making ladders
  • Cross-side arbitrage execution
  • On-chain merge/redeem automation
  • Wallet copy trading
  • Real-time CLOB monitoring
  • Risk management & operational safeguards

Features

Trading Engine

  • Automated BTC Up/Down market discovery
  • Multi-level ladder order placement
  • Real-time arbitrage execution
  • Automatic matched-position merging
  • Resolution redemption handling

Polymarket Integration

  • Full CLOB authentication support
  • Polygon on-chain transaction execution
  • WebSocket order book streaming
  • REST fallback support
  • Order signing & execution

Copy Trading

  • Integrated wallet mirroring
  • Dedicated high-frequency copy trader
  • Multi-wallet targeting
  • Spend caps & slippage protection
  • Dry-run simulation mode

Safety & Reliability

  • Configurable circuit breakers
  • Hourly loss limits
  • Inventory imbalance controls
  • Graceful shutdown handling
  • Structured logging system

Repository

https://github.com/abocchi1/polymarket-trading-bot


Strategy Overview

Arbitrage Workflow

The bot continuously:

  1. Discovers the next BTC 5-minute Up/Down market
  2. Places bid ladders on both market sides
  3. Monitors live order books
  4. Executes arbitrage when:
bestAskUp + bestAskDown < 1 - TARGET_EDGE
  1. Merges matched positions back into USDC
  2. Redeems winning outcomes after market resolution

Copy Trading Workflow

The copy-trading module:

  • Tracks target wallet activity
  • Detects new BUY executions
  • Replicates positions automatically
  • Applies configurable sizing and safety filters

Requirements

Software

  • Node.js 18+
  • npm

Accounts & Infrastructure

  • Polymarket account
  • Polymarket proxy wallet
  • Polygon EOA private key
  • Polygon RPC endpoint

Funds

  • USDC on Polygon
  • MATIC for gas fees

Installation

1. Clone Repository

git clone https://github.com/abocchi1/polymarket-trading-bot.git
cd polymarket-trading-bot

2. Install Dependencies

npm install

3. Configure Environment

cp .env.example .env

Update the required values:

PRIVATE_KEY=
PROXY_WALLET=
POLYGON_RPC=

4. Start the Bot

npm start

Running Modes

Main Arbitrage Bot

npm start

or

npm run arb

Development Mode

npm run dev

Dedicated Copy Trader

node src/copy/index.js

Environment Configuration

Core Settings

Variable Description
PRIVATE_KEY Polygon signer private key
PROXY_WALLET Polymarket proxy wallet
POLYGON_RPC Polygon RPC endpoint
LOG_LEVEL Logging verbosity

Trading Controls

# Maximum capital allocated per market
MAX_SPEND_PER_MARKET=1000

# Minimum arbitrage edge required
TARGET_EDGE=0.02

# Merge threshold for matched positions
MERGE_THRESHOLD_USDC=500

# Maximum taker execution size
MAX_TAKER_FILL_USDC=200

# Stop buying above combined ask threshold
COMBINED_ASK_STOP=0.98

# Hourly circuit breaker
MAX_LOSS_PER_HOUR_USDC=500

# Ladder configuration
LADDER_LEVELS=5
LADDER_SIZE_PER_LEVEL_USDC=100

Copy Trading Configuration

Integrated Mode

Runs alongside the main arbitrage engine.

TARGET_WALLET=0x...
COPY_TRADE_BUY_PERCENT=50
COPY_TRADE_POLL_MS=1000

Dedicated Copy Trading Mode

High-frequency standalone copy trader.

COPY_TARGETS=0xWallet1,0xWallet2

COPY_SIZE_MODE=FIXED
COPY_FIXED_USDC=100

COPY_MAX_USDC_PER_TRADE=500
COPY_MAX_USDC_PER_HOUR=2000

COPY_DRY_RUN=true

Risk Controls

The bot includes several built-in protection systems.

Control Purpose
MAX_SPEND_PER_MARKET Limits capital exposure
MAX_TAKER_FILL_USDC Caps taker order size
MAX_INVENTORY_IMBALANCE_USDC Prevents directional imbalance
COMBINED_ASK_STOP Avoids overpaying
MAX_LOSS_PER_HOUR_USDC Hourly circuit breaker
STOP_BUYING_BEFORE_CLOSE Reduces end-of-market risk

Logging

The bot outputs logs to:

Console  -> Human-readable live logs
bot.log  -> Structured JSON logs

Logs include:

  • Order activity
  • Arbitrage execution
  • Merge/redemption events
  • Errors & exceptions
  • Risk control triggers

Project Structure

src/
├── index.js
├── trader.js
├── market.js
├── clob.js
├── onchain.js
├── copy-trader.js
├── pnl.js
├── logger.js
└── copy/
    ├── index.js
    ├── activityFeed.js
    ├── copyTrader.js
    └── config.js

File Reference

File Responsibility
src/index.js Main lifecycle & orchestration
src/trader.js Per-market trading state machine
src/market.js Market discovery & API helpers
src/clob.js CLOB auth, REST & WebSocket client
src/onchain.js Polygon approvals & settlements
src/copy-trader.js Integrated copy trading
src/pnl.js Profit & loss tracking
src/logger.js Structured logging
src/copy/activityFeed.js Trade activity polling
src/copy/copyTrader.js Copy execution engine

CLOB Credentials

The bot can automatically derive Polymarket CLOB credentials.

Leave the following values blank:

POLY_API_KEY=
POLY_API_SECRET=
POLY_API_PASSPHRASE=

Credentials will be generated automatically on first run.


Recommended Production Setup

Infrastructure

  • Use a dedicated Polygon RPC provider
  • Prefer private RPC endpoints
  • Maintain sufficient MATIC reserves
  • Monitor logs continuously

Operational Safety

  • Start with small position sizing
  • Use dedicated wallets only
  • Enable COPY_DRY_RUN=true during testing
  • Gradually scale after validation

Troubleshooting

Bot Exits Immediately

Check:

  • PRIVATE_KEY
  • PROXY_WALLET
  • POLYGON_RPC

Authentication Failures

Verify:

  • Wallet signer matches Polymarket account
  • Proxy wallet address is correct
  • RPC endpoint is stable

Copy Trades Not Executing

Verify:

  • Target wallet formatting
  • Spend caps
  • Slippage settings
  • Dry-run configuration

Merge or Redeem Failures

Check:

  • Token approvals
  • Matched inventory availability
  • Market resolution status
  • bot.log error output

Performance Tracking

Example analytics available:

  • Daily PnL
  • Weekly summaries
  • Long-term performance
  • Trade execution history

See the img/ directory for screenshots and examples.


Best Practices

Arbitrage

  • Lower TARGET_EDGE for more opportunities
  • Increase LADDER_LEVELS for broader coverage
  • Tune end-of-market shutdown timing carefully

Copy Trading

  • Begin with very small allocations
  • Use strict slippage controls
  • Select high-quality target wallets
  • Always dry-run before production deployment

Disclaimer

This software is intended for research and experienced operators only.

Trading prediction markets involves substantial risk, including:

  • Market risk
  • Liquidity risk
  • Smart contract risk
  • RPC/network failures
  • Execution risk

This repository does not provide financial advice.

You are fully responsible for:

  • Configuration
  • Deployment
  • Operational security
  • Trading decisions
  • Financial outcomes

Use at your own risk.


Support

Before opening issues:

  1. Review bot.log
  2. Check .env.example
  3. Validate wallet & RPC configuration
  4. Test with reduced sizing
  5. Confirm strategy understanding

Quick Start Summary

npm install
cp .env.example .env
npm start

Configure your .env, fund your wallet, and the bot will begin monitoring and trading eligible BTC markets automatically.

About

polymarket trading bot, polymarket trading bot, polymarket trading bot, polymarket trading bot, polymarket trading bot, polymarket trading bot, polymarket trading bot, polymarket trading bot, polymarket trading bot, polymarket trading bot, polymarket trading bot,

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors