rusty_common/websocket/exchanges/
upbit.rs

1//! Upbit WebSocket configuration
2//!
3//! Upbit-specific WebSocket settings and handlers.
4
5use crate::types::Exchange;
6use crate::websocket::{CompressionConfig, WebSocketConfig};
7use std::time::Duration;
8
9/// Get default Upbit WebSocket configuration
10pub fn default_config(url: String) -> WebSocketConfig {
11    WebSocketConfig::builder(Exchange::Upbit, url)
12        .connect_timeout(Duration::from_secs(10))
13        .timeout(Duration::from_secs(30))
14        .ping_interval(Duration::from_secs(120)) // Upbit recommends 2 minutes
15        .pong_timeout(Duration::from_secs(10))
16        .max_frame_size(65536) // 64KB
17        .max_message_size(10 * 1024 * 1024) // 10MB
18        // Upbit supports compression
19        .compression(CompressionConfig::default())
20        .build()
21}
22
23/// Upbit WebSocket URLs
24pub mod urls {
25    /// Public WebSocket URL
26    pub const PUBLIC: &str = "wss://api.upbit.com/websocket/v1";
27
28    /// Private WebSocket URL (same as public, auth via JWT)
29    pub const PRIVATE: &str = "wss://api.upbit.com/websocket/v1";
30}
31
32/// Create a subscription message for Upbit
33pub fn create_subscription(
34    ticket: &str,
35    types: Vec<String>,
36    codes: Vec<String>,
37    is_only_snapshot: bool,
38    is_only_realtime: bool,
39) -> Vec<simd_json::OwnedValue> {
40    vec![
41        // Ticket
42        simd_json::json!({
43            "ticket": ticket
44        }),
45        // Type and codes
46        simd_json::json!({
47            "type": types.join(","),
48            "codes": codes,
49            "isOnlySnapshot": is_only_snapshot,
50            "isOnlyRealtime": is_only_realtime
51        }),
52    ]
53}
54
55/// Create a simple format subscription for Upbit
56pub fn create_simple_subscription(ticket: &str, format: &str) -> Vec<simd_json::OwnedValue> {
57    vec![
58        simd_json::json!({
59            "ticket": ticket
60        }),
61        simd_json::json!({
62            "format": format
63        }),
64    ]
65}