Lighter Rust SDK
Rust SDK for Lighter (v2)
Installation
Add this to your Cargo.toml
:
[]
= { = "https://github.com/yongkangc/lighter-rust" }
Quick Start
use ;
async
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:
- basic_usage.rs - Basic API operations and getting started
- websocket_example.rs - Real-time WebSocket streaming
- trading_bot.rs - Simple trading bot with SMA strategy
- advanced_order_management.rs - Grid trading, stop-loss/take-profit
- mnemonic_wallet.rs - Using mnemonic phrases and HD wallets
Run examples with:
Documentation
API Documentation
- AccountApi - Account management operations
- OrderApi - Order placement and management
- TransactionApi - Transaction history and tracking
- CandlestickApi - Market data and OHLCV
- WebSocketClient - Real-time data streaming
Guides
- Integration Guide - Complete integration walkthrough
- API Reference - Full API method reference
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
# Run tests
# Run with examples
# Build documentation
Configuration
The SDK can be configured through the Config
struct:
use Config;
let config = new
.with_api_key
.with_base_url?
.with_ws_url?
.with_timeout
.with_max_retries;
Error Handling
All methods return a Result<T, LighterError>
with comprehensive error types:
use LighterError;
match client.orders.create_order.await
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:
- Open an issue on GitHub
- Check the API documentation