7 releases
Uses new Rust 2024
| new 0.3.0 | Mar 5, 2026 |
|---|---|
| 0.2.1 | Mar 3, 2026 |
| 0.1.4 | Mar 2, 2026 |
| 0.1.2 | Feb 8, 2026 |
#482 in Asynchronous
400KB
10K
SLoC
kalshi-fast-rs
High-performance async Rust client for the Kalshi Trade API.
Highlights
- REST parity with Kalshi Trade API
3.8.0OpenAPI snapshot (77/77path+method operations) - WebSocket parity with current AsyncAPI snapshot, including
user_orders - Deterministic REST resilience: retries, exponential backoff+jitter,
429 Retry-Aftersupport - Builder-based transport controls: timeout, connect timeout, headers, user-agent, proxy, custom
reqwest::Client - Explicit WebSocket lifecycle controls:
close()+ configurableshutdown_timeout(...) - Pager/stream/all helpers for cursor endpoints
Installation
cargo add kalshi-fast-rs
REST Quick Start (Builder + Retry)
use std::time::Duration;
use kalshi_fast::{
KalshiEnvironment, KalshiRestClient, RateLimitConfig, RetryConfig,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = KalshiRestClient::builder(KalshiEnvironment::demo())
.with_rate_limit_config(RateLimitConfig { read_rps: 30, write_rps: 15 })
.with_retry_config(RetryConfig {
max_retries: 4,
base_delay: Duration::from_millis(200),
max_delay: Duration::from_secs(2),
jitter: 0.2,
retry_non_idempotent: false,
})
.with_timeout(Duration::from_secs(10))
.with_connect_timeout(Duration::from_secs(3))
.build()?;
let status = client.get_exchange_status().await?;
println!("exchange_active={}", status.exchange_active);
Ok(())
}
WebSocket V2 Quick Start (user_orders)
use kalshi_fast::{
KalshiAuth, KalshiEnvironment, KalshiWsClient, WsChannel, WsDataMessage, WsEvent, WsMessage,
WsReconnectConfig, WsSubscriptionParamsV2,
};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let auth = KalshiAuth::from_pem_file(
std::env::var("KALSHI_KEY_ID")?,
std::env::var("KALSHI_PRIVATE_KEY_PATH")?,
)?;
let mut ws = KalshiWsClient::connect_authenticated(
KalshiEnvironment::demo(),
auth,
WsReconnectConfig::default(),
).await?;
ws.subscribe_v2(WsSubscriptionParamsV2 {
channels: vec![WsChannel::UserOrders],
..Default::default()
}).await?;
while let Ok(event) = ws.next_event_v2().await {
if let WsEvent::Message(WsMessage::Data(WsDataMessage::UserOrder { msg, .. })) = event {
println!("order={} ticker={} status={:?}", msg.order_id, msg.ticker, msg.status);
}
}
Ok(())
}
Examples
examples/rest_retry_config.rsexamples/rfq_quotes_order_groups.rsexamples/ws_user_orders_v2.rsexamples/list_open_markets.rsexamples/orderbook_stream.rs
Spec Parity Artifacts
- OpenAPI snapshot:
docs/specs/kalshi/openapi.yaml - AsyncAPI snapshot:
docs/specs/kalshi/asyncapi.yaml - Parity report:
docs/spec-parity.md - Regeneration script:
scripts/generate_spec_parity.py
Environment Variables
KALSHI_KEY_IDKALSHI_PRIVATE_KEY_PATH- Optional for some examples:
KALSHI_MARKET_TICKER
References
License
MIT
Dependencies
~11–28MB
~337K SLoC