kalshi-pmx
kalshi-pmx is a high-level async Rust SDK for Kalshi's Trade API v2 and authenticated WebSocket streams.
It is built for Tokio applications that want typed request builders, typed query params, typed response models, ergonomic REST namespaces, and first-class streaming support without hand-writing raw HTTP calls.
Features
- Tokio async REST client with production, demo, and custom environments.
- RSA API-key signing for REST and WebSocket authentication.
- High-level REST namespaces for exchange, markets, events, orders, portfolio, communications, API keys, account, live data, milestones, search, FCM, historical data, multivariate markets, structured targets, incentive programs, and order groups.
- Generated OpenAPI structs, enums, query params, request builders, and typed operation methods.
- WebSocket subscriptions for public and private channels, including ticker, trades, orderbook deltas, fills, user orders, market positions, lifecycle, communications, order groups, and CF Benchmarks channels.
LiveOrderbookhelper that applies snapshots and deltas into local best-bid state.- Conservative optional rate limiter and retry handling for
429responses. - Offline unit and route tests plus ignored live demo integration tests.
Install
[]
= "0.1"
= { = "1", = ["macros", "rt-multi-thread"] }
The crate uses Rust 1.85 or newer.
Authentication
Public market-data REST calls can be made without credentials:
use GetMarketsParams;
use ;
async
Authenticated REST and WebSocket calls need an API key id and RSA private key:
use ;
async
For examples and live tests, create a .env file:
KALSHI_ENV=demo
KALSHI_API_KEY_ID=your-demo-api-key-id
KALSHI_PRIV_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"
KALSHI_TICKER=replace-with-active-market-ticker
KALSHI_PRIV_KEY may be PEM text or a path to a PEM file. KALSHI_ENV accepts demo/sandbox, production/prod, or a custom REST base URL paired with KALSHI_WS_URL.
You can also configure credentials manually:
use ;
High-Level REST
Normal SDK usage should go through namespace clients and typed params:
use ;
use ;
async
Order requests use generated builders and enums. Building a request is side-effect free; calling
orders().create(...) is the step that actually submits an order.
use ;
use TimeInForce;
use Result;
async
Typed OpenAPI Layer
The higher-level namespace clients delegate to generated typed operation methods. You can also call the generated layer directly when you want exact operation names from the OpenAPI spec:
use GetMarketsParams;
use ;
async
WebSockets
WebSocket streams are authenticated and use typed subscription builders:
use Subscription;
use ;
async
For orderbook streams, LiveOrderbook keeps local state:
use ;
use ;
async
Market Data Granularity
Kalshi's public streams provide market data such as ticker updates, trades, and aggregate
orderbook snapshots/deltas. They are suitable for maintaining a local aggregate orderbook with
LiveOrderbook, but they are not a feed of every individual order submitted by every participant.
Private streams such as fills and user orders report your authenticated account activity.
Examples
Run public REST examples without credentials:
Run authenticated read or stream examples after creating .env:
Specs and Generation
The repository keeps the Kalshi OpenAPI and AsyncAPI references used by this SDK in specs/:
specs/openapi.yamlspecs/asyncapi.yaml
From a repository checkout, regenerate typed schemas, params, and operation methods after updating the OpenAPI spec:
The crates.io package ships the generated Rust source, not the upstream spec files, because the checked-in specs carry their own upstream licensing metadata.
Tests
Offline tests cover auth signing and redaction, authenticated request headers, encoded path
segments, API error bodies, 429 retry behavior, generated builders and enums, model
serialization, route construction, typed query encoding, pagination helpers, WebSocket message
parsing, WebSocket client command flow, reconnect behavior, and spec coverage:
Read-only live demo tests are ignored by default. They load .env, use demo mode unless configured otherwise, and exercise authenticated REST, public market data, portfolio reads, typed operations, and WebSocket subscriptions:
Release checks:
API Coverage
The SDK includes generated types and typed operations for the checked-in OpenAPI spec, plus high-level REST namespace clients for the documented API areas. WebSocket channels from the checked-in AsyncAPI spec are represented as typed subscriptions and parsed stream messages, with raw message preservation for forward compatibility.