rusty_common/websocket/exchanges/
coinbase.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::Coinbase, url)
12 .connect_timeout(Duration::from_secs(10))
13 .timeout(Duration::from_secs(30))
14 .ping_interval(Duration::from_secs(30))
15 .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 PRODUCTION: &str = "wss://ws-feed.exchange.coinbase.com";
27
28 pub const SANDBOX: &str = "wss://ws-feed-public.sandbox.exchange.coinbase.com";
30}
31
32pub fn create_subscription(
34 product_ids: Vec<String>,
35 channels: Vec<String>,
36) -> simd_json::OwnedValue {
37 simd_json::json!({
38 "type": "subscribe",
39 "product_ids": product_ids,
40 "channels": channels
41 })
42}
43
44pub fn create_auth_subscription(
46 api_key: &str,
47 signature: &str,
48 timestamp: &str,
49 passphrase: &str,
50 product_ids: Vec<String>,
51 channels: Vec<String>,
52) -> simd_json::OwnedValue {
53 simd_json::json!({
54 "type": "subscribe",
55 "product_ids": product_ids,
56 "channels": channels,
57 "signature": signature,
58 "key": api_key,
59 "passphrase": passphrase,
60 "timestamp": timestamp
61 })
62}