nt_market_data/
lib.rs

1// Market Data Module - High-performance market data ingestion and aggregation
2//
3// Performance targets:
4// - WebSocket ingestion: <100μs per tick
5// - REST API calls: <50ms p99
6// - Throughput: 10,000 events/sec
7
8pub mod aggregator;
9pub mod alpaca;
10pub mod errors;
11pub mod polygon;
12pub mod rest;
13pub mod types;
14pub mod websocket;
15
16pub use aggregator::MarketDataAggregator;
17pub use alpaca::AlpacaClient;
18pub use errors::{MarketDataError, Result};
19pub use polygon::{PolygonClient, PolygonWebSocket};
20pub use types::{Bar, Quote, Tick, Timeframe, Trade};
21
22use async_trait::async_trait;
23use futures::Stream;
24use std::pin::Pin;
25
26/// Abstract market data provider trait
27#[async_trait]
28pub trait MarketDataProvider: Send + Sync {
29    /// Get current quote for symbol
30    async fn get_quote(&self, symbol: &str) -> Result<Quote>;
31
32    /// Get historical bars
33    async fn get_bars(
34        &self,
35        symbol: &str,
36        start: chrono::DateTime<chrono::Utc>,
37        end: chrono::DateTime<chrono::Utc>,
38        timeframe: Timeframe,
39    ) -> Result<Vec<Bar>>;
40
41    /// Subscribe to real-time quotes
42    async fn subscribe_quotes(&self, symbols: Vec<String>) -> Result<QuoteStream>;
43
44    /// Subscribe to trades
45    async fn subscribe_trades(&self, symbols: Vec<String>) -> Result<TradeStream>;
46
47    /// Health check
48    async fn health_check(&self) -> Result<HealthStatus>;
49}
50
51pub type QuoteStream = Pin<Box<dyn Stream<Item = Result<Quote>> + Send>>;
52pub type TradeStream = Pin<Box<dyn Stream<Item = Result<Trade>> + Send>>;
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55pub enum HealthStatus {
56    Healthy,
57    Degraded,
58    Unhealthy,
59}
60
61#[cfg(test)]
62mod tests {
63    use super::*;
64
65    #[test]
66    fn test_module_structure() {
67        // Smoke test to ensure module compiles
68        assert_eq!(HealthStatus::Healthy, HealthStatus::Healthy);
69    }
70}