kiteticker_async_manager/manager/
config.rs

1use crate::models::Mode;
2use std::time::Duration;
3
4/// Configuration for the KiteTicker multi-connection manager
5#[derive(Debug, Clone)]
6pub struct KiteManagerConfig {
7    /// Maximum symbols per WebSocket connection (Kite limit: 3000)
8    pub max_symbols_per_connection: usize,
9    
10    /// Number of WebSocket connections to maintain (Kite limit: 3)
11    pub max_connections: usize,
12    
13    /// Buffer size for each connection's message channel
14    pub connection_buffer_size: usize,
15    
16    /// Buffer size for each parser's output channel
17    pub parser_buffer_size: usize,
18    
19    /// Connection timeout for establishing WebSocket connections
20    pub connection_timeout: Duration,
21    
22    /// Health check interval for monitoring connections
23    pub health_check_interval: Duration,
24    
25    /// Maximum reconnection attempts per connection
26    pub max_reconnect_attempts: usize,
27    
28    /// Delay between reconnection attempts
29    pub reconnect_delay: Duration,
30    
31    /// Enable dedicated parser tasks for each connection
32    pub enable_dedicated_parsers: bool,
33    
34    /// Default subscription mode for new symbols
35    pub default_mode: Mode,
36}
37
38impl Default for KiteManagerConfig {
39    fn default() -> Self {
40        Self {
41            max_symbols_per_connection: 3000,
42            max_connections: 3,
43            connection_buffer_size: 5000,    // High buffer for performance
44            parser_buffer_size: 10000,       // Even higher for parsed messages
45            connection_timeout: Duration::from_secs(30),
46            health_check_interval: Duration::from_secs(10),
47            max_reconnect_attempts: 5,
48            reconnect_delay: Duration::from_secs(2),
49            enable_dedicated_parsers: true,
50            default_mode: Mode::Quote,
51        }
52    }
53}
54
55/// Connection statistics for monitoring
56#[derive(Debug, Clone, Default)]
57pub struct ConnectionStats {
58    pub connection_id: usize,
59    pub is_connected: bool,
60    pub symbol_count: usize,
61    pub messages_received: u64,
62    pub messages_parsed: u64,
63    pub errors_count: u64,
64    pub last_message_time: Option<std::time::Instant>,
65    pub average_latency: Duration,
66    pub connection_uptime: Duration,
67}
68
69/// Manager-wide statistics
70#[derive(Debug, Clone, Default)]
71pub struct ManagerStats {
72    pub total_symbols: usize,
73    pub active_connections: usize,
74    pub total_messages_received: u64,
75    pub total_messages_parsed: u64,
76    pub total_errors: u64,
77    pub uptime: Duration,
78    pub connection_stats: Vec<ConnectionStats>,
79}
80
81/// Channel identifier for output channels
82#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
83pub enum ChannelId {
84    Connection1 = 0,
85    Connection2 = 1,
86    Connection3 = 2,
87}
88
89impl ChannelId {
90    pub fn from_index(index: usize) -> Option<Self> {
91        match index {
92            0 => Some(Self::Connection1),
93            1 => Some(Self::Connection2),
94            2 => Some(Self::Connection3),
95            _ => None,
96        }
97    }
98    
99    pub fn to_index(self) -> usize {
100        self as usize
101    }
102    
103    pub fn all() -> Vec<Self> {
104        vec![Self::Connection1, Self::Connection2, Self::Connection3]
105    }
106}