| Crates.io | bybit-rust-api |
| lib.rs | bybit-rust-api |
| version | 0.3.0 |
| created_at | 2025-12-21 13:29:48.650777+00 |
| updated_at | 2025-12-28 08:09:27.717926+00 |
| description | Complete Rust SDK for Bybit API V5 with all endpoints, comprehensive type safety and full test coverage |
| homepage | https://github.com/cafercangundogdu/bybit.rust.api |
| repository | https://github.com/cafercangundogdu/bybit.rust.api |
| max_upload_size | |
| id | 1997968 |
| size | 811,943 |
A Rust SDK for the Bybit API V5, providing easy access to market data and trading functionality.
Add this to your Cargo.toml:
[dependencies]
bybit_rust_api = "0.3.0"
use bybit_rust_api::{ApiKeyPair, Category, MarketClient, RestClient};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create API key pair (empty for public endpoints)
let api_key_pair = ApiKeyPair::new(
"default".to_string(),
"".to_string(),
"".to_string(),
);
// Create REST client
let rest_client = RestClient::new(
api_key_pair,
"https://api.bybit.com".to_string(),
);
// Create Market client
let market_client = MarketClient::new(rest_client);
// Get server time
let server_time = market_client.get_server_time().await?;
println!("Server time: {:?}", server_time.result);
Ok(())
}
use bybit_rust_api::{ApiKeyPair, Category, OrderClient, OrderType, RestClient, Side, TimeInForce};
use bybit_rust_api::dto::PlaceOrderRequest;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Get API credentials from environment
let api_key = std::env::var("BYBIT_API_KEY")?;
let api_secret = std::env::var("BYBIT_API_SECRET")?;
// Create API key pair
let api_key_pair = ApiKeyPair::new(
"trading".to_string(),
api_key,
api_secret,
);
// Create REST client
let rest_client = RestClient::new(
api_key_pair,
"https://api.bybit.com".to_string(),
);
// Create Order client
let order_client = OrderClient::new(rest_client);
// Place a limit order
let order_request = PlaceOrderRequest {
category: Category::Spot,
symbol: "BTCUSDT".to_string(),
side: Side::Buy,
order_type: OrderType::Limit,
qty: "0.001".to_string(),
price: Some("40000".to_string()),
time_in_force: Some(TimeInForce::GTC),
// ... other optional fields
};
let response = order_client.place_order(order_request).await?;
println!("Order placed: {}", response.result.order_id);
Ok(())
}
For private endpoints, set these environment variables:
export BYBIT_API_KEY="your-api-key"
export BYBIT_API_SECRET="your-api-secret"
Run the examples:
# Market data example
cargo run --example market
# Trading example (requires API credentials)
cargo run --example trading
For testing, use the Bybit testnet:
let rest_client = RestClient::new(
api_key_pair,
"https://api-testnet.bybit.com".to_string(),
);
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
This project uses a pre-commit hook to verify code quality before committing.
This hook is automatically installed when you run cargo build.
It runs:
cargo fmtcargo checkcargo check --examplescargo check --testscargo testThis is an unofficial SDK. Please use at your own risk.