Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kalshi-cli

A thin, JSON-first command-line wrapper around Kalshi's official kalshi_python_sync SDK. Built so an LLM agent (Claude Code or any other) can pull Kalshi market data reliably by running one shell command and reading JSON.

Contract (what an agent needs to know)

  • Every command prints one JSON document to stdout.
  • Errors print {"error": ...} to stderr and exit non-zero.
  • Market data needs no credentials. Only account/portfolio + streaming do.

Setup

Already done in this folder: a .venv with kalshi_python_sync installed. To recreate elsewhere:

python3 -m venv .venv           # needs Python 3.13+
./.venv/bin/pip install kalshi-python-sync

Run via the ./kalshi launcher (it loads .env and uses the venv). Optionally symlink it onto your PATH: ln -s "$PWD/kalshi" ~/.local/bin/kalshi.

Public commands (no auth)

./kalshi status                              # exchange health
./kalshi markets --status open --limit 100   # list markets
./kalshi markets --search "president"        # client-side title/ticker filter
./kalshi market   KXELONMARS-99              # one market (bids/asks/volume)
./kalshi orderbook KXELONMARS-99 --depth 5   # order book
./kalshi trades   KXELONMARS-99 --limit 20   # recent trades (the tape)
./kalshi events   --status open --search fed # list/search events
./kalshi event    KXNEXTATLFED-30JAN01 --markets
./kalshi series   KXPRES

Prices come back as decimal-dollar strings in *_dollars fields (e.g. yes_bid_dollars: "0.12"); sizes/volumes in *_fp fields.

Add --pretty for indented JSON (works before or after the subcommand). Add --demo to hit the sandbox.

Authenticated commands

Create an API key in the Kalshi web app (Settings → API Keys), download the RSA .pem, then cp .env.example .env and fill in:

KALSHI_API_KEY_ID=...
KALSHI_PRIVATE_KEY_PATH=/absolute/path/to/private_key.pem
./kalshi balance
./kalshi positions --limit 50

The SDK signs each request (RSA-PSS) for you. Auth is wired up only when both env vars are present — public commands keep working without them.

Streaming (optional, off by default)

REST commands are "real-time enough" for most agent workflows (call them when you need fresh data). For a continuous push feed:

./.venv/bin/pip install websockets      # one-time
./kalshi stream KXELONMARS-99 --channel ticker_v2,trade

Needs credentials; emits newline-delimited JSON, one message per line.

Why this design

  • Official SDK underneath, so output tracks the live API (the SDK is regenerated weekly from Kalshi's OpenAPI spec).
  • No field guessing — responses are dumped straight from SDK models.
  • Simple — one command in, JSON out.

About

JSON-first Kalshi CLI over the official SDK, built for LLM agents. Market data needs no auth.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages