rusty_bin/monitor/collector/
types.rs

1//! Core data types for the data collection module.
2
3use crate::monitor::schema::{OrderBookRecord, TradeRecord};
4use smartstring::alias::String as SmartString;
5
6/// Data types that can be collected.
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
8pub enum DataType {
9    /// Trade data
10    Trades,
11    /// Order book data
12    OrderBook,
13}
14
15impl std::fmt::Display for DataType {
16    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17        match self {
18            DataType::Trades => write!(f, "trades"),
19            DataType::OrderBook => write!(f, "orderbook"),
20        }
21    }
22}
23
24/// Market data event that can be collected.
25#[derive(Debug, Clone)]
26pub enum MarketDataEvent {
27    /// Trade data received
28    Trade(TradeRecord),
29    /// Order book data received
30    OrderBook(OrderBookRecord),
31    /// Connection status change
32    ConnectionStatus {
33        /// Exchange name
34        exchange: SmartString,
35        /// Symbol name
36        symbol: SmartString,
37        /// Whether connected
38        connected: bool,
39        /// Timestamp in nanoseconds
40        timestamp: u64,
41    },
42    /// Error occurred
43    Error {
44        /// Exchange name
45        exchange: SmartString,
46        /// Symbol name (if applicable)
47        symbol: Option<SmartString>,
48        /// Error message
49        error: String,
50        /// Timestamp in nanoseconds
51        timestamp: u64,
52    },
53}
54
55/// Statistics for data collection.
56#[derive(Debug, Clone, Default)]
57pub struct CollectionStats {
58    /// Number of trades received
59    pub trades_received: u64,
60    /// Number of order books received
61    pub orderbooks_received: u64,
62    /// Number of errors encountered
63    pub errors_count: u64,
64    /// Timestamp of last trade in nanoseconds
65    pub last_trade_time: Option<u64>,
66    /// Timestamp of last order book in nanoseconds
67    pub last_orderbook_time: Option<u64>,
68    /// Total bytes received
69    pub bytes_received: u64,
70    /// Messages per second rate
71    pub messages_per_second: f64,
72    /// Current latency in nanoseconds
73    pub latency_nanos: u64,
74}
75
76/// Collection status for an exchange-symbol pair.
77#[derive(Debug, Clone)]
78pub struct CollectionStatus {
79    /// Exchange name
80    pub exchange: SmartString,
81    /// Symbol name
82    pub symbol: SmartString,
83    /// Data types being collected
84    pub data_types: Vec<DataType>,
85    /// Whether currently connected
86    pub connected: bool,
87    /// Timestamp of last data received in nanoseconds
88    pub last_seen: Option<u64>,
89    /// Collection statistics
90    pub stats: CollectionStats,
91    /// Number of errors encountered
92    pub error_count: u32,
93    /// Last error message if any
94    pub last_error: Option<String>,
95}
96
97/// Configuration for a specific collection task.
98#[derive(Debug, Clone)]
99pub struct CollectionTask {
100    /// Exchange name
101    pub exchange: SmartString,
102    /// Symbol name
103    pub symbol: SmartString,
104    /// Data types to collect
105    pub data_types: Vec<DataType>,
106    /// Whether this task is enabled
107    pub enabled: bool,
108    /// Current retry count
109    pub retry_count: u32,
110    /// Maximum number of retries allowed
111    pub max_retries: u32,
112    /// Backoff time in milliseconds
113    pub backoff_ms: u64,
114}