| Crates.io | lbank-rs |
| lib.rs | lbank-rs |
| version | 0.3.0 |
| created_at | 2025-08-13 06:24:49.507443+00 |
| updated_at | 2025-10-18 09:03:49.666823+00 |
| description | Complete Rust SDK for LBank API - Market data, trading, wallet management with both sync/async support, RSA/HmacSHA256 auth |
| homepage | https://www.lbank.com |
| repository | https://github.com/mmingyeomm/lbank-rs |
| max_upload_size | |
| id | 1793332 |
| size | 260,168 |
Complete Rust SDK for LBank cryptocurrency exchange API.
Add this to your Cargo.toml:
[dependencies]
lbank-rs = "0.3"
tokio = { version = "1", features = ["full"] } # For async support
dotenv = "0.15" # Optional: for loading API credentials
use lbank_rs::{market::Market, client::Client};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new(None, None);
let market = Market { client };
// Get market depth
let depth = market.depth("lbk_usdt", 10)?;
println!("Market depth: {}", depth);
// Get 24hr ticker
let ticker = market.ticker_24hr("lbk_usdt")?;
println!("24hr ticker: {}", ticker);
Ok(())
}
use lbank_rs::{spot::Spot, client::Client};
use dotenv::dotenv;
use std::env;
fn main() -> Result<(), Box<dyn std::error::Error>> {
dotenv().ok();
let api_key = env::var("LBANK_API_KEY").ok();
let secret_key = env::var("LBANK_SECRET_KEY").ok();
let client = Client::new(api_key, secret_key);
let spot = Spot { client };
// Get account information
let account = spot.account_info()?;
println!("Account: {}", account);
// Test order (safe - doesn't place real order)
let test_order = spot.create_order_test(
"lbk_usdt",
"buy",
Some("0.01"),
Some("100"),
None,
None
)?;
println!("Order test: {}", test_order);
Ok(())
}
use lbank_rs::{market::AsyncMarket, client::AsyncClient};
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = AsyncClient::new(None, None);
let market: Arc<AsyncMarket> = Arc::new(AsyncMarket { client });
// Spawn concurrent requests
let market1 = market.clone();
let handle1 = tokio::spawn(async move {
market1.ticker_24hr("lbk_usdt").await
});
let market2 = market.clone();
let handle2 = tokio::spawn(async move {
market2.depth("eth_usdt", 10).await
});
// Wait for all requests
let (ticker, depth) = tokio::try_join!(handle1, handle2)?;
println!("Ticker: {:?}", ticker?);
println!("Depth: {:?}", depth?);
Ok(())
}
Public configuration and system information:
currency_pairs() - Get all trading pairsaccuracy() - Get price/quantity precision for pairsasset_configs() - Get deposit/withdrawal configstime() - Get server timestampPublic 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 dataDeposit 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 informationOrder 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 historyAccount settings and permissions (requires authentication):
trade_fee_rate(category?) - Trading feesapi_restrictions() - API key permissionsaccount_info() - Account informationLBank supports two signature methods:
# In your .env file
LBANK_API_KEY=your_api_key
LBANK_SECRET_KEY=-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASC...
-----END PRIVATE KEY-----
# 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.
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::dotenv;
use std::env;
fn main() {
dotenv().ok();
let api_key = env::var("LBANK_API_KEY").ok();
let secret_key = env::var("LBANK_SECRET_KEY").ok();
// Use credentials...
}
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-killuse lbank_rs::errors::Result;
fn trade() -> Result<()> {
let client = Client::new(None, None);
let spot = Spot { client };
match spot.account_info() {
Ok(info) => println!("Account: {}", info),
Err(e) => {
eprintln!("Error: {}", e);
// Handle specific error types
for cause in e.iter() {
eprintln!("Caused by: {}", cause);
}
}
}
Ok(())
}
The repository includes comprehensive examples for each module:
# Market data examples
cargo run --example market_endpoints_test
cargo run --example market_endpoints_async_test
# Wallet examples
cargo run --example wallet_endpoints_test
cargo run --example wallet_endpoints_async_test
# Spot trading examples
cargo run --example spot_endpoints_test
cargo run --example spot_endpoints_async_test
# Account examples
cargo run --example account_endpoints_test
cargo run --example account_endpoints_async_test
# General endpoints
cargo run --example general_endpoints_blocking_test
cargo run --example general_endpoints_async_test
use lbank_rs::{config::Config, client::Client};
let mut config = Config::default();
config.rest_api_endpoint = "https://api.lbank.info".to_string();
let client = Client::new_with_config(
Some(api_key),
Some(secret_key),
&config
);
LBank API has the following rate limits:
The async client is ideal for staying within rate limits while maximizing throughput.
create_order_test() to validate orders without placing themContributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/amazing-feature)git commit -m 'Add amazing feature')git push origin feature/amazing-feature)This project is licensed under the MIT License - see the LICENSE file for details.
This software is for educational and development purposes only. Use at your own risk.
create_order_test() before placing real ordersMade with ❤️ for the Rust and crypto communities