rusty_common/websocket/exchanges/
bybit.rs1use crate::types::Exchange;
6use crate::websocket::{CompressionConfig, WebSocketConfig};
7use std::time::Duration;
8
9pub fn default_config(url: String) -> WebSocketConfig {
11 WebSocketConfig::builder(Exchange::Bybit, url)
12 .connect_timeout(Duration::from_secs(10))
13 .timeout(Duration::from_secs(30))
14 .ping_interval(Duration::from_secs(20)) .pong_timeout(Duration::from_secs(10))
16 .max_frame_size(65536) .max_message_size(10 * 1024 * 1024) .compression(CompressionConfig::default())
20 .build()
21}
22
23pub mod urls {
25 pub const V5_PUBLIC: &str = "wss://stream.bybit.com/v5/public/spot";
27
28 pub const V5_PRIVATE: &str = "wss://stream.bybit.com/v5/private";
30
31 pub const V5_PUBLIC_LINEAR: &str = "wss://stream.bybit.com/v5/public/linear";
33
34 pub const V5_PUBLIC_INVERSE: &str = "wss://stream.bybit.com/v5/public/inverse";
36
37 pub const V5_PUBLIC_OPTION: &str = "wss://stream.bybit.com/v5/public/option";
39
40 pub const TESTNET_V5_PUBLIC: &str = "wss://stream-testnet.bybit.com/v5/public/spot";
42
43 pub const TESTNET_V5_PRIVATE: &str = "wss://stream-testnet.bybit.com/v5/private";
45}
46
47pub fn create_subscription(req_id: &str, topics: Vec<String>) -> simd_json::OwnedValue {
49 simd_json::json!({
50 "req_id": req_id,
51 "op": "subscribe",
52 "args": topics
53 })
54}
55
56pub fn create_auth_message(api_key: &str, expires: i64, signature: &str) -> simd_json::OwnedValue {
58 simd_json::json!({
59 "req_id": "auth",
60 "op": "auth",
61 "args": [api_key, expires, signature]
62 })
63}