kiteticker_async_manager/manager/
config.rs1use crate::models::Mode;
2use std::time::Duration;
3
4#[derive(Debug, Clone)]
6pub struct KiteManagerConfig {
7 pub max_symbols_per_connection: usize,
9
10 pub max_connections: usize,
12
13 pub connection_buffer_size: usize,
15
16 pub parser_buffer_size: usize,
18
19 pub connection_timeout: Duration,
21
22 pub health_check_interval: Duration,
24
25 pub max_reconnect_attempts: usize,
27
28 pub reconnect_delay: Duration,
30
31 pub enable_dedicated_parsers: bool,
33
34 pub default_mode: Mode,
36
37 pub heartbeat_liveness_threshold: Duration,
39}
40
41impl Default for KiteManagerConfig {
42 fn default() -> Self {
43 Self {
44 max_symbols_per_connection: 3000,
45 max_connections: 3,
46 connection_buffer_size: 5000, parser_buffer_size: 10000, connection_timeout: Duration::from_secs(30),
49 health_check_interval: Duration::from_secs(10),
50 max_reconnect_attempts: 5,
51 reconnect_delay: Duration::from_secs(2),
52 enable_dedicated_parsers: true,
53 default_mode: Mode::Quote,
54 heartbeat_liveness_threshold: Duration::from_secs(10),
55 }
56 }
57}
58
59#[derive(Debug, Clone, Default)]
61pub struct ConnectionStats {
62 pub connection_id: usize,
63 pub is_connected: bool,
64 pub symbol_count: usize,
65 pub messages_received: u64,
66 pub messages_parsed: u64,
67 pub errors_count: u64,
68 pub last_message_time: Option<std::time::Instant>,
69 pub average_latency: Duration,
70 pub connection_uptime: Duration,
71}
72
73#[derive(Debug, Clone, Default)]
75pub struct ManagerStats {
76 pub total_symbols: usize,
77 pub active_connections: usize,
78 pub total_messages_received: u64,
79 pub total_messages_parsed: u64,
80 pub total_errors: u64,
81 pub uptime: Duration,
82 pub connection_stats: Vec<ConnectionStats>,
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
87pub enum ChannelId {
88 Connection1 = 0,
89 Connection2 = 1,
90 Connection3 = 2,
91}
92
93impl ChannelId {
94 pub fn from_index(index: usize) -> Option<Self> {
95 match index {
96 0 => Some(Self::Connection1),
97 1 => Some(Self::Connection2),
98 2 => Some(Self::Connection3),
99 _ => None,
100 }
101 }
102
103 pub fn to_index(self) -> usize {
104 self as usize
105 }
106
107 pub fn all() -> Vec<Self> {
108 vec![Self::Connection1, Self::Connection2, Self::Connection3]
109 }
110}
111
112#[derive(Debug, Clone, PartialEq, Eq, Hash)]
118pub struct ApiKeyId(pub String);
119
120impl ApiKeyId {
121 pub fn new(id: impl Into<String>) -> Self {
122 Self(id.into())
123 }
124}
125
126impl From<&str> for ApiKeyId {
127 fn from(s: &str) -> Self {
128 Self(s.to_string())
129 }
130}
131
132impl From<String> for ApiKeyId {
133 fn from(s: String) -> Self {
134 Self(s)
135 }
136}
137
138#[derive(Debug, Clone)]
140pub struct ApiCredentials {
141 pub api_key: String,
142 pub access_token: String,
143}
144
145impl ApiCredentials {
146 pub fn new(api_key: impl Into<String>, access_token: impl Into<String>) -> Self {
147 Self {
148 api_key: api_key.into(),
149 access_token: access_token.into(),
150 }
151 }
152}
153
154#[derive(Debug, Clone, Copy, PartialEq, Eq)]
156pub enum DistributionStrategy {
157 RoundRobin,
159 Manual,
161}
162
163impl Default for DistributionStrategy {
164 fn default() -> Self {
165 Self::RoundRobin
166 }
167}
168
169#[derive(Debug, Clone)]
171pub struct MultiApiConfig {
172 pub base_config: KiteManagerConfig,
174
175 pub max_connections_per_api: usize,
177
178 pub distribution_strategy: DistributionStrategy,
180
181 pub enable_health_monitoring: bool,
183}
184
185impl Default for MultiApiConfig {
186 fn default() -> Self {
187 Self {
188 base_config: KiteManagerConfig::default(),
189 max_connections_per_api: 3,
190 distribution_strategy: DistributionStrategy::RoundRobin,
191 enable_health_monitoring: true,
192 }
193 }
194}
195
196#[derive(Debug, Clone, Default)]
198pub struct ApiKeyStats {
199 pub api_key_id: String,
200 pub active_connections: usize,
201 pub total_symbols: usize,
202 pub total_messages_received: u64,
203 pub total_messages_parsed: u64,
204 pub total_errors: u64,
205 pub connection_stats: Vec<ConnectionStats>,
206}
207
208#[derive(Debug, Clone, Default)]
210pub struct MultiApiStats {
211 pub total_api_keys: usize,
212 pub total_connections: usize,
213 pub total_symbols: usize,
214 pub total_messages_received: u64,
215 pub total_messages_parsed: u64,
216 pub total_errors: u64,
217 pub uptime: Duration,
218 pub per_api_stats: Vec<ApiKeyStats>,
219}