kalshi-rs

Crates.iokalshi-rs
lib.rskalshi-rs
version0.2.1
created_at2025-11-17 07:44:32.312365+00
updated_at2026-01-12 22:21:30.945623+00
descriptionRust SDK for the Kalshi prediction market API. Mirrors the official Python SDK design for ease of use.
homepage
repositoryhttps://github.com/arnavchahal/kalshi-rs
max_upload_size
id1936391
size319,811
Arnav Chahal (arvchahal)

documentation

https://docs.rs/kalshi-rs

README

kalshi-rs

github crates.io docs.rs build status


A fast, strongly-typed Rust SDK for the Public Kalshi API with almost all endpoints supported.

Overview

kalshi-rs is a Rust client that mirrors the structure and behavior of the official Kalshi Python SDK https://docs.kalshi.com/sdks/python/quickstart

This means:

  • method names match the Python SDK whenever possible
  • request/response structures follow the same shape
  • authentication and request signing work exactly like the official version
  • examples from the Python docs can be translated to Rust easily

If you’ve used Kalshi’s Python SDK, the Rust version will feel immediately familiar.

The crate supports:

  • authentication using your Kalshi API key & PEM private key
  • listing and querying markets
  • retrieving orderbooks, trades, candlesticks
  • creating, canceling, and managing orders
  • fetching portfolio and positions
  • error handling consistent with Kalshi’s API responses

The best way to get started is to look at the examples below, the examples in the examples directory and in the quickstart guide and for contirbutions and understanding how the repo is structured the /src readme

Installation

Add the crate to your project:

cargo add kalshi-rs

Quickstart Example

use kalshi_rs::{KalshiClient, Account};
use kalshi_rs::markets::models::MarketsQuery;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let api_key_id = std::env::var("KALSHI_API_KEY_ID")?;
    let account = Account::from_file("kalshi_private.pem", api_key_id)?;
    let client = KalshiClient::new(account);

    let params = MarketsQuery {
        status: Some("active".into()),
        limit: Some(10),
        ..Default::default()
    };

    let markets = client.get_all_markets(&params).await?;
    for m in markets.markets {
        println!("{} — {}", m.ticker, m.title);
    }

    Ok(())
}

Placing and Canceling an Order

use kalshi_rs::portfolio::models::CreateOrderRequest;

let order = CreateOrderRequest {
    ticker: "KXWTAMATCH".into(),
    action: "buy".into(),
    side: "yes".into(),
    count: 1,
    type_: Some("limit".into()),
    yes_price: Some(3),
    ..Default::default()
};

let placed = client.create_order(&order).await?;
println!("Order ID: {}", placed.order.order_id);

client.cancel_order(placed.order.order_id.clone()).await?;
println!("Order canceled.");

Running Tests

Several tests interact with the real Kalshi API. You must set your environment variables:

export KALSHI_API_KEY_ID="your_key_id"
export KALSHI_PRIVATE_KEY_PATH="path/to/your/kalshi_private.pem"

You can generate these keys from the Kalshi dashboard:

API Keys Setup: API keys setup

Then run:

cargo test -- --nocapture

Tests involving trading endpoints will make real requests, so be mindful of costs.


Design Philosophy

kalshi-rs intentionally follows the official Python SDK’s structure and naming to make the transition between languages seamless. If the Python docs say:

client.markets.get_markets(...)

You can expect the Rust version to expose an equivalent:

client.get_all_markets(...)

The goal is clarity, reliability, and easy adoption — not reinvention.


Contributing

Contributions are welcome!

  • create a branch
  • add your features / improvements
  • open a pull request

If you're implementing newly released Kalshi endpoints, improving error handling, or adding examples, all PRs are appreciated.


License

This project is licensed under the MIT License. See LICENSE for details.

Commit count: 0

cargo fmt