An unofficial Rust SDK for the Bybit V5 API.
This repository is mostly generated by AI agents. While every effort is made to ensure code quality and correctness, this codebase should be used with caution.
Use at your own risk:
- This is an unofficial SDK and is not endorsed or maintained by Bybit
- Code generated by AI agents may contain errors or unexpected behavior
- Always thoroughly test any code before using it with real funds
- Start with testnet environments and small amounts
- Review the code before integrating it into production systems
- The authors assume no liability for any financial losses or damages
- Unified Trading Account Support - Single account type for all trading
- Type-Safe API - Strongly-typed enums prevent errors at compile time
- Full Async/Await - Built on tokio for non-blocking operations
- Comprehensive Error Handling - Detailed error types for better debugging
- HMAC-SHA256 Authentication - Secure signature generation for private endpoints
Add to your Cargo.toml:
[dependencies]
rusty-bybit = "0.1"Or install with cargo:
cargo add rusty-bybituse rusty_bybit::BybitClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = BybitClient::testnet();
let time = client.get_server_time().await?;
println!("Server time: {}", time.time_second);
let tickers = client.get_tickers("linear").await?;
println!("Got {} tickers", tickers.list.len());
Ok(())
}use rusty_bybit::BybitClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let api_key = std::env::var("BYBIT_API_KEY")?;
let api_secret = std::env::var("BYBIT_API_SECRET")?;
let client = BybitClient::testnet()
.with_credentials(api_key, api_secret);
let balance = client.get_wallet_balance(None).await?;
if let Some(account) = balance.list.first() {
println!("Total equity: {}", account.total_equity);
}
Ok(())
}use rusty_bybit::{BybitClient, CreateOrderRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = BybitClient::testnet()
.with_credentials("api_key".to_string(), "api_secret".to_string());
let request = CreateOrderRequest {
category: "linear".to_string(),
symbol: "BTCUSDT".to_string(),
side: "Buy".to_string(),
order_type: "Limit".to_string(),
qty: Some("0.001".to_string()),
price: Some("28000".to_string()),
time_in_force: Some("GTC".to_string()),
..Default::default()
};
let response = client.create_order(&request).await?;
println!("Order ID: {}", response.order_id);
Ok(())
}get_server_time()- Get Bybit server timeget_tickers(category)- Get tickers for a market categoryget_orderbook(category, symbol, limit)- Get orderbookget_instruments(category)- Get instrument infoget_kline(category, symbol, interval)- Get kline data
create_order(request)- Create a new ordercancel_order(category, order_id, symbol)- Cancel a specific ordercancel_all_orders(category, symbol)- Cancel all orders for a symbolget_order(category, order_id)- Get order detailsget_open_orders(category)- Get all open orders
get_wallet_balance(account_type)- Get wallet balanceget_position(category, symbol)- Get position infoset_leverage(category, symbol, buy_leverage, sell_leverage)- Set leverageget_execution_list(category, symbol)- Get execution historyget_closed_pnl(category, symbol)- Get closed PnL
let client = BybitClient::testnet();let client = BybitClient::mainnet();let client = BybitClient::new("https://api.bybit.com".to_string());See the crate documentation for detailed API reference.
See the examples/ directory for more usage examples:
basic_usage.rs- Basic market data and authenticated requestsmarket_data.rs- Market data endpointsorder_management.rs- Order creation and managementaccount_management.rs- Wallet and position management
The SDK provides comprehensive error types via BybitError:
use rusty_bybit::{BybitClient, BybitError};
#[tokio::main]
async fn main() {
let client = BybitClient::testnet();
match client.get_server_time().await {
Ok(time) => println!("Time: {}", time.time_second),
Err(BybitError::ApiError { ret_code, ret_msg }) => {
eprintln!("API error {}: {}", ret_code, ret_msg);
}
Err(e) => eprintln!("Error: {}", e),
}
}See CHANGELOG.md for version history and breaking changes.
Contributions are welcome! Please ensure:
- Code passes
cargo clippyandcargo fmt - All tests pass:
cargo test - Documentation is updated for public API changes
Apache-2.0 License
Copyright 2025 rusty-bybit contributors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.