Trading-enabled Kalshi skill for OpenClaw.
Browse prediction markets, execute trades, track positions, and discover hedging opportunities using LLM-powered analysis. Full trading capability via the Kalshi REST API — all in Rust + TypeScript.
Disclaimer: This software is provided as-is for educational and experimental purposes. It is not financial advice. Trading prediction markets involves risk of loss. Use at your own risk and only with funds you can afford to lose.
kalshi-claw markets trending— Top markets by 24h volumekalshi-claw markets search "query"— Search markets by keywordkalshi-claw market <ticker>— Market details with live orderbook
kalshi-claw buy <ticker> YES <amount>— Buy YES positionkalshi-claw buy <ticker> NO <amount>— Buy NO positionkalshi-claw sell <ticker> YES— Exit a YES position- RSA-signed limit orders via the Kalshi REST API
- Rust core computes contract count and Kelly-optimal sizing
kalshi-claw positions— List open positions with live P&Lkalshi-claw positions <ticker>— Detailed position view- Positions tracked locally in
~/.kalshi-claw/positions.json
kalshi-claw wallet status— Show API key, environment, and USD balance
kalshi-claw hedge scan— Scan trending markets for hedging opportunitieskalshi-claw hedge scan --query "topic"— Scan markets matching a querykalshi-claw hedge analyze <tickerA> <tickerB>— Analyze a specific market pair
Uses LLM-powered contrapositive logic to find covering portfolios on Kalshi. Only logically necessary implications accepted — correlations and "likely" relationships are rejected.
Coverage tiers: T1 (≥95%), T2 (90–95%), T3 (85–90%)
Open Terminal (⌘ Space → Terminal) and paste:
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.shThe installer handles everything automatically:
- Checks macOS compatibility
- Installs Xcode Command Line Tools (if missing)
- Installs Homebrew (if missing)
- Installs Rust toolchain via rustup (if missing)
- Installs Node.js 20+ via Homebrew (if missing)
- Installs napi-rs CLI for building the Rust addon
- Runs
npm install - Compiles the Rust native addon (
napi build --release) - Creates
.envfrom the template
open -e .envAdd to your shell environment (or openclaw.json — see OpenClaw docs):
KALSHI_API_KEY — Your Kalshi API key ID (UUID)
KALSHI_PRIVATE_KEY — Your RSA private key (PEM format)
KALSHI_USE_DEMO — true for paper trading, false for live
OPENROUTER_API_KEY — OpenRouter key (for hedge scan)
MAX_BET — Max USD per trade (default: 25)
DRY_RUN — true = simulate, false = real orders
Where to get the keys:
- Kalshi API key + RSA key — kalshi.com → Account → API Keys (or demo.kalshi.co for paper trading)
- OpenRouter API key — openrouter.ai/settings/keys (free tier available)
# Browse markets
npx tsx scripts/kalshi-claw.ts markets trending
npx tsx scripts/kalshi-claw.ts markets search "fed rate"
# Find hedging opportunities
npx tsx scripts/kalshi-claw.ts hedge scan --limit 20
# Check wallet and trade
npx tsx scripts/kalshi-claw.ts wallet status
npx tsx scripts/kalshi-claw.ts buy KXFED-25DEC-T525 YES 50Natural language prompts you can use with OpenClaw:
What's trending on Kalshi?
Returns market tickers, titles, YES/NO prices, and volume.
Show me details for market KXBTC-24DEC31-B100000
Returns full market info with YES/NO orderbook depth and a direct Kalshi link.
What's my Kalshi-Claw wallet balance?
Shows API key, environment (demo/live), and available USD balance.
Buy $50 YES on market KXFED-25DEC-T525
Computes Kelly-optimal contract count, signs an RSA order, and records the position.
Find me hedging opportunities on Kalshi
or more specifically:
Run Kalshi hedge scan limit 15
Note: This takes a minute or two. The skill fetches open markets, pre-scores pairs with the Rust engine, then sends the top candidates to the LLM for logical validation.
Review results — you'll see coverage tiers (T1 = 95%+, T2 = 90–95%, T3 = 85–90%) and the market pairs where you can take hedged positions.
Show my Kalshi-Claw positions
Lists open positions with entry price, current mid-price, and unrealised P&L.
Sell my YES position on market KXFED-25DEC-T525
Places a sell limit order at the current bid price.
- "What's trending on Kalshi?" → Get market tickers
- "Run Kalshi hedge scan limit 15" → Wait for LLM analysis (~60s)
- Review hedge opportunities with coverage tiers
- "Buy $25 YES on market KXFED-25DEC-T525" → Take position on target market
- "Buy $25 NO on market KXCPI-25JAN-T35" → Take position on covering market
- "Show my Kalshi-Claw positions" → Verify entries and track P&L
| Variable | Required | Description |
|---|---|---|
KALSHI_API_KEY |
Yes | Kalshi API key UUID |
KALSHI_PRIVATE_KEY |
Yes (trading) | RSA private key in PEM format (or path to file) |
KALSHI_USE_DEMO |
No | true for demo env (default: true) |
OPENROUTER_API_KEY |
Yes (hedge) | OpenRouter API key for LLM analysis |
KALSHI_LLM_MODEL |
No | LLM model to use (default: nemotron-nano free) |
MAX_BET |
No | Max USD per trade (default: 25) |
DRY_RUN |
No | false to enable real order placement |
Kalshi-Claw is built on two runtimes:
Rust (src/) — compiled to a native Node.js addon via napi-rs. Handles the CPU-intensive inner loop:
| Module | Responsibility |
|---|---|
auth.rs |
RSA-2048 PKCS#1 v1.5 request signing |
orderbook.rs |
Orderbook parsing, best bid/ask, contract count |
hedge.rs |
Batch hedge scoring, coverage tiers, pair ranking |
sizing.rs |
Kelly criterion, dollar sizing, max profit/loss calc |
TypeScript (lib/, scripts/) — async API clients, LLM integration, CLI, display:
| File | Responsibility |
|---|---|
lib/kalshiClient.ts |
Full Kalshi REST API (auth, markets, orders, portfolio) |
lib/llmClient.ts |
OpenRouter LLM for hedge validation |
lib/positionStorage.ts |
Local JSON position store at ~/.kalshi-claw/ |
lib/display.ts |
ANSI terminal UI (tables, banner, P&L colours) |
scripts/kalshi-claw.ts |
CLI dispatcher |
scripts/markets.ts |
Market browsing commands |
scripts/trade.ts |
Order execution |
scripts/positions.ts |
Position tracking with live P&L |
scripts/wallet.ts |
Account status |
scripts/hedge.ts |
LLM hedge discovery pipeline |
Kalshi-Claw/
├── SKILL.md # OpenClaw skill manifest
├── README.md # This file
├── install.sh # ← Start here. One-command macOS setup
├── package.json # npm config + scripts
├── tsconfig.json # TypeScript config
├── Cargo.toml # Rust native addon (napi-rs)
├── build.rs # napi-build setup
├── env_template.txt # Copy to .env, fill in keys
│
├── src/ # Rust source
│ ├── lib.rs # Module entry point
│ ├── auth.rs # RSA signing
│ ├── orderbook.rs # Price parsing + contract math
│ ├── hedge.rs # Hedge scoring + coverage tiers
│ └── sizing.rs # Kelly criterion + position sizing
│
├── lib/ # TypeScript library
│ ├── kalshiClient.ts # Kalshi REST API client
│ ├── llmClient.ts # OpenRouter LLM client
│ ├── positionStorage.ts # ~/.kalshi-claw/positions.json
│ └── display.ts # Terminal UI helpers
│
└── scripts/ # TypeScript CLI
├── kalshi-claw.ts # Main dispatcher
├── config.ts # Config from env vars
├── markets.ts # Market browsing
├── trade.ts # Order execution
├── positions.ts # Position tracking
├── wallet.ts # Wallet status
└── hedge.ts # Hedge discovery
Unlike Polymarket (which uses on-chain CTF token splits), Kalshi is a regulated centralised exchange. Trading is straightforward:
- Set API credentials — RSA key pair from kalshi.com
- Execute trade —
kalshi-claw buy KXFED-25DEC-T525 YES 50- Rust computes contract count:
floor($50 / yes_ask_price) - Signs the order with RSA-SHA256
- Submits a limit order at the current ask
- Rust computes contract count:
- Track position — recorded in
~/.kalshi-claw/positions.json
Example (buying YES at 65¢):
Input: $50 budget, YES ask = $0.65
Contracts: floor(50 / 0.65) = 76 contracts
Cost: 76 × $0.65 = $49.40
Payout: 76 × $1.00 = $76.00 (if YES wins)
Net P&L: +$26.60 (if correct)
Kelly f*: computed by Rust sizing module
- Scan markets:
kalshi-claw hedge scan --query "federal reserve" - Rust pre-scoring: pairs ranked by coverage = 1 − (1−pA)(1−pB)
- LLM validation: top candidates sent to OpenRouter for logical analysis
- Review output: table shows Tier, Coverage, Cost, Net Edge, Market A → Market B
- Analyze pair:
kalshi-claw hedge analyze KXFED-25DEC-T525 KXCPI-25JAN-T35 - Execute if profitable: buy both positions
Coverage tiers:
| Tier | Coverage | Meaning |
|---|---|---|
| T1 (HIGH) | ≥ 95% | Near-certain logical complement — strong hedge |
| T2 (GOOD) | 90–95% | Strong logical relationship |
| T3 (MODERATE) | 85–90% | Decent hedge, some residual risk |
| WEAK | < 85% | Filtered by default (--include-weak to show) |
export KALSHI_API_KEY="your-key-uuid"
export KALSHI_PRIVATE_KEY="$(cat ~/.kalshi/private_key.pem)"Required for hedge commands. Get a free key at openrouter.ai:
export OPENROUTER_API_KEY="sk-or-v1-..."Rebuild the addon:
napi build --platform --releaseModel quality matters. The default nvidia/nemotron-nano-8b-instruct:free works well. Try --include-weak to lower the threshold, or use a broader --query.
Check your RSA key format — it must be PKCS#1 PEM (-----BEGIN RSA PRIVATE KEY-----). PKCS#8 format (-----BEGIN PRIVATE KEY-----) is not supported.
Ensure DRY_RUN=true is set or not set to "false" in your environment.
MIT
Inspired by PolyClaw by Chainstack — the Polymarket equivalent of this skill.
- Kalshi — Regulated prediction market platform
- OpenRouter — LLM API for hedge discovery
- napi-rs — Rust → Node.js native addon framework