use crate::models::Mode;
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct KiteManagerConfig {
pub max_symbols_per_connection: usize,
pub max_connections: usize,
pub connection_buffer_size: usize,
pub parser_buffer_size: usize,
pub connection_timeout: Duration,
pub health_check_interval: Duration,
pub max_reconnect_attempts: usize,
pub reconnect_delay: Duration,
pub enable_dedicated_parsers: bool,
pub default_mode: Mode,
pub heartbeat_liveness_threshold: Duration,
}
impl Default for KiteManagerConfig {
fn default() -> Self {
Self {
max_symbols_per_connection: 3000,
max_connections: 3,
connection_buffer_size: 5000, parser_buffer_size: 10000, connection_timeout: Duration::from_secs(30),
health_check_interval: Duration::from_secs(10),
max_reconnect_attempts: 5,
reconnect_delay: Duration::from_secs(2),
enable_dedicated_parsers: true,
default_mode: Mode::Quote,
heartbeat_liveness_threshold: Duration::from_secs(10),
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ConnectionStats {
pub connection_id: usize,
pub is_connected: bool,
pub symbol_count: usize,
pub messages_received: u64,
pub messages_parsed: u64,
pub errors_count: u64,
pub last_message_time: Option<std::time::Instant>,
pub average_latency: Duration,
pub connection_uptime: Duration,
}
#[derive(Debug, Clone, Default)]
pub struct ManagerStats {
pub total_symbols: usize,
pub active_connections: usize,
pub total_messages_received: u64,
pub total_messages_parsed: u64,
pub total_errors: u64,
pub uptime: Duration,
pub connection_stats: Vec<ConnectionStats>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ChannelId {
Connection1 = 0,
Connection2 = 1,
Connection3 = 2,
}
impl ChannelId {
pub fn from_index(index: usize) -> Option<Self> {
match index {
0 => Some(Self::Connection1),
1 => Some(Self::Connection2),
2 => Some(Self::Connection3),
_ => None,
}
}
pub fn to_index(self) -> usize {
self as usize
}
pub fn all() -> Vec<Self> {
vec![Self::Connection1, Self::Connection2, Self::Connection3]
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ApiKeyId(pub String);
impl ApiKeyId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
}
impl From<&str> for ApiKeyId {
fn from(s: &str) -> Self {
Self(s.to_string())
}
}
impl From<String> for ApiKeyId {
fn from(s: String) -> Self {
Self(s)
}
}
#[derive(Debug, Clone)]
pub struct ApiCredentials {
pub api_key: String,
pub access_token: String,
}
impl ApiCredentials {
pub fn new(api_key: impl Into<String>, access_token: impl Into<String>) -> Self {
Self {
api_key: api_key.into(),
access_token: access_token.into(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DistributionStrategy {
RoundRobin,
Manual,
}
impl Default for DistributionStrategy {
fn default() -> Self {
Self::RoundRobin
}
}
#[derive(Debug, Clone)]
pub struct MultiApiConfig {
pub base_config: KiteManagerConfig,
pub max_connections_per_api: usize,
pub distribution_strategy: DistributionStrategy,
pub enable_health_monitoring: bool,
}
impl Default for MultiApiConfig {
fn default() -> Self {
Self {
base_config: KiteManagerConfig::default(),
max_connections_per_api: 3,
distribution_strategy: DistributionStrategy::RoundRobin,
enable_health_monitoring: true,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ApiKeyStats {
pub api_key_id: String,
pub active_connections: usize,
pub total_symbols: usize,
pub total_messages_received: u64,
pub total_messages_parsed: u64,
pub total_errors: u64,
pub connection_stats: Vec<ConnectionStats>,
}
#[derive(Debug, Clone, Default)]
pub struct MultiApiStats {
pub total_api_keys: usize,
pub total_connections: usize,
pub total_symbols: usize,
pub total_messages_received: u64,
pub total_messages_parsed: u64,
pub total_errors: u64,
pub uptime: Duration,
pub per_api_stats: Vec<ApiKeyStats>,
}