High-discipline Polymarket BTC 5-minute trading bot with paper/live modes, adaptive sizing, and strict risk guardrails.
This bot targets short-lived mispricings between model-estimated fair probability and live Polymarket order books.
- Tracks the active BTC 5m market window on Polymarket.
- Builds a fair value estimate for Up/Down using a GBM-style probability model.
- Compares fair value to real book prices including fee and slippage assumptions.
- Trades only when edge, depth, spread, and risk constraints all pass.
- Supports paper mode by default, with explicit controls for live execution.
- Provides Telegram monitoring and control commands.
The core probability engine computes:
z = (ln(S/S0) + (mu - 0.5*sigma^2)*t) / (sigma*sqrt(t))
Then:
pUp = Phi(z)(normal CDF)- Probability is shrunk toward 0.5 (
PROBABILITY_SHRINK) for conservatism. - Optional Chainlink confirmation can slightly boost or pull confidence.
Entry candidates are evaluated on real order book fill quality:
- VWAP-based fill estimate
- Fee + slippage adjusted cost
- Net edge and expected PnL thresholds
- Spread, depth, and price-band filters
MAX_DAILY_LOSS_USDCdaily lockout.MAX_ROUND_LOSS_USDCper-window risk cap.MAX_CONCURRENT_POSITIONScap on open exposure.- Same-side re-entry spacing and stricter repeat-entry criteria.
- Live run caps via
LIVE_MAX_TRADES_PER_RUNandLIVE_MAX_NOTIONAL_USDC. - Hard live arm requirements:
PAPER_TRADE=falseENABLE_LIVE_ORDERS=trueLIVE_ACKNOWLEDGE=I_UNDERSTAND_REAL_TRADES
src/index.js: main loop, orchestration, risk checks, execution flow.src/strategy/fair-value.js: probability model.src/strategy/edge-detector.js: edge math and trade gating.src/feeds/: market data / price tracking.src/execution/: discovery, order books, order placement, claims.src/integrations/telegram.js: Telegram control and notifications.live-preflight.js: safe connectivity and account readiness checks.
npm installcp .env.example .envFill required values in .env (especially API credentials for live mode).
npm run papernpm run live-preflightExpected output ends with: Preflight passed.
Set in .env:
PAPER_TRADE=false
ENABLE_LIVE_ORDERS=true
LIVE_ACKNOWLEDGE=I_UNDERSTAND_REAL_TRADESThen run:
npm run livenpm start: run bot with current.env.npm run paper: force paper mode.npm run live: force live mode.npm run live-preflight: auth/connectivity/market readiness check.npm run debug: verbose logging.npm run measure-latency: latency utility.npm run measure-ratelimits: API rate-limit utility.npm run analyze-paper: analyze paper trade history.
Build and run:
docker compose up --build -dThe bot persists data in ./data (mounted to /app/data in container).
Set:
TELEGRAM_BOT_TOKENTELEGRAM_CHAT_ID(orTELEGRAM_ALLOW_FIRST_CHAT=true)
Commands:
/status/balance/stop/resume/claim/help
- Use a dedicated low-balance bot wallet, never your primary wallet.
- Keep
PRICE_SOURCE=candlefor closest settlement alignment. - Start with smaller
POSITION_SIZE_USDCand strict risk caps. - Keep secrets only in
.envand never commit credential-bearing files. - Backup files like
.env.bak*are ignored; still treat them as sensitive.
- This project was scanned for secrets before open-sourcing.
.envand backup env files are gitignored.- If you discover a vulnerability or accidental secret exposure, rotate keys immediately and open a security issue or private report.
This software is experimental and provided as-is. Trading involves real financial risk, including total loss. You are responsible for your own configuration, key management, and execution decisions.