Expand description
§kalshi-rs
A high-performance Rust client for the Kalshi prediction market API.
§Features
- REST API Client - Full coverage of trading and market data endpoints
- WebSocket Client - Real-time orderbook, trades, fills, and lifecycle events
- HFT-Grade Orderbook - Cache-optimized with O(log n) updates
- Async/Await - Built on Tokio for maximum concurrency
§Quick Start
use kalshi_trading::{Config, KalshiClient};
use kalshi_trading::types::{CreateOrderRequest, Side, Action};
#[tokio::main]
async fn main() -> Result<(), kalshi_trading::Error> {
// Create client with API credentials
let private_key = std::fs::read_to_string("private_key.pem")?;
let config = Config::new("api-key-id", &private_key);
let client = KalshiClient::new(config)?;
// Get markets
let markets = client.rest().get_markets(Some("open"), None, None).await?;
// Place an order (buy 10 Yes contracts at $0.50)
let order = CreateOrderRequest::limit(
&markets.markets[0].ticker,
Side::Yes,
Action::Buy,
10,
5000, // Price in centi-cents ($0.50 = 5000 centi-cents)
);
let response = client.rest().create_order(&order).await?;
Ok(())
}§Price Representation
Kalshi uses centi-cents for subpenny precision:
- 100 centi-cents = 1 cent = $0.01
- 5000 centi-cents = 50 cents = $0.50
- 9900 centi-cents = 99 cents = $0.99
§Architecture
This crate is organized into several modules:
client- REST and WebSocket clients for API communicationtypes- Request/response types matching the Kalshi APIorderbook- High-performance orderbook data structureconfig- Configuration and credentials managementerror- Error types for the crate
§Performance
This crate is designed for low-latency trading workloads:
- Integer prices (centi-cents) instead of floating point
FxHashMapfor faster hashing of small keysparking_lotmutexes (faster than std)- Minimal allocations in hot paths
BTreeMapfor sorted price levels
Re-exports§
Modules§
- client
- API clients for communicating with Kalshi.
- config
- Configuration and credentials for the Kalshi API client.
- error
- Error types for the kalshi-rs crate.
- orderbook
- High-performance orderbook implementation.
- types
- API types for Kalshi requests and responses.
Structs§
- Kalshi
Client - The main Kalshi API client
Type Aliases§
- Result
- Result type alias using the crate’s Error type