The Lighter Client SDK provides a typed, Rust interface to the Lighter exchange. It wraps the generated OpenAPI client with ergonomic builders, order-state typestates, websocket helpers, and sensible defaults so you can build trading logic without dealing with raw REST calls or signer plumbing.
- Builder-driven
LighterClientwith async/await and Tokio support - Strongly typed identifiers (
MarketId,AccountId,ApiKeyIndex,Price,BaseQty, etc.) to prevent unit mix ups - DSL for constructing single orders, batches, and bracket strategies
- Handles for market data, funding, account management, and exports
- Websocket wrapper with automatic reconnect and typed events
- Bundled signer libraries for macOS (arm64) and Linux (x86_64) with optional overrides
Add the crate to your project with Cargo:
[dependencies]
lighter_client = { git = "https://github.com/arixoneth/lighter-client" }The crate targets Rust 1.70+ and requires Tokio because all high level APIs are asynchronous.
use lighter_client::{
lighter_client::LighterClient,
types::{AccountId, ApiKeyIndex},
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = LighterClient::builder()
.api_url("https://mainnet.zklighter.elliot.ai")
.private_key(std::env::var("LIGHTER_PRIVATE_KEY")?)
.account_index(AccountId::new(
std::env::var("LIGHTER_ACCOUNT_INDEX")?.parse()?,
))
.api_key_index(ApiKeyIndex::new(
std::env::var("LIGHTER_API_KEY_INDEX")?.parse()?,
))
.build()
.await?;
let account = client.account().details().await?;
println!("Fetched {} sub account(s)", account.accounts.len());
Ok(())
}Set these environment variables before running:
LIGHTER_PRIVATE_KEYLIGHTER_ACCOUNT_INDEXLIGHTER_API_KEY_INDEX- optional
LIGHTER_API_URL
The crate embeds the official signer shared libraries for macOS arm64 and Linux x86_64. They are unpacked on demand to a temporary directory, so most users do not need any extra configuration.
You can override the signer lookup using either:
LIGHTER_SIGNER_PATHenvironment variableLighterClient::builder().signer_library_path("path/to/lib")
These overrides are useful when pinning to a custom signer build or when the library lives outside the default search paths.
The examples/ directory contains focused scenarios:
examples/01_quickstart.rs- configure the client and fetch account metadataexamples/02_order_lifecycle.rs- create, sign, and optionally submit a limit orderexamples/03_market_data.rs- access public market data without credentialsexamples/04_account_history.rs- inspect trades, and withdrawalsexamples/05_websocket.rs- consume order book updates over websockets
Run them with cargo run --example 01_quickstart (replace the example name as
needed and export the required environment variables).
cargo fmt
cargo checkFiles under src/models/ and src/apis/ are generated from the OpenAPI
specification; avoid editing them manually.