## What We're Building
A trading bot that:
1. Maintains a macro thesis (e.g., "US recession by end of 2026")
2. Continuously scans Kalshi for contracts where market price diverges from thesis-implied value
3. Alerts you (or trades automatically) when edges appear
4. Tracks P&L and adjusts based on new information
This isn't a latency-sensitive HFT bot. Prediction markets reward information advantage, not speed. The bot's job is to systematically find and act on mispriced contracts.
## Prerequisites
npm install -g @spfunctions/cli
sf setup
You'll need:
- **SF API key** (free at [simplefunctions.dev/dashboard](https://simplefunctions.dev/dashboard))
- **Kalshi API key** with read+write permissions
- **OpenRouter API key** (for the agent's LLM — used for evaluation, not trading logic)
`sf setup` walks you through all of these with real-time validation.
## Step 1: Create Your Thesis
sf create "US enters a recession by end of 2026 — tariffs drive supply chain costs, inflation stays sticky, Fed can't cut fast enough"
This takes ~30 seconds. The engine:
- Decomposes your thesis into a **causal tree** of testable sub-claims
- Scans Kalshi and Polymarket for contracts matching each node
- Calculates **edges** — where market price ≠ thesis-implied price
- Sets initial confidence
## Step 2: Monitor with the Heartbeat
The heartbeat engine runs server-side every 15 minutes:
# Check what the heartbeat found
sf context
# See top edges across all theses
sf edges
# Detailed evaluation history
sf feed --hours 24
You don't need to build a cron job. The server handles news scanning, price refreshing, and milestone detection automatically.
## Step 3: The Trading Loop
For manual trading with bot-like efficiency:
# See what's actionable
sf edges --json | jq '.[] | select(.executableEdge > 10)'
# Check liquidity before entering
sf liquidity --topic oil
# Place an order
sf buy KXRECSSNBER-26 100 --price 32
For agent-assisted trading:
sf agent
> analyze my top edges and suggest trades
> buy 100 contracts of the recession market at 32 cents
The agent has 21+ tools including `place_order` and `cancel_order`. Every trade shows a preview and requires confirmation.
## Step 4: Scenario Analysis
Before committing capital, test scenarios:
# What if the war ends?
sf whatif --set "n1=0.1" --set "n3=0.2"
# What if oil hits ?
sf whatif --set "n3.3=0.95"
This is pure computation — zero LLM cost, instant results. It shows you how your edges change under different scenarios.
## Step 5: Monitor from Anywhere
# Terminal dashboard (Bloomberg-style)
sf dashboard
# Telegram bot (runs in background)
sf telegram --token YOUR_BOT_TOKEN --daemon
# Track performance over time
sf performance
The Telegram bot pushes alerts when confidence changes >2% and responds to natural language queries.
## Architecture
Your thesis
↓
Causal tree decomposition (LLM, one-time)
↓
Market scan: Kalshi + Polymarket
↓
Edge detection: thesis price vs market price
↓
Heartbeat (every 15 min):
- News scan (Tavily)
- Price refresh (Kalshi orderbook)
- Milestone check (economic calendar)
- LLM evaluation → confidence update
↓
You: read context → decide → trade
The bot isn't making trading decisions — it's maintaining an up-to-date view of where markets disagree with your thesis. You decide when to act.
## Cost
- **SF API**: Free tier covers 15M tokens/month
- **OpenRouter**: ~/bin/zsh.05 per evaluation (Claude Sonnet)
- **Tavily news**: Smart scheduling keeps this under /thesis/month
- **Kalshi**: Standard exchange fees
Total running cost for one active thesis: roughly -30/month.
For the complete API reference, see [simplefunctions.dev/docs](https://simplefunctions.dev/docs).