lighter-rust 0.1.0

A comprehensive Rust SDK for the Lighter trading platform with async/await, WebSocket support, and Ethereum wallet integration
Documentation

Lighter Rust SDK

Rust SDK for Lighter (v2)

Installation

Add this to your Cargo.toml:

[dependencies]
lighter-rust = { git = "https://github.com/yongkangc/lighter-rust" }

Quick Start

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(())
}

Features

  • ✅ Complete REST API coverage
  • ✅ WebSocket support for real-time data
  • ✅ Ethereum wallet integration using Alloy
  • ✅ Async/await with Tokio
  • ✅ Type-safe API with comprehensive error handling
  • ✅ Support for all order types (Market, Limit, Stop)
  • ✅ Account tier management (Standard/Premium)

Examples

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

Documentation

API Documentation

Guides

API Coverage

Account Management

  • Get account information
  • Get account statistics
  • Change account tier
  • Get balances and positions

Trading Operations

  • Create orders (market, limit, stop-loss, take-profit)
  • Cancel orders (single or all)
  • Get order history
  • Get trade history

Market Data

  • Candlestick/OHLCV data
  • Tickers
  • Order book depth
  • Market statistics

WebSocket Streams

  • Order book updates
  • Trade streams
  • Account updates

Architecture

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

Requirements

  • Rust 1.70+
  • Tokio runtime

Development

# Build
cargo build

# Run tests
cargo test

# Run with examples
cargo run --example basic_usage

# Build documentation
cargo doc --open

Configuration

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);

Error Handling

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),
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This is an unofficial SDK. Use at your own risk. Always test thoroughly before using in production.

Support

For issues and questions:

Related