| Crates.io | lighter-rust |
| lib.rs | lighter-rust |
| version | 0.1.0 |
| created_at | 2025-08-30 03:31:12.11645+00 |
| updated_at | 2025-08-30 03:31:12.11645+00 |
| description | A comprehensive Rust SDK for the Lighter trading platform with async/await, WebSocket support, and Ethereum wallet integration |
| homepage | https://github.com/yongkangc/lighter-rust |
| repository | https://github.com/yongkangc/lighter-rust |
| max_upload_size | |
| id | 1817218 |
| size | 349,995 |
Rust SDK for Lighter (v2)
Add this to your Cargo.toml:
[dependencies]
lighter-rust = { git = "https://github.com/yongkangc/lighter-rust" }
use lighter_rust::{LighterClient, Config};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create configuration
let config = Config::new()
.with_api_key("your-api-key")
.with_base_url("https://api.lighter.xyz")?;
// Initialize client with private key for trading
let client = LighterClient::new(config, "your-private-key")?;
// Get account info
let account = client.account().get_account().await?;
println!("Account: {:?}", account);
// Get market data
let ticker = client.market_data().get_ticker("BTC-USDC").await?;
println!("BTC-USDC Price: {}", ticker.price);
Ok(())
}
Check out the examples directory for comprehensive examples:
Run examples with:
cargo run --example basic_usage
cargo run --example websocket_example
cargo run --example trading_bot
The SDK is built with a modular architecture:
lighter-rust/
├── src/
│ ├── client/ # HTTP and WebSocket clients
│ ├── api/ # API endpoint implementations
│ ├── models/ # Data models and types
│ ├── signers/ # Ethereum signing (Alloy)
│ └── error.rs # Error handling
# Build
cargo build
# Run tests
cargo test
# Run with examples
cargo run --example basic_usage
# Build documentation
cargo doc --open
The SDK can be configured through the Config struct:
use lighter_rust::Config;
let config = Config::new()
.with_api_key("your-api-key")
.with_base_url("https://api.lighter.xyz")?
.with_ws_url("wss://ws.lighter.xyz")?
.with_timeout(30)
.with_max_retries(3);
All methods return a Result<T, LighterError> with comprehensive error types:
use lighter_rust::LighterError;
match client.orders().create_order(...).await {
Ok(order) => println!("Order created: {}", order.id),
Err(LighterError::RateLimit) => println!("Rate limited, please retry"),
Err(LighterError::Auth(msg)) => println!("Authentication failed: {}", msg),
Err(e) => println!("Error: {}", e),
}
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This is an unofficial SDK. Use at your own risk. Always test thoroughly before using in production.
For issues and questions: