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
- Automated BTC Up/Down market discovery
- Multi-level ladder order placement
- Real-time arbitrage execution
- Automatic matched-position merging
- Resolution redemption handling
- Full CLOB authentication support
- Polygon on-chain transaction execution
- WebSocket order book streaming
- REST fallback support
- Order signing & execution
- Integrated wallet mirroring
- Dedicated high-frequency copy trader
- Multi-wallet targeting
- Spend caps & slippage protection
- Dry-run simulation mode
- Configurable circuit breakers
- Hourly loss limits
- Inventory imbalance controls
- Graceful shutdown handling
- Structured logging system
https://github.com/abocchi1/polymarket-trading-bot
The bot continuously:
- Discovers the next BTC 5-minute Up/Down market
- Places bid ladders on both market sides
- Monitors live order books
- Executes arbitrage when:
bestAskUp + bestAskDown < 1 - TARGET_EDGE
- Merges matched positions back into USDC
- Redeems winning outcomes after market resolution
The copy-trading module:
- Tracks target wallet activity
- Detects new BUY executions
- Replicates positions automatically
- Applies configurable sizing and safety filters
- Node.js 18+
- npm
- Polymarket account
- Polymarket proxy wallet
- Polygon EOA private key
- Polygon RPC endpoint
- USDC on Polygon
- MATIC for gas fees
git clone https://github.com/abocchi1/polymarket-trading-bot.git
cd polymarket-trading-botnpm installcp .env.example .envUpdate the required values:
PRIVATE_KEY=
PROXY_WALLET=
POLYGON_RPC=npm startnpm startor
npm run arbnpm run devnode src/copy/index.js| Variable | Description |
|---|---|
PRIVATE_KEY |
Polygon signer private key |
PROXY_WALLET |
Polymarket proxy wallet |
POLYGON_RPC |
Polygon RPC endpoint |
LOG_LEVEL |
Logging verbosity |
# 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=100Runs alongside the main arbitrage engine.
TARGET_WALLET=0x...
COPY_TRADE_BUY_PERCENT=50
COPY_TRADE_POLL_MS=1000High-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=trueThe 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 |
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
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 | 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 |
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.
- Use a dedicated Polygon RPC provider
- Prefer private RPC endpoints
- Maintain sufficient MATIC reserves
- Monitor logs continuously
- Start with small position sizing
- Use dedicated wallets only
- Enable
COPY_DRY_RUN=trueduring testing - Gradually scale after validation
Check:
PRIVATE_KEYPROXY_WALLETPOLYGON_RPC
Verify:
- Wallet signer matches Polymarket account
- Proxy wallet address is correct
- RPC endpoint is stable
Verify:
- Target wallet formatting
- Spend caps
- Slippage settings
- Dry-run configuration
Check:
- Token approvals
- Matched inventory availability
- Market resolution status
bot.logerror output
Example analytics available:
- Daily PnL
- Weekly summaries
- Long-term performance
- Trade execution history
See the img/ directory for screenshots and examples.
- Lower
TARGET_EDGEfor more opportunities - Increase
LADDER_LEVELSfor broader coverage - Tune end-of-market shutdown timing carefully
- Begin with very small allocations
- Use strict slippage controls
- Select high-quality target wallets
- Always dry-run before production deployment
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.
Before opening issues:
- Review
bot.log - Check
.env.example - Validate wallet & RPC configuration
- Test with reduced sizing
- Confirm strategy understanding
npm install
cp .env.example .env
npm startConfigure your .env, fund your wallet, and the bot will begin monitoring and trading eligible BTC markets automatically.