lbank-rs
Complete Rust SDK for LBank cryptocurrency exchange API.
Features
- ✅ Complete API Coverage: All 32 LBank REST API v2 endpoints
- ✅ Dual Client Support: Both blocking and async HTTP clients
- ✅ Type-Safe: Full Rust type safety with comprehensive error handling
- ✅ Authenticated Trading: RSA and HmacSHA256 signature support
- ✅ Modular Design: Separate modules for Market, Trading, Wallet, and Account
- ✅ Easy Configuration: Dotenv support and custom endpoint configuration
- ✅ Well Documented: Complete examples for every module
Installation
Add this to your Cargo.toml:
[]
= "0.3"
= { = "1", = ["full"] } # For async support
= "0.15" # Optional: for loading API credentials
Quick Start
Public Market Data (No Auth Required)
use ;
Authenticated Trading
use ;
use dotenv;
use env;
Async Client
use ;
use Arc;
async
API Modules
1. Common (General) - 5 endpoints
Public configuration and system information:
currency_pairs()- Get all trading pairsaccuracy()- Get price/quantity precision for pairsasset_configs()- Get deposit/withdrawal configstime()- Get server timestamp
2. Market Data - 8 endpoints
Public market information:
system_ping()- Test connectivitydepth(symbol, size)- Order book depthprice(symbol?)- Latest pricesbook_ticker(symbol)- Best bid/askticker_24hr(symbol)- 24hr statisticsetf_ticker_24hr(symbol)- ETF tickertrades(symbol, size, time?)- Recent tradeskline(symbol, size, type, time)- Candlestick data
3. Wallet - 7 endpoints
Deposit and withdrawal management (requires authentication):
system_status()- System maintenance statususer_info()- All coin balanceswithdraw(...)- Submit withdrawaldeposit_history(...)- Deposit recordswithdraw_history(...)- Withdrawal recordsdeposit_address(coin, network?)- Get deposit addressasset_detail(coin?)- Asset information
4. Spot Trading - 9 endpoints
Order and trade management (requires authentication):
create_order_test(...)- Test order (safe)create_order(...)- Place ordercancel_order(...)- Cancel specific ordercancel_order_by_symbol(symbol)- Cancel all ordersorder_info(...)- Query order detailsopen_orders(...)- Current pending ordersorder_history(...)- Historical ordersaccount_info()- Account balancestransaction_history(...)- Trade history
5. Account - 3 endpoints
Account settings and permissions (requires authentication):
trade_fee_rate(category?)- Trading feesapi_restrictions()- API key permissionsaccount_info()- Account information
Authentication
LBank supports two signature methods:
1. RSA Signature (Recommended)
# In your .env file
LBANK_API_KEY=your_api_key
LBANK_SECRET_KEY=-----BEGIN
2. HmacSHA256 Signature
# In your .env file
LBANK_API_KEY=your_api_key
LBANK_SECRET_KEY=your_hex_secret_key
The library automatically detects which signature method to use based on the secret key format.
Environment Setup
Create a .env file in your project root:
LBANK_API_KEY=your_api_key_here
LBANK_SECRET_KEY=your_secret_key_here
Then use dotenv in your code:
use dotenv;
use env;
Order Types
The library supports all LBank order types:
buy/sell- Limit ordersbuy_market/sell_market- Market ordersbuy_maker/sell_maker- Post-only ordersbuy_ioc/sell_ioc- Immediate-or-cancelbuy_fok/sell_fok- Fill-or-kill
Error Handling
use Result;
Examples
The repository includes comprehensive examples for each module:
# Market data examples
# Wallet examples
# Spot trading examples
# Account examples
# General endpoints
Custom Configuration
use ;
let mut config = default;
config.rest_api_endpoint = "https://api.lbank.info".to_string;
let client = new_with_config;
Rate Limits
LBank API has the following rate limits:
- Order operations: 500 requests per 10 seconds
- Other endpoints: 200 requests per 10 seconds
The async client is ideal for staying within rate limits while maximizing throughput.
Safety Features
- 🔒 Test Endpoints: Use
create_order_test()to validate orders without placing them - ⚠️ Clear Warnings: Examples include safety warnings for destructive operations
- 🛡️ Type Safety: Rust's type system prevents common API usage errors
- ✅ Signature Verification: Automatic signature generation for authenticated requests
Documentation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Changelog
Version 0.3.0 (2025-01-XX)
- ✨ Complete API coverage: All 32 REST endpoints
- ✨ Added Market module with 8 endpoints
- ✨ Added Wallet module with 7 endpoints
- ✨ Added Spot Trading module with 9 endpoints
- ✨ Added Account module with 3 endpoints
- ✨ Full RSA and HmacSHA256 signature support
- ✨ Comprehensive examples for all modules
- ✨ Arc + tokio::spawn pattern for async tests
- 📚 Complete documentation overhaul
Version 0.2.0
- Initial release with basic functionality
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
This software is for educational and development purposes only. Use at your own risk.
- The authors and contributors are not responsible for any financial losses
- Always test with small amounts first
- Use
create_order_test()before placing real orders - Keep your API keys secure and never commit them to version control
Links
Made with ❤️ for the Rust and crypto communities