rusty_common/websocket/exchanges/
coinbase.rs

1//! Coinbase WebSocket configuration
2//!
3//! Coinbase-specific WebSocket settings and handlers.
4
5use crate::types::Exchange;
6use crate::websocket::{CompressionConfig, WebSocketConfig};
7use std::time::Duration;
8
9/// Get default Coinbase WebSocket configuration
10pub 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) // 64KB
17        .max_message_size(10 * 1024 * 1024) // 10MB
18        // Coinbase supports compression
19        .compression(CompressionConfig::default())
20        .build()
21}
22
23/// Coinbase WebSocket URLs
24pub mod urls {
25    /// Production WebSocket URL
26    pub const PRODUCTION: &str = "wss://ws-feed.exchange.coinbase.com";
27
28    /// Sandbox WebSocket URL
29    pub const SANDBOX: &str = "wss://ws-feed-public.sandbox.exchange.coinbase.com";
30}
31
32/// Create a subscription message for Coinbase
33pub 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
44/// Create an authenticated subscription for Coinbase
45pub 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}