What It Does
Trading Strategy
Instead of taking directional positions like the Price Action Bot, the Market Maker:-
Computes fair probability using a statistical model (normal CDF) based on:
- Current price deviation from strike
- Time remaining until expiration
- Volatility (from recent price observations)
- Momentum (directional price trend)
-
Places symmetric quotes around the fair probability:
- Bids (buy orders) below fair value
- Asks (sell orders) above fair value
- Spread widens based on volatility and momentum
- Adjusts for inventory — skews quotes to reduce net exposure
- Detects adverse selection — trips a circuit breaker when one side fills disproportionately
- One-sided quoting — stops providing liquidity on the losing side when markets trend
Why This Strategy Works
Market making captures the spread. You buy at 48% and sell at 52%, profiting 4% on every round-trip. Over many trades, these small edges compound. Statistical pricing is time-aware. The bot understands that BTC +0.5% with 1 minute left is very different from BTC +0.5% with 7 minutes left:| Scenario | YES Probability (Model) | What It Means |
|---|---|---|
| BTC +0.45%, 1 min left | 99% | Very likely to stay above |
| BTC +0.45%, 7 min left | 75% | Could still reverse |
| BTC ±0%, any time | 50% | Coin flip |
Architecture
High-Level Flow
Key Components
The bot is structured into specialized components:| Component | Purpose | Lines |
|---|---|---|
| PriceTracker | Rolling window of price observations with velocity, volatility, momentum | 140-215 |
| InventoryTracker | Net position tracking and adverse selection detection | 217-286 |
| AssetState | Per-asset market making state (targets, spread, orders, circuit breaker) | 349-384 |
| MarketMaker | Main bot orchestrating pricing, quoting, and rebalancing | 390-1280+ |
Core Concepts
1. Statistical Probability Model
The bot computes YES probability using the normal cumulative distribution function (CDF):- Time decay: As expiration approaches,
sqrt(seconds_remaining)shrinks, making the same price deviation more significant - Volatility aware: Higher volatility increases uncertainty, pulling probabilities toward 50%
- Mean-reverting: Small deviations with lots of time left are less predictive
2. Price Tracker (Momentum & Volatility)
Tracks a rolling window of price observations and computes microstructure signals:- Momentum shifts probability: Strong upward momentum increases YES target
- Volatility widens spread: High volatility = more uncertainty = wider spread
- Triggers rebalance: Volatility spike forces requote
3. Inventory Management
Tracks net position (long YES, short NO, or balanced) and skews quotes to reduce exposure:4. Adverse Selection Detection
If one side fills disproportionately (e.g., only bids fill for 30 seconds), the bot is being adversely selected — informed traders are picking off mispriced orders.5. One-Sided Quoting
When the market is trending strongly (YES target > 65% or < 35%), the bot stops providing liquidity on the losing side:6. Multi-Level Geometric Quoting
Instead of placing one order per side, the bot places multiple orders at different price levels with geometrically distributed sizes:| Level | Weight | USDC | Price |
|---|---|---|---|
| 1 | 32% | $19.20 | 47.0% (closest to mid) |
| 2 | 21% | $12.80 | 46.0% |
| 3 | 14% | $8.53 | 45.0% |
| 4 | 10% | $5.69 | 44.0% |
| 5 | 6% | $3.79 | 43.0% |
| 6 | 4% | $2.53 | 42.0% (furthest from mid) |
7. Graceful Rebalancing
When the fair price moves significantly (>2%), the bot must requote. But canceling orders first creates a gap where the bot provides no liquidity. Graceful rebalance solves this:8. Fill Replacement at Current Fair Value
When an order fills, the bot immediately replaces it — but at the current fair value, not the old fill price:Configuration
Command-Line Arguments
Key Parameters
Running the Bot
Local Development
Minimum Capital
Default: 180 minimum** You can reduce this for testing:Performance Tuning
- Tighter Spreads
- More Levels
- Per-Asset Volatility
Goal: Capture more flow by quoting closer to mid.Trade-off: Higher adverse selection risk. Use with caution.
Claiming Strategy
Unlike the Price Action Bot (which claims every 2 minutes), the Market Maker uses Multicall3 on-chain discovery to find and claim all resolved positions, not just markets traded in the current session:Risk Management
Circuit Breaker
If adverse selection is detected (one side fills >80% over 30 seconds):- Cancel all orders immediately
- Go dark for 10 seconds
- Resume quoting after cooldown
Inventory Limits
The bot doesn’t enforce hard inventory limits, but it skews quotes to naturally reduce exposure:- Long YES → lower YES target → cheaper to sell YES to the bot
- Short NO → higher NO target → cheaper to sell NO to the bot
End-of-Market Behavior
- Last 90 seconds: Widen spread (2x multiplier)
- Last 30 seconds: Pull all orders (too risky)
Performance Metrics
How to evaluate if your market maker is working:| Metric | Good | Bad | What It Means |
|---|---|---|---|
| Fill rate | 40-60% | <20% or >80% | Balanced two-sided flow |
| Adverse selection ratio | <65% | >80% | Getting picked off by informed traders |
| Inventory drift | Near zero | Large net position | Quotes aren’t balanced |
| Spread capture | 1-2% per round-trip | <0.5% | Earning the bid-ask spread |
| Circuit breaker trips | 0-2 per hour | >5 per hour | Model is mispricing |
Customizing the Model
Adjust Volatility Estimation
If the bot’s volatility estimate is off, tune the floor:Change Momentum Impact
Alternative Probability Model
Replace the normal CDF with a custom model:Troubleshooting
Only one side is filling (adverse selection)
Only one side is filling (adverse selection)
Symptoms:
- Circuit breaker trips frequently
- Large net inventory (long YES or NO)
- Low P&L despite high volume
- Spread too tight
- Probability model is wrong
- Not adjusting for momentum
- Widen spread:
--spread 0.02 - Increase momentum factor:
MOMENTUM_FACTOR = 1.0 - Lower adverse selection threshold:
ADVERSE_SELECTION_THRESHOLD = 0.70
No fills at all (passive market)
No fills at all (passive market)
Symptoms:
- Orders rest on book but never fill
- Orderbook is empty or very wide
- Market is illiquid
- Spread is too wide
- Price levels are too far from mid
- Tighten spread:
--spread 0.008 - Increase levels:
--levels 10 - Check orderbook: are there other bots?
Rebalancing too frequently (high API load)
Rebalancing too frequently (high API load)
Symptoms:
- Logs show “REBALANCE” every 2-3 seconds
- High API rate limit warnings
- Threshold too low
- Volatility is high
- Increase rebalance threshold:
REBALANCE_THRESHOLD = 0.05 - Increase min interval:
MIN_REBALANCE_INTERVAL = 5 - Disable volatility-triggered rebalance (comment out line 1219)
Comparison: Market Maker vs Price Action
| Aspect | Market Maker | Price Action |
|---|---|---|
| Strategy | Provide liquidity, earn spread | Take directional positions |
| Order type | Resting limit orders (maker) | Marketable limit orders (taker) |
| Sides | Both (bids + asks) | One (buy YES or buy NO) |
| Risk profile | Lower (inventory risk) | Higher (directional risk) |
| Complexity | High (statistical model, inventory, circuit breakers) | Low (simple signal) |
| Capital required | $60-200 | $10-50 |
| Best for | Consistent small gains | Betting on oracle alignment |
Next Steps
Position Monitoring
Track your market maker’s inventory and P&L.
Price Action Bot
Compare with the simpler directional strategy.
WebSocket Streaming
Replace polling with real-time orderbook updates.
Deploy to Railway
Run your market maker 24/7.