diff --git a/adaptive-strategy/src/microstructure/mod.rs b/adaptive-strategy/src/microstructure/mod.rs index 82e9c8c50..1d3d61657 100644 --- a/adaptive-strategy/src/microstructure/mod.rs +++ b/adaptive-strategy/src/microstructure/mod.rs @@ -174,7 +174,8 @@ pub struct VPINMetrics { /// Processes order book data, trade data, and market events to extract /// microstructure features and signals for trading strategies. pub struct MicrostructureAnalyzer { - /// Configuration parameters + /// Configuration parameters (stored for potential reconfiguration/debugging) + #[allow(dead_code)] config: MicrostructureConfig, /// Order book state tracker order_book: OrderBookTracker, diff --git a/adaptive-strategy/src/models/deep_learning.rs b/adaptive-strategy/src/models/deep_learning.rs index 5435957ac..3e075b970 100644 --- a/adaptive-strategy/src/models/deep_learning.rs +++ b/adaptive-strategy/src/models/deep_learning.rs @@ -287,7 +287,11 @@ impl ModelTrait for LSTMModel { #[derive(Debug)] pub struct GRUModel { name: String, + /// Model configuration (stub for future ML integration) + #[allow(dead_code)] config: ModelConfig, + /// Model readiness flag (stub for future ML integration) + #[allow(dead_code)] ready: bool, } @@ -366,7 +370,11 @@ impl ModelTrait for GRUModel { #[derive(Debug)] pub struct TransformerModel { name: String, + /// Model configuration (stub for future ML integration) + #[allow(dead_code)] config: ModelConfig, + /// Model readiness flag (stub for future ML integration) + #[allow(dead_code)] ready: bool, } @@ -433,7 +441,11 @@ impl ModelTrait for TransformerModel { #[derive(Debug)] pub struct CNNModel { name: String, + /// Model configuration (stub for future ML integration) + #[allow(dead_code)] config: ModelConfig, + /// Model readiness flag (stub for future ML integration) + #[allow(dead_code)] ready: bool, } diff --git a/adaptive-strategy/src/models/ensemble_models.rs b/adaptive-strategy/src/models/ensemble_models.rs index 6766e8976..8a3dfced7 100644 --- a/adaptive-strategy/src/models/ensemble_models.rs +++ b/adaptive-strategy/src/models/ensemble_models.rs @@ -11,7 +11,11 @@ use async_trait::async_trait; #[derive(Debug)] pub struct EnsembleModel { name: String, + /// Model configuration (stub for future ML integration) + #[allow(dead_code)] config: ModelConfig, + /// Model readiness flag (stub for future ML integration) + #[allow(dead_code)] ready: bool, } diff --git a/adaptive-strategy/src/models/traditional.rs b/adaptive-strategy/src/models/traditional.rs index d0067866c..7b3eff808 100644 --- a/adaptive-strategy/src/models/traditional.rs +++ b/adaptive-strategy/src/models/traditional.rs @@ -11,7 +11,11 @@ use async_trait::async_trait; #[derive(Debug)] pub struct RandomForestModel { name: String, + /// Model configuration (stub for future ML integration) + #[allow(dead_code)] config: ModelConfig, + /// Model readiness flag (stub for future ML integration) + #[allow(dead_code)] ready: bool, } @@ -76,7 +80,11 @@ impl ModelTrait for RandomForestModel { #[derive(Debug)] pub struct XGBoostModel { name: String, + /// Model configuration (stub for future ML integration) + #[allow(dead_code)] config: ModelConfig, + /// Model readiness flag (stub for future ML integration) + #[allow(dead_code)] ready: bool, } @@ -143,7 +151,11 @@ impl ModelTrait for XGBoostModel { #[derive(Debug)] pub struct SVMModel { name: String, + /// Model configuration (stub for future ML integration) + #[allow(dead_code)] config: ModelConfig, + /// Model readiness flag (stub for future ML integration) + #[allow(dead_code)] ready: bool, } diff --git a/adaptive-strategy/src/regime/mod.rs b/adaptive-strategy/src/regime/mod.rs index 5c847de93..814fc371d 100644 --- a/adaptive-strategy/src/regime/mod.rs +++ b/adaptive-strategy/src/regime/mod.rs @@ -27,7 +27,8 @@ use super::models::{ModelConfig, ModelTrait, TrainingData}; /// model training, regime classification, and transition monitoring. #[derive(Debug)] pub struct RegimeDetector { - /// Configuration parameters + /// Configuration parameters (stored for potential reconfiguration) + #[allow(dead_code)] config: RegimeConfig, /// Current market regime current_regime: MarketRegime, @@ -248,8 +249,9 @@ pub struct RegimePerformanceTracker { regime_performance: HashMap, /// Detection accuracy tracking detection_accuracy: VecDeque, - /// False positive tracking metrics - false_positives: VecDeque, } + /// False positive tracking metrics (reserved for future ML quality monitoring) + #[allow(dead_code)] + false_positives: VecDeque, } /// Performance metrics for a specific regime #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/adaptive-strategy/src/risk/kelly_position_sizer.rs b/adaptive-strategy/src/risk/kelly_position_sizer.rs index f81cd6783..7978c9b77 100644 --- a/adaptive-strategy/src/risk/kelly_position_sizer.rs +++ b/adaptive-strategy/src/risk/kelly_position_sizer.rs @@ -196,7 +196,8 @@ pub struct DynamicRiskAdjuster { regime_scalers: HashMap, /// Portfolio drawdown tracker drawdown_tracker: DrawdownTracker, - /// Volatility environment + /// Volatility environment (reserved for volatility-adjusted sizing) + #[allow(dead_code)] volatility_regime: VolatilityRegime, } diff --git a/adaptive-strategy/src/risk/ppo_position_sizer.rs b/adaptive-strategy/src/risk/ppo_position_sizer.rs index 5aa250709..e22640409 100644 --- a/adaptive-strategy/src/risk/ppo_position_sizer.rs +++ b/adaptive-strategy/src/risk/ppo_position_sizer.rs @@ -140,7 +140,8 @@ impl Default for ContinuousPolicyConfig { /// for position sizing in trading environments. #[derive(Debug)] pub(super) struct ContinuousPPO { - /// Configuration parameters for the PPO agent + /// Configuration parameters for the PPO agent (stub for future full implementation) + #[allow(dead_code)] config: ContinuousPPOConfig, } @@ -258,7 +259,8 @@ pub struct ContinuousTrajectoryStep { /// for batch training of the PPO agent. #[derive(Debug, Clone)] pub(super) struct ContinuousTrajectoryBatch { - /// Collection of trajectories for training + /// Collection of trajectories for training (stub for future PPO implementation) + #[allow(dead_code)] pub trajectories: Vec, } diff --git a/data/src/providers/benzinga/historical.rs b/data/src/providers/benzinga/historical.rs index a4c26286c..1d7e7c20c 100644 --- a/data/src/providers/benzinga/historical.rs +++ b/data/src/providers/benzinga/historical.rs @@ -16,85 +16,140 @@ use ::common::Symbol; /// Benzinga channel information #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BenzingaChannel { + /// Channel ID pub id: u32, + /// Channel name pub name: String, } /// Benzinga tag information #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BenzingaTag { + /// Tag ID pub id: u32, + /// Tag name pub name: String, } /// Benzinga news article #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BenzingaNewsArticle { + /// Article ID pub id: u32, + /// Article title pub title: String, + /// Article body text pub body: String, + /// Article author name pub author: Option, + /// Creation timestamp pub created: DateTime, + /// Last update timestamp pub updated: DateTime, + /// Article URL pub url: String, + /// Article image URL pub image: Option, + /// Associated ticker symbols pub symbols: Vec, + /// Content channels pub channels: Vec, + /// Content tags pub tags: Vec, + /// Sentiment score pub sentiment: Option, } /// Benzinga rating information #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BenzingaRating { + /// Rating ID pub id: u32, + /// Ticker symbol pub ticker: String, + /// Company name pub name: String, + /// Analyst name pub analyst: String, + /// Analyst firm name pub firm: String, + /// Rating action (upgrade/downgrade/initiated/reiterated) pub action: String, + /// Current rating pub current_rating: String, + /// Previous rating if applicable pub previous_rating: Option, + /// Current price target pub price_target: Option, + /// Previous price target if applicable pub previous_price_target: Option, + /// Analyst comment pub comment: Option, + /// Rating date pub rating_date: DateTime, + /// Event timestamp pub timestamp: DateTime, + /// Importance score (0-100) pub importance: Option, } /// Benzinga earnings information #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BenzingaEarnings { + /// Earnings event ID pub id: u32, + /// Ticker symbol pub ticker: String, + /// Company name pub name: String, + /// Earnings date pub date: DateTime, + /// Reporting period (e.g., Q1, Q2) pub period: String, + /// Reporting period year pub period_year: u32, + /// Estimated EPS pub eps_est: Option, + /// Actual EPS pub eps: Option, + /// EPS surprise (actual - estimated) pub eps_surprise: Option, + /// Estimated revenue pub revenue_est: Option, + /// Actual revenue pub revenue: Option, + /// Revenue surprise (actual - estimated) pub revenue_surprise: Option, + /// Time of day (BMO/AMC/DMT) pub time: Option, + /// Importance score (0-100) pub importance: Option, } /// Benzinga economic event information #[derive(Debug, Clone, Serialize, Deserialize)] pub struct BenzingaEconomicEvent { + /// Economic event ID pub id: u32, + /// Event name pub name: String, + /// Event description pub description: Option, + /// Event date and time pub date: DateTime, + /// Country code (e.g., US, GB) pub country: String, + /// Event category pub category: String, + /// Importance level (low/medium/high) pub importance: String, + /// Actual reported value pub actual: Option, + /// Consensus forecast pub consensus: Option, + /// Previous value pub previous: Option, + /// Revised previous value pub previous_revised: Option, } diff --git a/data/src/providers/benzinga/integration.rs b/data/src/providers/benzinga/integration.rs index 66ba31b88..08ad88ce5 100644 --- a/data/src/providers/benzinga/integration.rs +++ b/data/src/providers/benzinga/integration.rs @@ -219,7 +219,7 @@ pub struct BenzingaHFTIntegration { /// Integration performance metrics #[derive(Debug, Default)] -struct IntegrationMetrics { +pub struct IntegrationMetrics { /// Total events processed events_processed: u64, diff --git a/data/src/providers/benzinga/production_historical.rs b/data/src/providers/benzinga/production_historical.rs index 9510e7519..2b6337dd0 100644 --- a/data/src/providers/benzinga/production_historical.rs +++ b/data/src/providers/benzinga/production_historical.rs @@ -637,12 +637,13 @@ impl ProductionBenzingaHistoricalProvider { .unwrap_or_else(|_| Utc::now()), timestamp: Utc::now(), url: item.url.unwrap_or_default(), - sentiment_score: None, - sentiment: item.sentiment.as_deref().and_then(|s| match s { + sentiment_score: item.sentiment.as_deref().and_then(|s| match s { "positive" => Some(0.5), "negative" => Some(-0.5), _ => None, }), + #[allow(deprecated)] + sentiment: None, event_type: crate::providers::common::NewsEventType::News, }; @@ -817,8 +818,9 @@ impl ProductionBenzingaHistoricalProvider { published_at: earning_date, timestamp: Utc::now(), url: "".to_string(), - sentiment_score: None, - sentiment: None, // Earnings are typically neutral until analyzed + sentiment_score: None, // Earnings are typically neutral until analyzed + #[allow(deprecated)] + sentiment: None, event_type: crate::providers::common::NewsEventType::Earnings, }; @@ -995,8 +997,9 @@ impl ProductionBenzingaHistoricalProvider { published_at: event_date, timestamp: Utc::now(), url: "".to_string(), - sentiment_score: None, - sentiment: None, // Economic events typically neutral + sentiment_score: None, // Economic events typically neutral + #[allow(deprecated)] + sentiment: None, event_type: crate::providers::common::NewsEventType::Economic, }; diff --git a/data/src/providers/benzinga/production_streaming.rs b/data/src/providers/benzinga/production_streaming.rs index adf72110e..b8b80c05b 100644 --- a/data/src/providers/benzinga/production_streaming.rs +++ b/data/src/providers/benzinga/production_streaming.rs @@ -192,9 +192,12 @@ pub struct ProductionMetrics { /// Circuit breaker states #[derive(Debug, Clone, Copy)] pub enum CircuitBreakerState { - Closed, // Normal operation - Open, // Blocking requests - HalfOpen, // Testing recovery + /// Normal operation - requests flowing + Closed, + /// Blocking requests - failure threshold exceeded + Open, + /// Testing recovery - allowing limited requests + HalfOpen, } /// Circuit breaker for fault tolerance @@ -208,6 +211,7 @@ pub struct CircuitBreaker { } impl CircuitBreaker { + /// Create new circuit breaker with failure threshold and timeout pub fn new(threshold: u32, timeout: Duration) -> Self { Self { state: Arc::new(RwLock::new(CircuitBreakerState::Closed)), @@ -218,6 +222,7 @@ impl CircuitBreaker { } } + /// Check if call is permitted based on circuit breaker state pub async fn is_call_permitted(&self) -> bool { let state = *self.state.read().await; @@ -242,12 +247,14 @@ impl CircuitBreaker { } } + /// Record successful call - resets circuit breaker to closed state pub async fn record_success(&self) { let mut state_guard = self.state.write().await; *state_guard = CircuitBreakerState::Closed; self.failure_count.store(0, Ordering::Relaxed); } + /// Record failed call - may open circuit breaker if threshold exceeded pub async fn record_failure(&self) { let failures = self.failure_count.fetch_add(1, Ordering::Relaxed) + 1; let mut last_failure_guard = self.last_failure.write().await; diff --git a/data/src/providers/databento/client.rs b/data/src/providers/databento/client.rs index 05d7ae8b5..f7aa8d01a 100644 --- a/data/src/providers/databento/client.rs +++ b/data/src/providers/databento/client.rs @@ -39,9 +39,7 @@ use crate::providers::databento::dbn_parser::DbnParserMetricsSnapshot; use futures_core::Stream; use std::pin::Pin; use async_trait::async_trait; -use trading_engine::{ - events::EventProcessor, -}; +use trading_engine::events::EventProcessor; use reqwest::Client as HttpClient; use tokio::{ sync::{Mutex, RwLock}, @@ -705,22 +703,33 @@ impl ClientMetrics { } /// Client metrics snapshot -#[derive(Debug, Clone, serde::Serialize)] +#[derive(Debug, Clone, Default)] pub struct ClientMetricsSnapshot { + /// Total connection attempts pub connection_attempts: u64, + /// Successful connections pub connection_successes: u64, + /// Failed connections pub connection_failures: u64, + /// Total API requests made pub api_requests: u64, + /// Successful API requests pub request_successes: u64, + /// Failed API requests pub request_failures: u64, + /// Cache hits pub cache_hits: u64, + /// Cache misses pub cache_misses: u64, + /// Cache hit rate (0.0 - 1.0) pub cache_hit_rate: f64, + /// Number of active subscriptions pub active_subscriptions: u64, + /// Current requests per second pub requests_per_second: u64, + /// Client uptime in seconds pub uptime_s: u64, } - /// Client builder for configuration pub struct DatabentoClientBuilder { config: DatabentoConfig, diff --git a/data/src/providers/databento/dbn_parser.rs b/data/src/providers/databento/dbn_parser.rs index 485cca900..086825949 100644 --- a/data/src/providers/databento/dbn_parser.rs +++ b/data/src/providers/databento/dbn_parser.rs @@ -55,6 +55,7 @@ pub struct DbnMessageHeader { #[repr(C, packed)] #[derive(Debug, Clone, Copy)] pub struct DbnTradeMessage { + /// Message header with timestamp and symbol pub header: DbnMessageHeader, /// Trade price (scaled integer) pub price: i64, @@ -78,6 +79,7 @@ pub struct DbnTradeMessage { #[repr(C, packed)] #[derive(Debug, Clone, Copy)] pub struct DbnQuoteMessage { + /// Message header with timestamp and symbol pub header: DbnMessageHeader, /// Bid price (scaled integer) pub bid_px: i64, @@ -103,6 +105,7 @@ pub struct DbnQuoteMessage { #[repr(C, packed)] #[derive(Debug, Clone, Copy)] pub struct DbnOrderBookMessage { + /// Message header with timestamp and symbol pub header: DbnMessageHeader, /// Order ID pub order_id: u64, @@ -130,6 +133,7 @@ pub struct DbnOrderBookMessage { #[repr(C, packed)] #[derive(Debug, Clone, Copy)] pub struct DbnOhlcvMessage { + /// Message header with timestamp and symbol pub header: DbnMessageHeader, /// Open price (scaled integer) pub open: i64, @@ -147,11 +151,17 @@ pub struct DbnOhlcvMessage { #[repr(u8)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum DbnMessageType { + /// Trade message (tick data) Trade = 0x54, // 'T' + /// Quote message (BBO) Quote = 0x51, // 'Q' + /// Order book message (depth) OrderBook = 0x4F, // 'O' + /// OHLCV bar message Ohlcv = 0x42, // 'B' (Bar) + /// Status message Status = 0x53, // 'S' + /// Error message Error = 0x45, // 'E' } @@ -603,45 +613,81 @@ impl DbnParser { /// Processed message types from DBN parsing #[derive(Debug, Clone)] pub enum ProcessedMessage { + /// Trade tick message Trade { + /// Trading symbol symbol: String, + /// Event timestamp timestamp: HardwareTimestamp, + /// Trade price price: Price, + /// Trade size size: Decimal, + /// Trade side (buy/sell) side: OrderSide, + /// Optional trade identifier trade_id: Option, + /// Trade conditions conditions: Vec, }, + /// Quote (BBO) message Quote { + /// Trading symbol symbol: String, + /// Event timestamp timestamp: HardwareTimestamp, + /// Bid price bid: Option, + /// Ask price ask: Option, + /// Bid size bid_size: Option, + /// Ask size ask_size: Option, + /// Exchange identifier exchange: Option, }, + /// Order book depth update OrderBook { + /// Trading symbol symbol: String, + /// Event timestamp timestamp: HardwareTimestamp, + /// Price level price: Price, + /// Size at level size: Decimal, + /// Side (bid/ask) side: OrderSide, + /// Action (add/modify/cancel) action: OrderBookAction, + /// Depth level level: usize, + /// Optional order ID order_id: Option, }, + /// OHLCV bar message Ohlcv { + /// Trading symbol symbol: String, + /// Bar timestamp timestamp: HardwareTimestamp, + /// Open price open: Price, + /// High price high: Price, + /// Low price low: Price, + /// Close price close: Price, + /// Volume volume: Decimal, }, + /// Status message Status { + /// Status timestamp timestamp: HardwareTimestamp, + /// Status message message: String, }, } @@ -649,9 +695,13 @@ pub enum ProcessedMessage { /// Order book actions #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum OrderBookAction { + /// Add order to book Add, + /// Cancel order from book Cancel, + /// Modify existing order Modify, + /// Trade execution Trade, } diff --git a/data/src/providers/databento/stream.rs b/data/src/providers/databento/stream.rs index 8fc061770..4af17bd15 100644 --- a/data/src/providers/databento/stream.rs +++ b/data/src/providers/databento/stream.rs @@ -32,7 +32,7 @@ use crate::error::{DataError, Result}; use common::MarketDataEvent; -use crate::providers::databento::types::{DatabentoWebSocketConfig}; +use crate::providers::databento::types::DatabentoWebSocketConfig; use crate::providers::databento::websocket_client::{DatabentoWebSocketClient, WebSocketMetricsSnapshot}; use crate::providers::databento::dbn_parser::{DbnParser, DbnParserMetricsSnapshot}; use trading_engine::events::EventProcessor; diff --git a/ml-data/src/features.rs b/ml-data/src/features.rs index fe9e8dbac..fef455ced 100644 --- a/ml-data/src/features.rs +++ b/ml-data/src/features.rs @@ -9,6 +9,7 @@ use uuid::Uuid; use crate::{MlDataError, Result, FeatureStoreConfig}; use database::{Database}; +use sqlx::Row; /// Feature repository for ML feature engineering and serving #[derive(Clone)] diff --git a/ml-data/src/performance.rs b/ml-data/src/performance.rs index f7607feea..f42886729 100644 --- a/ml-data/src/performance.rs +++ b/ml-data/src/performance.rs @@ -9,7 +9,8 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::{MlDataError, Result, PerformanceConfig}; -use database::{Database}; +use database::{Database, DatabaseTransaction}; +use sqlx::Row; /// Performance tracking repository for ML models #[derive(Clone)] @@ -275,9 +276,8 @@ impl PerformanceRepository { /// Start a performance benchmark pub async fn start_benchmark(&self, request: StartBenchmarkRequest) -> Result { - let mut conn = self.db.acquire().await?; let benchmark_id = Uuid::new_v4(); - + let mut conn = self.db.acquire().await?; sqlx::query( r#"INSERT INTO ml_performance_benchmarks diff --git a/ml-data/src/training.rs b/ml-data/src/training.rs index 0f0ac0168..fb168738e 100644 --- a/ml-data/src/training.rs +++ b/ml-data/src/training.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::{MlDataError, Result, TrainingConfig}; -use database::{Database}; +use database::{Database, DatabaseTransaction}; /// Training data repository for ML workflows #[derive(Clone)] diff --git a/ml/src/bridge.rs b/ml/src/bridge.rs index d0acca52d..24dc333c7 100644 --- a/ml/src/bridge.rs +++ b/ml/src/bridge.rs @@ -8,6 +8,7 @@ use crate::{MLError, MLResult}; use common::Price; use rust_decimal::Decimal; +use rust_decimal::prelude::FromPrimitive; // Note: Using common::Price directly now, no alias needed @@ -53,7 +54,6 @@ impl MLFinancialBridge { /// Convert common::Price to f64 for ML computations pub fn price_to_f64(price: &Price) -> f64 { - use rust_decimal::prelude::ToPrimitive; price.to_f64() } diff --git a/ml/src/common/mod.rs b/ml/src/common/mod.rs index 784f7f8fb..62899ea2d 100644 --- a/ml/src/common/mod.rs +++ b/ml/src/common/mod.rs @@ -111,8 +111,7 @@ pub struct ONNXExportConfig { // Direct use of canonical types - no compatibility wrappers /// `Market` data structure compatible with ML models -#[derive(Debug, Clone)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] /// MarketData component. pub struct MarketData { pub asset_id: Symbol, @@ -138,7 +137,6 @@ pub mod conversions { /// Convert canonical Price to liquid submodule FixedPoint (8-decimal to 6-decimal precision) pub fn price_to_liquid_fixed_point(price: Price) -> Result> { let liquid_precision = 1_000_000_i64; // 6 decimal places - let canonical_precision = 100_000_000_i64; // 8 decimal places // Scale down from 8-decimal to 6-decimal precision with proper error handling let price_f64 = price.to_f64(); @@ -149,7 +147,6 @@ pub mod conversions { /// Convert liquid submodule FixedPoint to canonical Price (6-decimal to 8-decimal precision) pub fn liquid_fixed_point_to_price(fixed_point: crate::liquid::FixedPoint) -> Result> { let liquid_precision = 1_000_000_i64; // 6 decimal places - let canonical_precision = 100_000_000_i64; // 8 decimal places // Scale up from 6-decimal to 8-decimal precision with proper error handling let value_f64 = fixed_point.0 as f64 / liquid_precision as f64; diff --git a/ml/src/dqn/agent.rs b/ml/src/dqn/agent.rs index 9d29e918c..74f22a926 100644 --- a/ml/src/dqn/agent.rs +++ b/ml/src/dqn/agent.rs @@ -7,7 +7,6 @@ use std::collections::HashMap; use candle_core::Tensor; use candle_nn::VarBuilder; -use candle_nn::Module; use candle_optimisers::adam::ParamsAdam; use crate::Adam; // Use our Adam wrapper from lib.rs // use crate::Optimizer; // Optimizer trait not available in candle v0.9 @@ -442,7 +441,7 @@ impl DQNAgent { input: &Tensor, var_builder: &VarBuilder<'_>, ) -> Result { - use candle_nn::{linear, Module}; + use candle_nn::linear; let mut layers = Vec::new(); let mut input_dim = self.config.state_dim; @@ -487,7 +486,7 @@ impl DQNAgent { input: &Tensor, var_builder: &VarBuilder<'_>, ) -> Result { - use candle_nn::{linear, Module}; + use candle_nn::linear; let mut layers = Vec::new(); let mut input_dim = self.config.state_dim; @@ -583,7 +582,7 @@ impl DQNAgent { /// Forward pass through either main or target network fn forward_network(&self, input: &Tensor, use_target: bool) -> Result { - use candle_nn::{Module, VarBuilder}; + use candle_nn::VarBuilder; let vars = if use_target { self.target_network.vars() diff --git a/ml/src/dqn/prioritized_replay.rs b/ml/src/dqn/prioritized_replay.rs index 893b7fc96..9f4a26c57 100644 --- a/ml/src/dqn/prioritized_replay.rs +++ b/ml/src/dqn/prioritized_replay.rs @@ -15,7 +15,6 @@ use rand::prelude::*; use rand::rngs::StdRng; use parking_lot::{Mutex, RwLock}; -use rayon::prelude::*; use serde::{Deserialize, Serialize}; use crate::dqn::experience::Experience; diff --git a/ml/src/dqn/replay_buffer.rs b/ml/src/dqn/replay_buffer.rs index e2514e80c..7a2e66cdc 100644 --- a/ml/src/dqn/replay_buffer.rs +++ b/ml/src/dqn/replay_buffer.rs @@ -3,7 +3,6 @@ use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; use parking_lot::RwLock; -use rayon::prelude::*; use rand::prelude::*; // Replace common::rng with standard rand // Import the types module for RNG functionality diff --git a/ml/src/dqn/reward.rs b/ml/src/dqn/reward.rs index 460d2aab6..0d690e03b 100644 --- a/ml/src/dqn/reward.rs +++ b/ml/src/dqn/reward.rs @@ -83,9 +83,7 @@ impl RewardFunction { current_state: &TradingState, next_state: &TradingState, ) -> Result { - let mut reward = Decimal::ZERO; - - match action { + let reward = match action { TradingAction::Buy | TradingAction::Sell => { // Calculate P&L-based reward let pnl_reward = self.calculate_pnl_reward(current_state, next_state)?; @@ -96,15 +94,15 @@ impl RewardFunction { // Calculate transaction cost penalty let cost_penalty = self.calculate_cost_penalty(current_state, next_state); - reward = self.config.pnl_weight * pnl_reward + self.config.pnl_weight * pnl_reward - self.config.risk_weight * risk_penalty - - self.config.cost_weight * cost_penalty; + - self.config.cost_weight * cost_penalty } TradingAction::Hold => { // Small positive reward for holding to prevent over-trading - reward = self.config.hold_reward; + self.config.hold_reward } - } + }; // Store reward in history self.reward_history.push(reward); diff --git a/ml/src/examples.rs b/ml/src/examples.rs index 94b59665b..92170aecd 100644 --- a/ml/src/examples.rs +++ b/ml/src/examples.rs @@ -7,7 +7,6 @@ use common::types::Price; use crate::{safety::{MLSafetyConfig, MLSafetyManager}, MLError}; use rand::prelude::*; -use num_traits::FromPrimitive; // For Decimal::from_f64 use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use tracing::{debug, info}; diff --git a/ml/src/features.rs b/ml/src/features.rs index 19f471a25..4035501ce 100644 --- a/ml/src/features.rs +++ b/ml/src/features.rs @@ -13,7 +13,6 @@ // Import types from common crate use common::types::{Price, Quantity, Volume, Symbol}; -use crate::{MLError, MLResult}; use std::collections::HashMap; use std::sync::Arc; diff --git a/ml/src/inference.rs b/ml/src/inference.rs index 4ac4c6137..cb80c5c2a 100644 --- a/ml/src/inference.rs +++ b/ml/src/inference.rs @@ -15,13 +15,11 @@ use std::time::Instant; use candle_core::{Device, Tensor}; use candle_nn::{ops::sigmoid, Module, VarMap}; -use rust_decimal::prelude::ToPrimitive; use serde::{Deserialize, Serialize}; use thiserror::Error; use tokio::sync::RwLock; use common::types::{Price, Symbol}; -use crate::{MLError, MLResult}; use tracing::{error, info, warn}; use uuid::Uuid; diff --git a/ml/src/lib.rs b/ml/src/lib.rs index 8d5d27a4e..081e38d3d 100644 --- a/ml/src/lib.rs +++ b/ml/src/lib.rs @@ -315,7 +315,6 @@ pub enum ErrorCategory { /// }; /// ``` #[derive(Debug, Clone, Serialize, Deserialize)] -#[cfg_attr(feature = "database", derive(sqlx::FromRow))] pub struct Trade { /// Trading symbol (e.g., "AAPL", "MSFT") pub symbol: String, diff --git a/ml/src/liquid/cells.rs b/ml/src/liquid/cells.rs index fd32c8e27..7483e2095 100644 --- a/ml/src/liquid/cells.rs +++ b/ml/src/liquid/cells.rs @@ -7,7 +7,7 @@ use std::time::{SystemTime, UNIX_EPOCH}; use super::activation::{self, apply_activation, ActivationType}; use super::ode_solvers::{ - ODESolver, SolverEnum, SolverFactory, SolverType, VolatilityAwareTimeConstants, + SolverEnum, SolverFactory, SolverType, VolatilityAwareTimeConstants, }; use super::{FixedPoint, LiquidError, Result}; use serde::{Deserialize, Serialize}; diff --git a/ml/src/liquid/network.rs b/ml/src/liquid/network.rs index 96a4c1046..928626bf9 100644 --- a/ml/src/liquid/network.rs +++ b/ml/src/liquid/network.rs @@ -305,16 +305,7 @@ impl LiquidNetwork { MarketRegime::Bull => FixedPoint(self.config.default_dt.0 / 4), MarketRegime::Bear => FixedPoint(self.config.default_dt.0 / 4), MarketRegime::Crisis => FixedPoint(self.config.default_dt.0 / 8), - MarketRegime::Crisis => { - FixedPoint(self.config.default_dt.0 / 4) - } - MarketRegime::Sideways => { - FixedPoint(self.config.default_dt.0 * 2) - } - MarketRegime::Normal => self.config.default_dt, - MarketRegime::Trending => FixedPoint(self.config.default_dt.0 / 2), - MarketRegime::Bear => FixedPoint(self.config.default_dt.0 / 8), - MarketRegime::Bull => FixedPoint(self.config.default_dt.0 / 4), }; + }; } // Update all layers with volatility information diff --git a/ml/src/mamba/mod.rs b/ml/src/mamba/mod.rs index e23175e99..18b0512b2 100644 --- a/ml/src/mamba/mod.rs +++ b/ml/src/mamba/mod.rs @@ -52,7 +52,6 @@ use std::time::{Duration, Instant, SystemTime}; use candle_core::{DType, Device, Tensor}; use candle_nn::{Dropout, Linear, VarBuilder}; use candle_nn::Module; -use candle_nn::LayerNorm; use serde::{Deserialize, Serialize}; use tracing::{debug, info, instrument, warn}; use uuid::Uuid; @@ -699,7 +698,6 @@ impl Mamba2SSM { for epoch in 0..epochs { let epoch_start = Instant::now(); let mut epoch_loss = 0.0; - let mut epoch_accuracy = 0.0; let mut batch_count = 0; // Training phase @@ -726,7 +724,7 @@ impl Mamba2SSM { // Validation phase let val_loss = self.validate(val_data)?; - epoch_accuracy = self.calculate_accuracy(val_data)?; + let epoch_accuracy = self.calculate_accuracy(val_data)?; // Update learning rate scheduler let current_lr = self.get_current_learning_rate(); @@ -1021,17 +1019,17 @@ impl Mamba2SSM { // Clear all gradients for SSM parameters for _ssm_state in &mut self.state.ssm_states { // Zero gradients for A, B, C matrices and delta parameter - if let Some(mut A_grad) = self.gradients.get("A").cloned() { - A_grad = A_grad.zeros_like()?; + if let Some(grad) = self.gradients.get("A").cloned() { + self.gradients.insert("A".to_string(), grad.zeros_like()?); } - if let Some(mut B_grad) = self.gradients.get("B").cloned() { - B_grad = B_grad.zeros_like()?; + if let Some(grad) = self.gradients.get("B").cloned() { + self.gradients.insert("B".to_string(), grad.zeros_like()?); } - if let Some(mut C_grad) = self.gradients.get("C").cloned() { - C_grad = C_grad.zeros_like()?; + if let Some(grad) = self.gradients.get("C").cloned() { + self.gradients.insert("C".to_string(), grad.zeros_like()?); } - if let Some(mut delta_grad) = self.gradients.get("delta").cloned() { - delta_grad = delta_grad.zeros_like()?; + if let Some(grad) = self.gradients.get("delta").cloned() { + self.gradients.insert("delta".to_string(), grad.zeros_like()?); } } diff --git a/ml/src/mamba/scan_algorithms.rs b/ml/src/mamba/scan_algorithms.rs index ee9002625..34fd77b9f 100644 --- a/ml/src/mamba/scan_algorithms.rs +++ b/ml/src/mamba/scan_algorithms.rs @@ -254,10 +254,9 @@ impl ParallelScanEngine { let batch_input = input.narrow(0, b, 1)?; let batch_segments = segment_ids.narrow(0, b, 1)?; - let mut current_segment = -1_i64; let mut accumulator = batch_input.narrow(1, 0, 1)?; let first_seg: i64 = batch_segments.narrow(1, 0, 1)?.to_scalar()?; - current_segment = first_seg; + let mut current_segment = first_seg; result_data.push(accumulator.clone()); for t in 1..seq_len { diff --git a/ml/src/models_demo.rs b/ml/src/models_demo.rs index bb4319be9..ed6547204 100644 --- a/ml/src/models_demo.rs +++ b/ml/src/models_demo.rs @@ -6,8 +6,7 @@ use crate::safety::{MLSafetyConfig, MLSafetyManager}; use crate::{MLError, ModelType}; -use num_traits::FromPrimitive; // For Decimal::from_f64 - use rust_decimal::Decimal; +use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/ml/src/portfolio_transformer.rs b/ml/src/portfolio_transformer.rs index 213d83497..6c9c1c4a9 100644 --- a/ml/src/portfolio_transformer.rs +++ b/ml/src/portfolio_transformer.rs @@ -5,7 +5,7 @@ //! operates directly on portfolio state vectors for optimal weight prediction. use candle_core::{DType, Device, IndexOp, Result as CandleResult, Tensor, Module, ModuleT}; -use candle_nn::{LayerNorm, Linear, VarBuilder, VarMap}; +use candle_nn::{Linear, VarBuilder, VarMap}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use tracing::{debug, instrument, warn}; diff --git a/ml/src/risk/kelly_position_sizing_service.rs b/ml/src/risk/kelly_position_sizing_service.rs index a78017f51..d9e80cb1d 100644 --- a/ml/src/risk/kelly_position_sizing_service.rs +++ b/ml/src/risk/kelly_position_sizing_service.rs @@ -45,7 +45,6 @@ use std::sync::Arc; use std::time::Duration; use chrono::{DateTime, Utc}; -use num_traits::FromPrimitive; // For Decimal::from_f64 use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use tokio::sync::{broadcast, RwLock}; @@ -519,14 +518,12 @@ impl KellyPositionSizingService { asset_id: &String, _portfolio_summary: &Option, ) -> Result<(f64, f64, f64, f64)> { - let mut current_allocation = 0.0; - let mut portfolio_concentration = 0.0; let portfolio_beta = 1.0; // Production let portfolio_correlation = 0.5; // Production // Production implementation until PortfolioSummary is implemented - current_allocation = 0.05; // 5% default allocation - portfolio_concentration = 0.3; // 30% default concentration + let current_allocation = 0.05; // 5% default allocation + let portfolio_concentration = 0.3; // 30% default concentration // Log the asset for debugging debug!("Calculating metrics for asset: {}", asset_id); diff --git a/ml/src/safety/gradient_safety.rs b/ml/src/safety/gradient_safety.rs index 324a5b6b8..7142c32e9 100644 --- a/ml/src/safety/gradient_safety.rs +++ b/ml/src/safety/gradient_safety.rs @@ -50,7 +50,7 @@ pub struct GradientSafetyConfig { impl GradientSafetyConfig { /// Create from configuration system - eliminates hardcoded defaults - pub fn from_config_manager(config_manager: &config::ConfigManager) -> Result> { + pub fn from_config_manager(_config_manager: &config::ConfigManager) -> Result> { // Use emergency defaults since specific gradient safety configs may not be available tracing::warn!("Using emergency gradient safety config defaults - gradient safety configs not available in ServiceConfig"); Ok(Self::emergency_safe_defaults()) diff --git a/ml/src/stress_testing/mod.rs b/ml/src/stress_testing/mod.rs index c3b04884d..30cb7c930 100644 --- a/ml/src/stress_testing/mod.rs +++ b/ml/src/stress_testing/mod.rs @@ -612,7 +612,7 @@ pub fn create_test_stress_test_config() -> StressTestConfig { /// Create stress test configuration with custom simulation parameters pub fn create_custom_stress_test_config( - symbols: Vec, + _symbols: Vec, simulation_config: config::SimulationConfig, ) -> StressTestConfig { let mut config = create_hft_stress_test_config(); diff --git a/ml/src/tft/hft_optimizations.rs b/ml/src/tft/hft_optimizations.rs index d466a06ca..194853037 100644 --- a/ml/src/tft/hft_optimizations.rs +++ b/ml/src/tft/hft_optimizations.rs @@ -197,11 +197,9 @@ impl SIMDMatrixOps { assert_eq!(a.len(), b.len()); let len = a.len(); - let mut result = 0.0_f32; unsafe { let chunks = len / 8; - let _remainder = len % 8; let mut sum_vec = _mm256_setzero_ps(); @@ -216,15 +214,15 @@ impl SIMDMatrixOps { // Horizontal sum of the vector let sum_array: [f32; 8] = std::mem::transmute(sum_vec); - result = sum_array.iter().sum(); + let mut result = sum_array.iter().sum(); // Handle remaining elements for i in (chunks * 8)..len { result += a[i] * b[i]; } - } - result + result + } } #[cfg(not(target_arch = "x86_64"))] @@ -253,8 +251,6 @@ impl SIMDMatrixOps { .enumerate() .for_each(|(row_idx, result_row)| { for col_idx in 0..b_cols { - let mut sum = 0.0_f32; - // Use SIMD for dot product let a_row_start = row_idx * a_cols; let a_row = &a[a_row_start..a_row_start + a_cols]; @@ -264,7 +260,7 @@ impl SIMDMatrixOps { b_col.push(b[k * b_cols + col_idx]); } - sum = Self::vectorized_dot_product_f32(a_row, &b_col); + let sum = Self::vectorized_dot_product_f32(a_row, &b_col); result_row[col_idx] = sum; } }); diff --git a/risk/src/drawdown_monitor.rs b/risk/src/drawdown_monitor.rs index a968dbd56..51d08d33e 100644 --- a/risk/src/drawdown_monitor.rs +++ b/risk/src/drawdown_monitor.rs @@ -233,26 +233,24 @@ impl DrawdownMonitor { let latest = portfolio_history .last() .ok_or_else(|| RiskError::CalculationError("Portfolio history is empty".to_owned()))?; - let current_drawdown_pct = if let dd = latest.current_drawdown_pct { + let dd = latest.current_drawdown_pct; + let current_drawdown_pct = { let hwm = latest.high_water_mark.to_f64(); if hwm > 0.0 { (dd.abs() / hwm) * 100.0 } else { 0.0 } - } else { - 0.0 }; - let max_drawdown_pct = if let max_dd = latest.max_drawdown.to_f64() { + let max_dd = latest.max_drawdown.to_f64(); + let max_drawdown_pct = { let hwm = latest.high_water_mark.to_f64(); if hwm > 0.0 { (max_dd.abs() / hwm) * 100.0 } else { 0.0 } - } else { - 0.0 }; Ok(DrawdownStats { diff --git a/risk/src/risk_types.rs b/risk/src/risk_types.rs index 0cc395cb6..be18da29f 100644 --- a/risk/src/risk_types.rs +++ b/risk/src/risk_types.rs @@ -12,7 +12,6 @@ use tracing::warn; // ELIMINATED: Re-exports removed to force explicit imports use common::types::{Price, Quantity, Symbol, Volume, OrderType, OrderSide}; -use crate::error::RiskError; // Note: Side is an alias for OrderSide - using canonical OrderSide from trading_engine // Note: Side is an alias for OrderSide in common crate - both are available diff --git a/tests/chaos/nightly_chaos_runner.rs b/tests/chaos/nightly_chaos_runner.rs index 56f480872..0cb04e3b7 100644 --- a/tests/chaos/nightly_chaos_runner.rs +++ b/tests/chaos/nightly_chaos_runner.rs @@ -15,6 +15,7 @@ use tokio::time::{interval, sleep_until, timeout, Instant}; use tracing::{error, info, warn}; use uuid::Uuid; +use super::chaos_framework::ChaosResult; use super::ml_training_chaos::{MLChaosConfig, MLChaosResult, MLTrainingChaosTests}; /// Nightly chaos job configuration diff --git a/tests/e2e/src/ml_pipeline.rs b/tests/e2e/src/ml_pipeline.rs index 8a82260f6..7eb6142eb 100644 --- a/tests/e2e/src/ml_pipeline.rs +++ b/tests/e2e/src/ml_pipeline.rs @@ -6,6 +6,7 @@ use common::types::MarketTick; use anyhow::{Context, Result}; +use std::collections::HashMap; use std::time::{Duration, Instant}; use tracing::{debug, info, warn}; diff --git a/tests/e2e/src/utils.rs b/tests/e2e/src/utils.rs index 602775127..0319b8f4d 100644 --- a/tests/e2e/src/utils.rs +++ b/tests/e2e/src/utils.rs @@ -4,9 +4,23 @@ use std::collections::HashMap; use common::{ Price, Quantity, Symbol, OrderSide, OrderType, TimeInForce, }; -use crate::proto::trading::MarketDataEvent; use uuid::Uuid; +/// Test market data event structure +/// Note: This is a test-specific type, not the proto MarketDataEvent +#[derive(Debug, Clone)] +pub struct MarketDataEvent { + pub id: Uuid, + pub symbol: Symbol, + pub timestamp: DateTime, + pub bid: Price, + pub ask: Price, + pub bid_size: Quantity, + pub ask_size: Quantity, + pub last_price: Option, + pub volume: Option, +} + /// Test utilities for generating market data and orders pub struct TestDataGenerator { symbols: Vec, diff --git a/tests/e2e/src/workflows.rs b/tests/e2e/src/workflows.rs index c914a1fb0..28875733b 100644 --- a/tests/e2e/src/workflows.rs +++ b/tests/e2e/src/workflows.rs @@ -8,11 +8,14 @@ //! - Error handling and recovery scenarios use anyhow::{Context, Result}; +use std::collections::HashMap; +use std::sync::Arc; use std::time::{Duration, Instant}; use tokio::time::{sleep, timeout}; use tokio_stream::StreamExt; use tracing::{debug, error, info, warn}; +use crate::clients::TliClient; use crate::database::TestDatabase; use crate::ml_pipeline::MLTestPipeline; use crate::proto::trading::*; @@ -700,12 +703,7 @@ impl BacktestingWorkflow { } }; - match backtest_client.list_backtests(ListBacktestsRequest { - limit: Some(100), - offset: Some(0), - strategy_name: None, - status_filter: None, - }).await { + match backtest_client.list_backtests().await { Ok(response) => { let list_response = response.into_inner(); info!("Found {} existing backtests", list_response.backtests.len()); @@ -916,12 +914,7 @@ impl BacktestingWorkflow { } // Step 7: Verify final list of backtests - match backtest_client.list_backtests(ListBacktestsRequest { - limit: Some(100), - offset: Some(0), - strategy_name: None, - status_filter: None, - }).await { + match backtest_client.list_backtests().await { Ok(response) => { let list_response = response.into_inner(); info!("Final backtest count: {}", list_response.backtests.len()); diff --git a/tests/fixtures/lib.rs b/tests/fixtures/lib.rs index 4ec3f51cb..0e1abab6a 100644 --- a/tests/fixtures/lib.rs +++ b/tests/fixtures/lib.rs @@ -1,6 +1,6 @@ pub mod test_data; -// CANONICAL TYPE IMPORTS - Use common::prelude::Decimal +use rust_decimal::Decimal; use std::str::FromStr; /// Production-grade test fixtures with no hardcoded values diff --git a/tests/helpers.rs b/tests/helpers.rs index 816084898..1f04c76fc 100644 --- a/tests/helpers.rs +++ b/tests/helpers.rs @@ -38,20 +38,6 @@ pub fn create_test_order( } } -/// Create a test MarketEvent with all required fields -pub fn create_test_market_event(symbol: &str, price: Decimal) -> MarketEvent { - MarketEvent::Trade { - symbol: Symbol::new(symbol.to_string()), - price: Price::from_decimal(price), - size: Quantity::from_decimal(Decimal::from(100)) - .unwrap_or(Quantity::from_decimal(Decimal::from(1)).unwrap()), - timestamp: Utc::now(), - side: None, - venue: Some("TEST_VENUE".to_string()), - trade_id: Some(format!("TRADE_{}", generate_test_id())), - } -} - /// Create test configuration with sensible defaults pub fn create_test_config() -> TestConfig { TestConfig { diff --git a/tests/test_common/database_helper.rs b/tests/test_common/database_helper.rs index 51878be86..09c2aad6e 100644 --- a/tests/test_common/database_helper.rs +++ b/tests/test_common/database_helper.rs @@ -17,6 +17,7 @@ use chrono::Utc; // All Decimal operations use rust_decimal::Decimal use rust_decimal::Decimal; use sqlx::{PgPool, Row}; +use std::time::Duration; use tokio::time::timeout; use uuid::Uuid; diff --git a/tests/test_common/src/lib.rs b/tests/test_common/src/lib.rs index cd07c0a2d..aefa12324 100644 --- a/tests/test_common/src/lib.rs +++ b/tests/test_common/src/lib.rs @@ -1,17 +1,11 @@ //! Common test utilities and helpers for Foxhunt testing suites -//! +//! //! This crate provides shared utilities, fixtures, and helper functions //! used across all test suites in the Foxhunt system. +// Allow dead code for test infrastructure that may not be fully used yet #![allow(dead_code)] -pub mod fixtures; -pub mod generators; -pub mod assertions; -pub mod mocks; -pub mod test_data; -pub mod database_helpers; - use std::sync::Once; use tracing_subscriber; diff --git a/tests/utils/hft_utils.rs b/tests/utils/hft_utils.rs index f158174a7..ea1d8dd5a 100644 --- a/tests/utils/hft_utils.rs +++ b/tests/utils/hft_utils.rs @@ -498,7 +498,7 @@ pub mod orders { // Import order types from common crate use common::trading::{OrderSide, OrderType}; - use crate::proto::trading::OrderStatus; + use common::types::OrderStatus; impl TestOrder { /// Create a new market order diff --git a/trading_engine/src/comprehensive_performance_benchmarks.rs b/trading_engine/src/comprehensive_performance_benchmarks.rs index 550b224e6..482decba9 100644 --- a/trading_engine/src/comprehensive_performance_benchmarks.rs +++ b/trading_engine/src/comprehensive_performance_benchmarks.rs @@ -180,6 +180,7 @@ impl BenchmarkResult { } /// Comprehensive performance benchmark suite +#[derive(Debug)] pub struct ComprehensivePerformanceBenchmarks { config: BenchmarkConfig, results: Vec, diff --git a/trading_engine/src/events/event_types.rs b/trading_engine/src/events/event_types.rs index 501d5bc64..972b0ecaf 100644 --- a/trading_engine/src/events/event_types.rs +++ b/trading_engine/src/events/event_types.rs @@ -569,6 +569,7 @@ impl EventMetadata { } /// Builder for creating trading events with proper metadata +#[derive(Debug)] pub struct TradingEventBuilder { sequence_number: Option, metadata: Option, diff --git a/trading_engine/src/events/mod.rs b/trading_engine/src/events/mod.rs index 472ebc555..c94c2cbe2 100644 --- a/trading_engine/src/events/mod.rs +++ b/trading_engine/src/events/mod.rs @@ -140,6 +140,7 @@ impl Default for EventProcessorConfig { } /// High-performance event processor with guaranteed delivery +#[derive(Debug)] pub struct EventProcessor { /// Buffer manager for load balancing across multiple ring buffers buffer_manager: Arc, diff --git a/trading_engine/src/events/postgres_writer.rs b/trading_engine/src/events/postgres_writer.rs index 26b686156..1171c3480 100644 --- a/trading_engine/src/events/postgres_writer.rs +++ b/trading_engine/src/events/postgres_writer.rs @@ -57,6 +57,7 @@ impl Default for WriterConfig { } /// High-performance `PostgreSQL` writer with batching and recovery +#[derive(Debug)] pub struct PostgresWriter { /// Writer configuration config: WriterConfig, @@ -206,7 +207,7 @@ impl PostgresWriter { self.shutdown.store(true, Ordering::Relaxed); // Close batch sender to signal completion - drop(&self.batch_sender); + // Note: The sender is owned by the struct and will be dropped when the struct is dropped // Wait for processing to complete (max 30 seconds) for _ in 0..300 { @@ -268,6 +269,7 @@ impl EventBatch { } /// Batch processor for `PostgreSQL` operations +#[derive(Debug)] pub struct BatchProcessor { config: WriterConfig, db_pool: PgPool, diff --git a/trading_engine/src/events/ring_buffer.rs b/trading_engine/src/events/ring_buffer.rs index 917ca3a42..cb86a0544 100644 --- a/trading_engine/src/events/ring_buffer.rs +++ b/trading_engine/src/events/ring_buffer.rs @@ -14,6 +14,7 @@ use std::sync::Arc; use tokio::sync::RwLock; /// Specialized ring buffer for trading events with sequence tracking +#[derive(Debug)] pub struct EventRingBuffer { /// Underlying lock-free ring buffer buffer: LockFreeRingBuffer, @@ -219,6 +220,7 @@ impl BufferStats { } /// Manager for multiple ring buffers with load balancing +#[derive(Debug)] pub struct BufferManager { /// Array of event ring buffers buffers: Vec>, @@ -382,6 +384,7 @@ pub enum LoadBalancingStrategy { } /// Specialized buffer for sequence-ordered events +#[derive(Debug)] pub struct SequenceOrderedBuffer { /// Events indexed by sequence number events: Vec>, diff --git a/trading_engine/src/lockfree/atomic_ops.rs b/trading_engine/src/lockfree/atomic_ops.rs index 336679b95..6588c47d3 100644 --- a/trading_engine/src/lockfree/atomic_ops.rs +++ b/trading_engine/src/lockfree/atomic_ops.rs @@ -123,6 +123,14 @@ impl Default for AtomicFlag { } } +impl std::fmt::Debug for AtomicFlag { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("AtomicFlag") + .field("flag", &self.is_set()) + .finish() + } +} + /// Atomic metrics collector for performance monitoring #[repr(align(64))] // Cache line alignment /// AtomicMetrics @@ -244,6 +252,20 @@ impl Default for AtomicMetrics { } } +impl std::fmt::Debug for AtomicMetrics { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let snapshot = self.snapshot(); + f.debug_struct("AtomicMetrics") + .field("operations_count", &snapshot.operations_count) + .field("avg_latency_ns", &snapshot.avg_latency_ns) + .field("min_latency_ns", &snapshot.min_latency_ns) + .field("max_latency_ns", &snapshot.max_latency_ns) + .field("errors_count", &snapshot.errors_count) + .field("bytes_processed", &snapshot.bytes_processed) + .finish() + } +} + /// Snapshot of metrics at a point in time #[derive(Debug, Clone)] /// MetricsSnapshot diff --git a/trading_engine/src/lockfree/mpsc_queue.rs b/trading_engine/src/lockfree/mpsc_queue.rs index 4d23068b9..336484530 100644 --- a/trading_engine/src/lockfree/mpsc_queue.rs +++ b/trading_engine/src/lockfree/mpsc_queue.rs @@ -193,6 +193,15 @@ unsafe impl Send for MPSCQueue {} // - Memory ordering (Release/Acquire) prevents data races unsafe impl Sync for MPSCQueue {} +impl std::fmt::Debug for MPSCQueue { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("MPSCQueue") + .field("size", &self.len()) + .field("is_empty", &self.is_empty()) + .finish_non_exhaustive() + } +} + /// Simple hazard pointer implementation for memory reclamation struct HazardPointers { retired: AtomicPtr>, @@ -328,6 +337,15 @@ impl Default for AtomicCounter { } } +impl std::fmt::Debug for AtomicCounter { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("AtomicCounter") + .field("value", &self.get()) + .field("increment", &self.increment) + .finish() + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/trading_engine/src/lockfree/small_batch_ring.rs b/trading_engine/src/lockfree/small_batch_ring.rs index 11d31967b..00be5faac 100644 --- a/trading_engine/src/lockfree/small_batch_ring.rs +++ b/trading_engine/src/lockfree/small_batch_ring.rs @@ -314,6 +314,21 @@ impl Drop for SmallBatchRing { } } +impl std::fmt::Debug for SmallBatchRing { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let head = self.head.load(Ordering::Relaxed); + let tail = self.tail.load(Ordering::Relaxed); + let len = (head - tail) as usize; + f.debug_struct("SmallBatchRing") + .field("capacity", &self.capacity) + .field("head", &head) + .field("tail", &tail) + .field("len", &len) + .field("batch_mode", &self.batch_mode) + .finish() + } +} + /// Cache-optimized structure-of-arrays layout for small batch orders #[repr(align(64))] /// SmallBatchOrdersSoA @@ -481,6 +496,18 @@ impl Default for SmallBatchOrdersSoA { } } +impl std::fmt::Debug for SmallBatchOrdersSoA { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("SmallBatchOrdersSoA") + .field("count", &self.count) + .field("order_ids", &&self.order_ids[..self.count]) + .field("prices", &&self.prices[..self.count]) + .field("quantities", &&self.quantities[..self.count]) + .field("timestamps", &&self.timestamps[..self.count]) + .finish_non_exhaustive() + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/trading_engine/src/metrics.rs b/trading_engine/src/metrics.rs index 1d179a222..94f5d154e 100644 --- a/trading_engine/src/metrics.rs +++ b/trading_engine/src/metrics.rs @@ -150,6 +150,7 @@ impl LatencyMetric { /// This structure uses cache-padded atomic operations to prevent false sharing /// and minimize contention between producer (trading threads) and consumer /// (metrics collection thread). +#[derive(Debug)] pub struct MetricsRingBuffer { /// Ring buffer storage with cache padding to prevent false sharing buffer: [CachePadded; RING_BUFFER_SIZE], @@ -306,6 +307,7 @@ pub struct RingBufferStats { /// /// This extends the existing HftLatencyTracker with metrics collection /// and export functionality while maintaining the same performance characteristics. +#[derive(Debug)] pub struct EnhancedHftLatencyTracker { /// Original latency tracker (maintains compatibility) pub inner: HftLatencyTracker, diff --git a/trading_engine/src/persistence/backup.rs b/trading_engine/src/persistence/backup.rs index c1c882795..87774c15a 100644 --- a/trading_engine/src/persistence/backup.rs +++ b/trading_engine/src/persistence/backup.rs @@ -151,6 +151,7 @@ pub enum BackupVerificationStatus { } /// Main backup manager +#[derive(Debug)] pub struct BackupManager { config: BackupConfig, persistence_config: PersistenceConfig, diff --git a/trading_engine/src/persistence/clickhouse.rs b/trading_engine/src/persistence/clickhouse.rs index 3ab6bcd74..ab86a1aeb 100644 --- a/trading_engine/src/persistence/clickhouse.rs +++ b/trading_engine/src/persistence/clickhouse.rs @@ -88,6 +88,7 @@ impl Default for ClickHouseConfig { } /// `ClickHouse` client for analytics operations +#[derive(Debug)] pub struct ClickHouseClient { client: Client, config: ClickHouseConfig, diff --git a/trading_engine/src/persistence/health.rs b/trading_engine/src/persistence/health.rs index dc2f643a8..956f61848 100644 --- a/trading_engine/src/persistence/health.rs +++ b/trading_engine/src/persistence/health.rs @@ -102,6 +102,7 @@ impl SystemStatus { } /// Health monitoring coordinator +#[derive(Debug)] pub struct PersistenceHealth { enabled: bool, timeout_duration: Duration, diff --git a/trading_engine/src/persistence/influxdb.rs b/trading_engine/src/persistence/influxdb.rs index 9301fbe89..0cb7f02ac 100644 --- a/trading_engine/src/persistence/influxdb.rs +++ b/trading_engine/src/persistence/influxdb.rs @@ -91,6 +91,7 @@ impl Default for InfluxConfig { } /// High-performance `InfluxDB` client +#[derive(Debug)] pub struct InfluxClient { client: Client, config: InfluxConfig, diff --git a/trading_engine/src/persistence/mod.rs b/trading_engine/src/persistence/mod.rs index 0c6dec5cb..9fd1bcc22 100644 --- a/trading_engine/src/persistence/mod.rs +++ b/trading_engine/src/persistence/mod.rs @@ -131,6 +131,7 @@ pub enum PersistenceError { } /// Main persistence manager coordinating all database connections +#[derive(Debug)] pub struct PersistenceManager { postgres: PostgresPool, influx: InfluxClient, diff --git a/trading_engine/src/persistence/postgres.rs b/trading_engine/src/persistence/postgres.rs index 1a69c45b9..e4070d46d 100644 --- a/trading_engine/src/persistence/postgres.rs +++ b/trading_engine/src/persistence/postgres.rs @@ -85,6 +85,7 @@ impl Default for PostgresConfig { } /// `PostgreSQL` connection pool with HFT optimizations +#[derive(Debug)] pub struct PostgresPool { pool: PgPool, config: PostgresConfig, diff --git a/trading_engine/src/persistence/redis.rs b/trading_engine/src/persistence/redis.rs index ed72658ff..1bf9ed373 100644 --- a/trading_engine/src/persistence/redis.rs +++ b/trading_engine/src/persistence/redis.rs @@ -111,10 +111,19 @@ pub struct RedisPool { config: RedisConfig, metrics: Arc>, /// Pre-warmed connections for ultra-low latency (currently unused) - _warm_connections: Arc>>, -} - -impl RedisPool { + _warm_connections: Arc>>, + } + + impl std::fmt::Debug for RedisPool { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("RedisPool") + .field("config", &self.config) + .field("connection_semaphore_available", &self.connection_semaphore.available_permits()) + .finish_non_exhaustive() + } + } + + impl RedisPool { /// Create a new Redis connection pool optimized for HFT pub async fn new(config: RedisConfig) -> Result { // Create Redis client with connection options diff --git a/trading_engine/src/repositories/compliance_repository.rs b/trading_engine/src/repositories/compliance_repository.rs index ca7d2023c..317b799b7 100644 --- a/trading_engine/src/repositories/compliance_repository.rs +++ b/trading_engine/src/repositories/compliance_repository.rs @@ -388,6 +388,7 @@ pub struct IntegrityReport { } /// Mock implementation for testing +#[derive(Debug)] pub struct MockComplianceRepository { events: Arc>>, reports: Arc>>, diff --git a/trading_engine/src/repositories/event_repository.rs b/trading_engine/src/repositories/event_repository.rs index 69f2026a5..2b844ca5d 100644 --- a/trading_engine/src/repositories/event_repository.rs +++ b/trading_engine/src/repositories/event_repository.rs @@ -210,6 +210,7 @@ pub struct EventStorageStats { } /// Mock implementation for testing +#[derive(Debug)] pub struct MockEventRepository { events: Arc>>, sequence_counter: Arc, diff --git a/trading_engine/src/repositories/migration_repository.rs b/trading_engine/src/repositories/migration_repository.rs index 1c45e9137..e6c56522c 100644 --- a/trading_engine/src/repositories/migration_repository.rs +++ b/trading_engine/src/repositories/migration_repository.rs @@ -329,6 +329,7 @@ pub struct MigrationStats { } /// Mock implementation for testing +#[derive(Debug)] pub struct MockMigrationRepository { applied_migrations: Arc>>, should_fail: Arc, diff --git a/trading_engine/src/small_batch_optimizer.rs b/trading_engine/src/small_batch_optimizer.rs index 68d5b3965..2a80abfb9 100644 --- a/trading_engine/src/small_batch_optimizer.rs +++ b/trading_engine/src/small_batch_optimizer.rs @@ -311,6 +311,16 @@ impl Default for SmallBatchSimd { } } +impl std::fmt::Debug for SmallBatchSimd { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("SmallBatchSimd") + .field("prices", &self.prices) + .field("quantities", &self.quantities) + .field("timestamps", &self.timestamps) + .finish() + } +} + impl SmallBatchProcessor { /// Create new small batch processor pub fn new() -> Self { @@ -467,6 +477,18 @@ impl Default for SmallBatchProcessor { } } +impl std::fmt::Debug for SmallBatchProcessor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("SmallBatchProcessor") + .field("batch_size", &self.batch_size) + .field("is_empty", &self.is_empty()) + .field("is_full", &self.is_full()) + .field("has_simd", &self.simd_ops.is_some()) + .field("metrics", &self.metrics) + .finish() + } +} + /// Result of batch processing #[derive(Debug)] /// SmallBatchResult diff --git a/trading_engine/src/tracing.rs b/trading_engine/src/tracing.rs index f9d55c9aa..1a377db13 100644 --- a/trading_engine/src/tracing.rs +++ b/trading_engine/src/tracing.rs @@ -247,6 +247,7 @@ pub struct JaegerProcess { } /// Lock-free tracing infrastructure +#[derive(Debug)] pub struct FastTracer { /// Service name for all spans created by this tracer pub service_name: String, diff --git a/trading_engine/src/trading/broker_client.rs b/trading_engine/src/trading/broker_client.rs index d9026e769..c3ba311eb 100644 --- a/trading_engine/src/trading/broker_client.rs +++ b/trading_engine/src/trading/broker_client.rs @@ -113,6 +113,7 @@ pub enum TwsMessageType { } /// TWS message encoder/decoder +#[derive(Debug)] pub struct TwsMessageCodec; impl TwsMessageCodec { @@ -227,6 +228,7 @@ impl RequestTracker { self.next_request_id.fetch_add(1, Ordering::SeqCst) } + #[allow(dead_code)] async fn track_request(&self, request_type: &str, order_id: Option) -> u32 { let request_id = self.next_id(); let request = PendingRequest { @@ -235,14 +237,15 @@ impl RequestTracker { timestamp: Utc::now(), order_id, }; - + self.pending_requests .write() .await .insert(request_id, request); request_id } - + + #[allow(dead_code)] async fn complete_request(&self, request_id: u32) -> Option { self.pending_requests.write().await.remove(&request_id) }