DEV Community

Ryan Gillett
Ryan Gillett

Posted on

I built 13 AI agents that trade Kalshi prediction markets 24/7 — here's how it works

Prediction markets are fascinating. Unlike stock markets where you're guessing at company valuations, prediction markets let you bet directly on whether specific events will happen — BTC settles above $90k by 4pm, the Lakers win tonight, inflation hits 3.2% this month.

Kalshi is a CFTC-regulated US exchange for exactly this. And because it's regulated, you can trade programmatically via their REST API.

So I built a system: 13 autonomous agents that trade Kalshi 24/7 from a desktop app. Here's how it works.

The Problem with Manual Trading on Kalshi

Most retail traders on Kalshi are:

  1. Slow — they manually browse markets, check prices, place orders
  2. Emotional — they chase moves, overbuy winners
  3. Uninformed — they don't have real-time feeds for the underlying asset data

The markets are reasonably liquid (BTC crypto settlement contracts trade hundreds of contracts/day), and the odds update in near-real-time. This creates an edge for anyone with fast, systematic signals.

Architecture Overview

Python backend (FastAPI) ──── 13 async agents
       │
       └── Electron shell ──── React dashboard (Vite)
Enter fullscreen mode Exit fullscreen mode

Two layers:

  • Python backend on localhost:8001 — all trading logic, API calls, WebSocket feeds
  • Electron + React frontend — real-time dashboard, equity curve, agent controls

The Python backend spawns and monitors agents, collects P&L, and serves data via REST endpoints polled every 2 seconds.

The 13 Agents

Crypto Settlement Agents (5 bots)

These trade the BTC, SOL, XRP, DOGE, and HYPE 15-minute settlement contracts.

Each contract settles YES or NO based on whether the price is above a threshold at expiry. My agents use a 9-signal consensus model — at least 6 of 9 signals must agree before placing a trade.

The 9 signals:

  1. Price vs. previous settlement (momentum)
  2. 60-second price momentum
  3. VWAP deviation
  4. RSI (14-period, adapted for 15-min prediction markets)
  5. Bollinger Band position
  6. Volume-weighted direction
  7. Time-of-day pattern (crypto has intraday structure)
  8. Cross-asset correlation (BTC moves drag SOL/XRP)
  9. Order book imbalance from Kraken WebSocket

Signal data comes from a live Kraken WebSocket feed — sub-100ms latency on price updates.

# Simplified consensus check
signals = [
    price_momentum_signal(),
    sixty_sec_momentum(),
    vwap_deviation(),
    rsi_signal(),
    bb_position(),
    volume_direction(),
    time_of_day_bias(),
    cross_asset_correlation(),
    orderbook_imbalance()
]
yes_count = sum(1 for s in signals if s == 'YES')
no_count  = sum(1 for s in signals if s == 'NO')

if yes_count >= 6:
    place_order('YES', kelly_size)
elif no_count >= 6:
    place_order('NO', kelly_size)
Enter fullscreen mode Exit fullscreen mode

Arbitrage Bot

Watches for Kalshi repricing lag — the 5–30 second window after a significant price move where market makers haven't fully updated their quotes.

When BTC drops 0.4% in 8 seconds on Kraken but Kalshi still shows the YES contract at 68¢ (fair value ~52¢), that's a tradeable gap. Target: ≥75% win rate.

Sports Bot

Pulls live ESPN score feeds and converts game state to win probability. If Kalshi's YES price for "Lakers win tonight" is 58¢ but the model says 72% probability, that's a 14% edge — well above the 6% threshold required to place a trade.

Prediction Bot

Trades macro markets — Fed decisions, NOAA weather outcomes, political events. Uses public probability feeds (Vegas lines, polling aggregators) and news sentiment.

Infrastructure Agents

  • Price Feed — Kraken WebSocket, publishes BTC/SOL/XRP/DOGE to an in-memory event bus
  • Signal Hub — aggregates signals from all trading bots, deduplicates overlapping orders
  • Adaptive Brain — re-tunes Kelly fraction every 15 minutes based on recent win rate
  • Account Manager — monitors balance, open positions, enforces per-bot limits
  • Rapid Mode — high-frequency arb for <30 second repricing gaps

Risk Management

The Adaptive Brain handles position sizing using fractional Kelly:

kelly_f = (win_rate * avg_win - loss_rate * avg_loss) / avg_win
safe_f  = kelly_f * 0.25   # quarter-Kelly for safety
contracts = int(balance * safe_f / contract_price)
contracts = min(contracts, MAX_CONTRACTS_PER_TRADE)
Enter fullscreen mode Exit fullscreen mode

Additional guardrails:

  • Daily loss limit — shuts all bots down if daily P&L drops below threshold
  • Dead zones — no trading within 2 minutes of contract expiry (spreads widen, slippage spikes)
  • Drawdown guard — reduces Kelly fraction when drawdown exceeds 8%
  • Max contracts per trade — hard cap regardless of Kelly output

The Dashboard

React + Vite app embedded in Electron. Real-time updates via polling the FastAPI backend.

Key views:

  • Live tab — real-time BTC/SOL/XRP/DOGE prices, active agent signals, current positions
  • Analytics tab — equity curve (gradient area chart via Recharts), per-bot P&L breakdown
  • Markets tab — all 200+ open Kalshi markets, filterable by category

Live Results (Our Own Account)

  • 521 trades executed
  • 58% win rate (302W / 219L)
  • +$177.16 total P&L
  • SOL bot leading at +$91.61 / 61.7% win rate

The SOL agent has been the standout — SOL's intraday volatility creates frequent strong-consensus setups.

Lessons Learned

1. Deduplication matters more than you think. When multiple bots see correlated signals on related assets, they can pile into similar positions simultaneously. The Signal Hub helps, but it still requires tuning.

2. Dead zones are non-negotiable. Trading within 2 minutes of expiry is where bad fills happen. The spread widens dramatically as market makers hedge expiry risk.

3. Static thresholds are fragile. The 6/9 consensus threshold works well in moderate-volatility regimes but can be too aggressive (miss trades) or too loose (bad fills) depending on conditions. Dynamic thresholds based on recent realized vol would be better.

4. Kelly sizing is conservative by design. Quarter-Kelly feels timid until you have a 5-loss streak and realize the full-Kelly version would have wiped 40% of your balance.

Try It

The desktop app is available at whop.com/bearbrief-bot/kalshi-bot-30 ($10/month). Source architecture, install scripts, and README are on GitHub.

Stack: Python, FastAPI, Uvicorn, Electron, React, Vite, Recharts, Kraken WS API, Kalshi REST API.


Trading prediction markets involves financial risk. Past results don't guarantee future performance.

Top comments (0)