Kalshi-Claw: Open-Source OpenClaw Skill for AI-Powered Prediction Market Trading
Kalshi-Claw is an open-source OpenClaw skill that brings full Kalshi prediction market trading capabilities to natural language commands. Most prediction market platforms either lack proper APIs or require complex manual integration for RSA signing and position tracking — Kalshi-Claw abstracts all of this away.
The project uses a Rust + TypeScript dual-engine architecture: a Rust core (compiled to a native Node.js addon via napi-rs) handles CPU-intensive tasks like RSA-2048 request signing, Kelly criterion position sizing, and hedge scoring; the TypeScript layer interfaces directly with the Kalshi REST API for market browsing and order execution. Simply say 'Buy $50 YES on KXFED-25DEC-T525' and the system computes optimal contract count, signs the RSA order, submits it, and records the position.
The standout feature is LLM-powered hedge discovery: it scans trending markets, uses Rust pre-scoring to rank pairs by coverage, then validates top candidates through an LLM using strict contrapositive logic (correlations and probabilistic relationships are rejected). Results are shown in three coverage tiers: T1 (≥95%), T2 (90–95%), T3 (85–90%). All position data stays local in ~/.kalshi-claw/positions.json. A one-command macOS installer handles all dependencies automatically.
Project Background
Kalshi is a US-regulated centralized prediction market exchange. Unlike Polymarket (which uses on-chain ERC-20 contracts), Kalshi operates more like traditional finance: RSA key pair authentication, REST API order submission, and limit order mechanics. The integration barrier is still significant — RSA signing, contract quantity calculation, and position tracking all need custom implementation. Kalshi-Claw encapsulates all of this into natural language commands within the OpenClaw agent ecosystem.
Technical Architecture
Rust core (src/) compiled to a Node.js native addon via napi-rs, handling:
- `auth.rs`: RSA-2048 PKCS#1 v1.5 request signing
- `orderbook.rs`: Orderbook parsing, best bid/ask, contract count calculation
- `hedge.rs`: Batch hedge scoring, coverage tiers, pair ranking
- `sizing.rs`: Kelly criterion, dollar sizing, max profit/loss calculation
TypeScript layer (lib/, scripts/) handles API communication and CLI:
- `kalshiClient.ts`: Full Kalshi REST API client (auth, markets, orders, portfolio)
- `llmClient.ts`: OpenRouter LLM integration (for hedge validation)
- `positionStorage.ts`: Local JSON position store at ~/.kalshi-claw/
- `display.ts`: ANSI terminal UI (tables, P&L colors)
Core Features
Market Browsing
kalshi-claw markets trending # Top markets by 24h volume
kalshi-claw markets search "fed rate" # Keyword search
kalshi-claw market <ticker> # Market details + live orderbook
Trade Execution
kalshi-claw buy <ticker> YES <amount> # Buy YES position
kalshi-claw buy <ticker> NO <amount> # Buy NO position
kalshi-claw sell <ticker> YES # Exit YES position
The system computes Kelly-optimal contract count, RSA-signs the order, and submits a limit order at the current ask.
Position Tracking
kalshi-claw positions # List open positions with live P&L
Data stored locally in `~/.kalshi-claw/positions.json` — never leaves your machine.
Hedge Discovery (Standout Feature)
kalshi-claw hedge scan # Scan trending markets
kalshi-claw hedge scan --query "federal reserve" # Topic-specific scan
kalshi-claw hedge analyze <ticker-A> <ticker-B> # Analyze a specific pair
Pipeline:
1. Fetch open markets
2. Rust engine batch pre-scoring: coverage = 1 − (1−pA)(1−pB)
3. Top candidates sent to LLM (OpenRouter) for logical validation
4. **Strict contrapositive logic only — correlations and probabilistic relationships rejected**
5. Output coverage tiers: T1 (≥95%) / T2 (90–95%) / T3 (85–90%)
Installation
macOS one-command install:
curl -fsSLk https://github.com/Kirubel125/Kalshi-Claw/archive/refs/heads/main.zip -o /tmp/cw.zip && \
unzip -qo /tmp/cw.zip -d /tmp && \
cd /tmp/Kalshi-Claw-main && \
bash install.sh
The installer automatically handles: Xcode CLI Tools, Homebrew, Rust toolchain, Node.js 20+, napi-rs CLI, and compilation.
Environment Configuration
| Variable | Required | Description |
|----------|----------|-------------|
| KALSHI_API_KEY | Yes | Kalshi API Key UUID |
| KALSHI_PRIVATE_KEY | Yes (trading) | RSA private key in PKCS#1 PEM format |
| KALSHI_USE_DEMO | No | true = paper trading (default: true) |
| OPENROUTER_API_KEY | Yes (hedge) | OpenRouter API Key |
| MAX_BET | No | Max USD per trade (default: 25) |
| DRY_RUN | No | false to enable real order placement |
Note: RSA private key must be PKCS#1 format (-----BEGIN RSA PRIVATE KEY-----). PKCS#8 is not supported.
Use Cases
- **Event-driven trading**: Fed rate decisions, CPI data, election results — these are Kalshi's primary markets. An AI agent can monitor and execute strategies in real time.
- **Risk hedging**: Use hedge discovery to find logically related market pairs with high coverage for hedged positions.
- **Strategy backtesting**: Enable DEMO mode to test strategies without risking real funds.
- **Intelligence signal**: Prediction market prices aggregate social expectations — monitoring them can serve as a signal source.
Limitations
- Currently macOS-only (install script)
- Hedge discovery requires an OpenRouter API key (free tier available)
- RSA private key format requirements are strict — configuration errors are the most common issue
- For educational and experimental purposes only — not financial advice