A polymarket trading bot that detects temporary pricing inefficiencies across connected Polymarket sports markets.
proof.mp4
This repository is not a commercial product.
It exists for one reason:
To share a real working trading system instead of publishing endless AI-generated articles that provide no practical value.
There are thousands of blog posts explaining arbitrage.
Very few people actually build one.
This project is my attempt to bridge that gap.
Everything inside this repository comes from building, testing, breaking, and rebuilding real trading infrastructure.
This bot will not magically print money.
I don't hide that.
Markets evolve.
Edges disappear.
Liquidity changes.
Competition increases.
This repository is a foundation, not a guaranteed income machine.
However, it contains many of the engineering ideas, mathematical models, and architecture that I used before becoming consistently profitable.
If you're interested in quantitative trading, prediction markets, market microstructure, or TypeScript architecture, I hope you'll learn something useful.
While building this project I also created:
STAKE-MATH
A Node.js library implementing Kelly-based stake sizing and probability mathematics.
Trading is not gambling.
Trading is probability management.
Without mathematics, risk management becomes guessing.
Many of the position sizing models used here are based on the Kelly Criterion, fractional Kelly, expected value, and bankroll optimization.
Those mathematical foundations have been responsible for far more of my long-term success than any individual trading strategy.
If you decide to experiment with this project:
- start with simulation mode
- understand every trade the bot makes
- test your own ideas
- use small position sizes
- never risk money you cannot afford to lose
Happy Trading β€οΈ
- β‘ Real-time Polymarket CLOB streaming
- π§ Cross-line arbitrage detection
- π Kelly Criterion stake sizing
- π° Paper trading & Live trading
- π‘ Risk management engine
- π Beautiful terminal dashboard
- π§© Modular architecture
- π Structured logging
- π Production-oriented TypeScript codebase
Sports markets inside a single event should satisfy several no-arbitrage relationships.
Whenever one market reprices faster than another after new information arrives, temporary inefficiencies can appear.
The bot continuously:
Gamma API
β
βΌ
Discover connected markets
β
βΌ
Stream live CLOB orderbooks
β
βΌ
Detect pricing violations
β
βΌ
Risk evaluation
β
βΌ
Kelly stake sizing
β
βΌ
Submit limit orders
β
βΌ
Track positions & PnL
Current arbitrage checks include:
- Complementary YES/NO pairs
- Totals ladder relationships
- Spread ladder relationships
- Moneyline vs Spread
- Three-way market sums
- BTTS relationships
By default the bot focuses on the markets where liquidity is strongest.
| Sport | Markets |
|---|---|
| π NBA | Games, Futures, Draft, Trades, Props |
| β½ FIFA World Cup | Match Winner, Groups, Knockout, Tournament Winner |
SPORT_FOCUS=nba,world_cup
Discovery logs look like:
Discovery refresh:
40 events
520 tokens
NBA: 10
World Cup: 30
Adding another sport only requires creating another profile inside
src/model/sportsRegistry.ts
git clone https://github.com/PolySports/polymarket-cross-line-arbitrage-bot.git
cd polymarket-cross-line-arbitrage-bot
cp .env.example .env
npm install
npm run start:simnpm start -- --mode simnpm start -- --mode live --confirm-livenpm start -- --event nba-lal-bos-2026-01-15npm start -- --tag 100381| Flag | Description |
|---|---|
--mode sim |
Simulation mode |
--mode live |
Live trading |
--event |
Watch specific event |
--tag |
Filter Gamma tags |
--confirm-live |
Required safety confirmation |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Header β
β Mode β’ WS Status β’ Balance β’ PnL β’ Uptime β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Tracked Markets β Opportunities β
ββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββ€
β PnL Chart Exposure β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Orders / Fills β Alerts β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
[p] Pause
[f] Flatten
[q] Quit
Logs are written separately using Pino so they never corrupt the dashboard.
See .env.example.
Important variables:
| Variable | Default | Description |
|---|---|---|
| MODE | sim | sim or live |
| MIN_NET_EDGE_BPS | 50 | Minimum edge |
| MAX_POSITION_USD | 500 | Max Kelly stake |
| KELLY_FRACTION | 0.5 | Half Kelly |
| MIN_STAKE_USD | 5 | Minimum trade |
| MAX_EVENT_EXPOSURE_USD | 200 | Event exposure cap |
| DAILY_LOSS_LIMIT_USD | 100 | Kill switch |
| SIM_INITIAL_BALANCE | 10000 | Paper balance |
The project sizes positions using the Kelly Criterion.
f* = (p β price)
βββββββββββ
(1-price)
stake = bankroll
Γ Kelly
Γ Fractional Kelly
Position sizes are automatically clamped between:
- Minimum stake
- Maximum position
- Event exposure limits
Supported for:
- Locked arbitrage
- Relative value
- Hedged ladder trades
Default configuration uses Half Kelly (0.5) to reduce variance.
Gamma REST
β
βΌ
Event Graph
β
βΌ
Market Classifier
β
βΌ
CLOB REST / WebSocket
β
βΌ
OrderBook Store
β
βΌ
Arbitrage Detector
β
βΌ
Risk Management
β
ββββββββββββββ΄βββββββββββββ
βΌ βΌ
Sim Executor Live Executor
β β
ββββββββββββββ¬βββββββββββββ
βΌ
Portfolio + Dashboard
Live mode requires:
PRIVATE_KEY
CLOB_API_KEY
CLOB_API_SECRET
CLOB_API_PASSPHRASE
and either
--confirm-live
or
CONFIRM_LIVE=true
Execution uses
@polymarket/clob-client-v2
against production endpoints.
src/
βββ arb/
β βββ Arbitrage detection
βββ config/
β βββ Zod configuration
βββ core/
β βββ Engine
βββ data/
β βββ Gamma
β βββ CLOB REST
β βββ WebSocket
βββ exec/
β βββ Simulation
β βββ Live
β βββ Order Manager
βββ model/
β βββ Event Graph
β βββ Classifier
βββ portfolio/
β βββ PnL
βββ risk/
β βββ Exposure controls
βββ ui/
β βββ blessed-contrib dashboard
βββ util/
βββ Logging
βββ Math
βββ Rate limiting
npm test- Additional sports
- Historical backtesting
- Strategy plugins
- Multi-exchange support
- Automatic parameter optimization
- Portfolio analytics
- Web dashboard
- Discord notifications
Contributions are welcome.
Whether you're interested in:
- quantitative trading
- prediction markets
- TypeScript
- market microstructure
- performance optimization
feel free to open an Issue or Pull Request.
This repository is provided for educational purposes only.
Nothing contained here should be interpreted as financial advice.
Prediction markets involve substantial financial risk.
Always test thoroughly using simulation before deploying capital.
Past performance does not guarantee future results.
If this repository helped you learn something new, consider giving it a β.