Skip to main content
This page assumes you’ve completed installation.

Construct an Exchange

Pass an exchange ID and a config object. Both fields match the structure documented on each exchange’s setup page.
use openpx::ExchangeInner;
use serde_json::json;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let ex = ExchangeInner::new("kalshi", json!({
        "api_key_id": std::env::var("KALSHI_API_KEY_ID")?,
        "private_key_pem": std::env::var("KALSHI_PRIVATE_KEY_PEM")?,
    }))?;
    println!("connected to {}", ex.name());
    Ok(())
}

Fetch markets

fetch_markets returns one page plus an opaque cursor. Pass the cursor back in to fetch the next page.
use openpx::FetchMarketsParams;

let (markets, next_cursor) = ex.fetch_markets(&FetchMarketsParams::default()).await?;
println!("{} markets, next cursor: {:?}", markets.len(), next_cursor);
The TypeScript binding’s fetchMarkets() auto-paginates and returns every market in one call. Rust and Python expose the cursor directly.

Next steps

Set up an exchange

Configure Kalshi or Polymarket credentials.

Unified schema

See how exchange fields map to OpenPX models.

API methods

Full reference for every method on the Exchange interface.

WebSockets

Stream live orderbooks, trades, and fills.