Skip to content

RajdeepSah/Kalshi_Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kalshi Autonomous Sports Trading Bot

An AI-powered autonomous trading bot for Kalshi prediction markets. The bot scans live sports markets every 2 hours, uses Claude AI to analyze probabilities, and executes $10 trades when confidence is high.

Architecture

┌─────────────────────────────────────────────┐
│           Railway.com (Node.js)             │
│                                             │
│  Cron (2hr) → Fetch Markets → Filter Rules  │
│                     ↓                       │
│            Claude AI Analysis               │
│                     ↓                       │
│           Execute Trade on Kalshi           │
│                     ↓                       │
│           SQLite (trade history)            │
│                     ↓                       │
│        Express API → HTML Dashboard         │
└─────────────────────────────────────────────┘

Trading Rules (Hardcoded Safety)

Rule Value
Category Sports ONLY
Market type Live events only (resolves within 5 hours)
Bet size $10 per trade
Min probability 70% implied
Min payout 1.5x return
Daily loss limit $50 (bot stops trading if hit)
AI confidence threshold 70% minimum
NEVER deposits/withdrawals Hardcoded restriction

Quick Start

1. Clone & Install

git clone <your-repo-url>
cd kalshi-bot
npm install

2. Configure Environment

cp .env.example .env

Edit .env with your credentials:

KALSHI_API_KEY=your_key         # From kalshi.com/account/api
KALSHI_API_SECRET=your_secret   # Base64-encoded secret
KALSHI_ENV=demo                 # Use 'demo' first, 'prod' for real money
ANTHROPIC_API_KEY=sk-ant-...    # From console.anthropic.com

3. Run Locally

node server/index.js

Open http://localhost:3000 to see the dashboard.

4. Test a Cycle

Click "Run now" on the dashboard, or:

curl -X POST http://localhost:3000/api/trigger

Deploy to Railway

Step 1: Push to GitHub

git init
git add .
git commit -m "Initial commit"
git remote add origin <your-github-repo>
git push -u origin main

Step 2: Deploy on Railway

  1. Go to railway.app
  2. Click "New Project""Deploy from GitHub repo"
  3. Select your repository
  4. Railway auto-detects Node.js and deploys

Step 3: Add Environment Variables

In Railway dashboard → your service → Variables tab, add:

KALSHI_API_KEY=your_key
KALSHI_API_SECRET=your_secret
KALSHI_ENV=demo
ANTHROPIC_API_KEY=sk-ant-...
PORT=3000
MAX_BET_AMOUNT=10
MAX_DAILY_LOSS=50
MIN_PROBABILITY=0.70
MIN_PAYOUT_MULTIPLIER=1.5
MAX_RESOLVE_HOURS=5
CRON_SCHEDULE=0 */2 * * *

Step 4: Add Persistent Storage (for SQLite)

In Railway → your service → Volumes tab:

  • Add a volume mounted at /app/data
  • Set env var: DB_PATH=/app/data/trades.db

This keeps your trade history across deploys.

API Endpoints

Endpoint Method Description
/api/status GET Bot status, portfolio summary
/api/trades GET All trade history
/api/trades/open GET Currently open trades
/api/pnl GET Daily P&L breakdown
/api/runs GET Bot run history
/api/balance GET Kalshi account balance
/api/trigger POST Manually trigger trading cycle
/api/check-trades POST Check & resolve open trades
/api/health GET Health check

How the Bot Decides

  1. Fetch: Pulls all active sports markets from Kalshi API
  2. Filter: Keeps only markets where:
    • Resolves within 5 hours (live events)
    • Either YES or NO side has ≥70% implied probability
    • Payout is ≥1.5x the bet
  3. AI Analysis: Sends top 5 (by volume) to Claude, which evaluates:
    • Is the implied probability reasonable?
    • Any red flags or information asymmetry?
    • Confidence score 0-100
  4. Execute: Places $10 trades for markets where AI confidence ≥70%
  5. Monitor: Checks open trades every 30 minutes for resolution

⚠️ Important Warnings

  • Start with KALSHI_ENV=demo to paper trade first
  • Real money risk: When set to prod, this bot places real trades
  • No guarantee of profit: Prediction markets are speculative
  • API costs: Each cycle uses 5 Claude API calls ($0.05)
  • Do NOT increase bet sizes until you've tested extensively
  • Monitor the dashboard — don't just set and forget

Project Structure

kalshi-bot/
├── server/
│   ├── index.js       # Express server + cron + routes
│   ├── kalshi.js      # Kalshi API wrapper
│   ├── brain.js       # Claude AI decision engine
│   ├── trader.js      # Main trading loop orchestrator
│   └── database.js    # SQLite setup + queries
├── client/
│   └── dist/
│       └── index.html # Dashboard (static, no build step)
├── .env.example       # Environment template
├── .gitignore
├── package.json
├── railway.toml       # Railway config
├── Procfile
└── README.md

License

For educational and personal use only. Trade at your own risk.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors