bybit-api
A production-grade Rust SDK for Bybit V5 API.
Features
- Async-first: Built on tokio for high-performance async I/O
- Type-safe: Strongly typed request/response models with serde
- Zero-panic: No
unwrap()orexpect()in library code - Fund safety: Parameter validation before sending orders/withdrawals
- Complete API coverage: REST API + WebSocket support
- Production ready: Timeout protection, error handling, reconnection
Installation
Add to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["rt-multi-thread", "macros"] }
Quick Start
REST API
use ;
async
Place Order
use ;
use PlaceOrderParams;
async
WebSocket
use BybitWebSocket;
use TESTNET_WS_PUBLIC_LINEAR;
async
Environments
// Mainnet (production)
let client = with_credentials?;
// Testnet
let client = testnet?;
// Demo trading
let client = demo?;
API Coverage
Market Data
get_server_time()- Server timeget_instruments_info()- Instruments infoget_orderbook()- Orderbook depthget_tickers()- 24hr tickerget_klines()- Kline/candlestick dataget_funding_history()- Funding rate historyget_recent_trades()- Recent tradesget_open_interest()- Open interest
Trading
place_order()- Place orderamend_order()- Amend ordercancel_order()- Cancel ordercancel_all_orders()- Cancel all ordersplace_batch_order()- Batch place ordersget_open_orders()- Get open ordersget_order_history()- Order history
Position
get_positions()- Get positionsset_leverage()- Set leverageset_trading_stop()- Set TP/SLget_closed_pnl()- Closed PnLget_executions()- Execution list
Account
get_wallet_balance()- Wallet balanceget_account_info()- Account infoget_fee_rate()- Fee ratesget_transaction_log()- Transaction log
Asset
get_coin_info()- Coin infointernal_transfer()- Internal transferget_deposit_address()- Deposit addresswithdraw()- Withdraw (with validation)
WebSocket Topics
- Public:
orderbook,trade,ticker,kline - Private:
position,order,wallet,execution
Error Handling
use ;
match client.place_order.await
Examples
See the examples directory for more:
market_ticker.rs- Fetch market dataplace_order.rs- Place ordersget_positions.rs- Get positionsget_wallet_balance.rs- Get wallet balancewebsocket_orderbook.rs- Subscribe to orderbookwebsocket_private.rs- Private channel subscriptions
Run examples:
License
MIT License - see LICENSE for details.