Polymarket Market-Making Bot
๐ญ Overview
A market-making bot for Polymarket prediction markets that goes beyond simple spread posting. It implements a fair-value model informed by external market microstructure signals โ BTC price momentum and order book imbalance โ to generate adaptive two-sided quotes that adjust dynamically to market conditions.
โ The Problem
Naive market-making on prediction markets is a losers' game: if you just post fixed spreads, informed traders pick off your quotes whenever a signal moves. Profitable market-making requires a fair-value estimate that's continuously updated based on observable signals, plus risk controls to limit inventory exposure.
๐ ๏ธ What I Built
๐ Fair-Value Model
- ๐ BTC momentum signal: Binance WebSocket feed provides real-time BTC price; momentum (recent directional move) is used as a proxy for broader market risk sentiment, adjusting fair value of correlated prediction markets
- โ๏ธ Order book imbalance signal: Polymarket CLOB order book is analyzed in real time; high bid-side imbalance shifts fair value toward YES, high ask-side imbalance shifts toward NO
- ๐ Combined signal produces a continuously-updated fair value estimate for each market
๐ฌ Quote Generation
- ๐ Two-sided YES/NO quotes generated around fair value with configurable base spread
- ๐ Spread widens automatically when volatility is elevated (volatility kill-switch)
- ๐ Quotes are repriced on every signal update โ no stale orders
๐ฆ Inventory Management
- ๐ Inventory skewing: when long YES, widen the YES ask and tighten the NO ask to reduce exposure
- ๐ซ Max position limits: configurable per-market position caps, bot stops quoting when limit is hit
- ๐ Inventory PnL tracking: marks positions to fair value for real-time unrealized PnL
๐ก๏ธ Risk Controls
- ๐ Spread kill-switch: halts quoting if spread collapses below minimum profitability threshold
- โก Volatility kill-switch: halts quoting during extreme BTC volatility (unreliable fair-value conditions)
- ๐ Manual override: kill-switch commands for immediate position exit
๐งช Backtesting Simulator
- ๐ Round-based backtesting framework replays historical Polymarket CLOB data
- ๐ Simulates fill probability based on historical order flow
- ๐ฐ PnL tracking per round: realized spread income, inventory mark-to-market, position costs
โญ Key Highlights
- ๐ Fair-value model using external signals (BTC momentum + order imbalance) โ not static spread posting
- ๐ Inventory-aware quoting with dynamic skewing
- ๐ก๏ธ Multiple kill-switches for risk management in volatile conditions
- ๐งช Full backtesting framework with historical data replay and PnL tracking