Expand description
Bybit V5 WebSocket Trading Implementation
This module provides a high-performance WebSocket trading client for Bybit V5 exchange with robust connection management, automatic reconnection, and comprehensive health monitoring.
§Features
- V5 unified authentication: Support for all product types (spot, linear, inverse, option)
- Batch operations: Create, cancel, and amend up to 20 orders in a single request
- Position updates: Real-time position change notifications
- Connection health monitoring: Real-time metrics and health status
- Automatic reconnection: Configurable backoff strategy with exponential delays
- Zero-copy message processing: Optimized for low-latency trading
§Connection Management
The client maintains connection health through:
- WebSocket ping frames sent every 20 seconds (as recommended by Bybit)
- JSON ping requests for API-level health checks
- Automatic reconnection on connection loss
- Configurable pong timeout (default: 10 seconds)
§Batch Operations
Supports Bybit V5 batch operations:
order.create-batch: Create up to 20 orders (10 for spot) in one requestorder.cancel-batch: Cancel multiple orders by IDsorder.amend-batch: Modify multiple orders
§Usage Example
use rusty_common::auth::exchanges::bybit::BybitAuth;
use rusty_ems::exchanges::bybit_websocket_trading::BybitWebSocketTrader;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<()> {
let auth = Arc::new(BybitAuth::new(
"api_key".into(),
"secret_key".into()
));
let trader = BybitWebSocketTrader::new(auth, false); // false = mainnet
let (report_tx, report_rx) = flume::bounded(100);
// Connect and authenticate
trader.connect(report_tx).await?;
// Check connection health
let health = trader.get_connection_health();
println!("Connection healthy: {}", health.is_healthy);
Ok(())
}Structs§
- Bybit
Amend Order Request - Order amendment request
- Bybit
Batch Order Request - Bybit WebSocket batch order request
- Bybit
Cancel AllRequest - Cancel all orders request
- Bybit
Order Request - Bybit WebSocket order request for individual orders
- Bybit
WebSocket Trader - Bybit WebSocket Trading Client
- Connection
Health - Connection health metrics
Enums§
- Bybit
Account Type - Bybit account type
- Bybit
Category - Bybit V5 product categories