Skip to content

openfi-dao/kalshi-trading-bot

Repository files navigation

Kalshi AI Trading Bot

Multi-agent AI ensemble for Kalshi prediction markets. Five specialized LLM agents debate every market, reach consensus with Kelly-sized positions, and execute in paper or live mode — with full SQLite audit trail.

Node.js Kalshi OpenRouter


What Makes This Different?

Most "AI trading bots" are a single prompt and a prayer. This one runs a structured pipeline:

  1. Ingest — Kalshi markets, news, and context
  2. Debate — five agents analyze in parallel, then synthesize
  3. Consensus — weighted ensemble with disagreement penalty
  4. Size — Kelly criterion with hard risk limits
  5. Execute — paper or live via Kalshi REST + WebSocket
  6. Track & evaluate — SQLite audit, dashboard, agent scorecards

You're not betting on one model's hunch — you're betting on a committee that must agree.


The Agent Ensemble

Agent Weight Role
Forecaster 30% Base probability estimate
News Analyst 20% Event and headline impact
Bull Researcher 20% Upside case
Bear Researcher 15% Downside case
Risk Manager 15% Position sizing veto

Consensus rules: minimum 3 models, disagreement penalty applied, min confidence 0.45.

If the ensemble is disabled, falls back to primaryModel + fallbackModel via ModelRouter.


Features

  • Paper trading — full pipeline without risking capital
  • Live trading — gated by LIVE_TRADING_ENABLED
  • Daily AI cost capDAILY_AI_COST_LIMIT prevents runaway LLM bills
  • Model health routing — unhealthy models auto-demoted
  • Multiple strategies — Safe Compounder, Market Making, Quick-Flip, category scorer
  • SQLite audit — every decision logged to trading.db
  • CLI dashboard — status, scores, history at a glance

Quick Start

Prerequisites

Install

git clone https://github.com/openfi-dao/kalshi-trading-bot.git
cd kalshi-trading-bot
npm install
cp env.template .env

Configure .env

KALSHI_API_KEY=your_key
KALSHI_PRIVATE_KEY_PATH=./kalshi.pem
OPENROUTER_API_KEY=sk-or-...

# Safety defaults
LIVE_TRADING_ENABLED=false
DAILY_AI_COST_LIMIT=10
LOG_LEVEL=info

Run (paper mode)

npm run bot
# or
npm run dev

CLI commands

kalshi-bot run [--live] [--daily-limit n] [--iterations n]
kalshi-bot dashboard
kalshi-bot status
kalshi-bot scores
kalshi-bot history [--limit n]
kalshi-bot safe-compounder [--live]
kalshi-bot health

Pipeline Architecture

flowchart LR
    Ingest[Market Ingest] --> Agents[5-Agent Parallel Analysis]
    Agents --> Debate[Debate Round]
    Debate --> Consensus[Weighted Consensus]
    Consensus --> Kelly[Kelly Sizing]
    Kelly --> Limits[Risk Limits]
    Limits --> Execute[Paper / Live]
    Execute --> Track[SQLite Audit]
    Track --> Eval[Agent Evaluation]
Loading

Risk Parameters

Configured in src/config/settings.ts:

Limit Default
Max per position ~3% of bankroll
Max daily loss ~10%
Max open positions Configurable
Stop-loss Per-strategy
Max hold time Per-strategy

Project Structure

src/
├── cli.ts              # Command-line interface
├── beastModeBot.ts     # Main orchestrator
├── agents/             # Ensemble + debate logic
├── clients/
│   ├── KalshiClient.ts # REST API
│   ├── KalshiWS.ts     # WebSocket
│   └── ModelRouter.ts  # LLM routing + failover
├── jobs/
│   ├── ingest.ts
│   ├── decide.ts
│   ├── trade.ts
│   ├── track.ts
│   └── evaluate.ts
├── strategies/         # Safe-compounder, MM, quick-flip
├── paper/              # Paper tracker + dashboard
└── utils/database.ts   # SQLite layer
trading.db              # Audit log (created at runtime)

Optional Strategies

Strategy Description
Safe Compounder NO-side focused compounding
Market Making Two-sided quoting
Quick-Flip Short-hold directional
Category Scorer Sector-weighted selection

Run with: kalshi-bot safe-compounder [--live]


Development

npm test          # Vitest: ensemble, Kelly, DB, JSON repair
npm run typecheck
npm run lint
npm run build

Failover & Resilience

  • ModelRouter demotes unhealthy LLM providers automatically
  • ensemble.enabled=false → single primary + fallback model
  • All decisions persisted — replay and debug from trading.db

Safety & Disclaimer

  • Start in paper mode. LLM outputs are probabilistic, not oracle predictions.
  • Set a daily AI cost limit before enabling live trading.
  • Kalshi markets involve real money and regulatory constraints — know your jurisdiction.
  • Authors not liable for trading or API costs.

Contributing

Issues and PRs welcome — especially agent prompt improvements, backtesting hooks, and safer default limits.

About

kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot kalshi trading bot

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors