✅ FIXED CRITICAL COMPILATION ERRORS: - ProductionBenzingaProvider: Added missing Debug trait - Trading Service: Fixed Option<f64> to f64 conversion in order book levels - TLS Config: Fixed certificate ownership and lifetime issues - Repository Impl: Fixed unused variable warnings with underscore prefix - Config Database: Fixed sqlx lifetime parameter errors - Common Types: Removed invalid Side import causing compilation failure 🔧 ARCHITECTURAL COMPLIANCE ACHIEVED: - Config Crate Centralization: All vault access properly routed through config crate - TLI Pure Client: No server components, clean gRPC client architecture - Service Independence: Trading/Backtesting/ML services properly decoupled - Repository Pattern: Clean dependency injection without database coupling 🎯 DEPENDENCY MANAGEMENT CORRECTED: - Fixed circular dependencies between services - Centralized configuration through config crate only - Removed direct vault dependencies outside config crate - Clean import structure across all services 📊 COMPILATION PROGRESS: - From 100+ critical errors to manageable type imports - Core architectural violations resolved - Clean service boundaries established - Repository interfaces properly abstracted 🚀 NEXT PHASE READY: - Common type exports need completion - Final import reconciliation pending - Zero errors target within reach 🎉 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
242 lines
8.1 KiB
Rust
242 lines
8.1 KiB
Rust
//! TLI (Terminal Line Interface) - Client for Foxhunt HFT Trading System
|
|
//!
|
|
//! This module provides a comprehensive gRPC client infrastructure for connecting
|
|
//! to and monitoring core trading services including:
|
|
//!
|
|
//! ## Core Services
|
|
//! - **Trading Service**: Integrated service with all operations (trading, risk, monitoring, config, system status)
|
|
//! - **Backtesting Service**: Strategy testing, performance analysis, results management
|
|
//!
|
|
//! ## Key Features
|
|
//! - **Connection Management**: Pooling, health checks, automatic reconnection
|
|
//! - **Real-time Streaming**: Market data, order updates, system events
|
|
//! - **Error Handling**: Circuit breakers, exponential backoff, comprehensive error types
|
|
//! - **Security**: TLS support, authentication, credential management
|
|
//! - **Monitoring**: Metrics collection, performance tracking, alerting
|
|
//! - **High Availability**: Load balancing, failover, redundancy
|
|
//!
|
|
//! ## Architecture
|
|
//! ```
|
|
//! TLI Client Suite
|
|
//! ├── Connection Manager (pooling, health checks)
|
|
//! ├── Event Stream Manager (real-time data)
|
|
//! ├── Trading Client (ALL operations: trading, risk, monitoring, config, system status)
|
|
//! └── Backtesting Client (strategy testing, performance analysis)
|
|
//! ```
|
|
//!
|
|
//! ## Example Usage
|
|
//! ```rust,no_run
|
|
//! use tli::prelude::*;
|
|
//!
|
|
//! #[tokio::main]
|
|
//! async fn main() -> TliResult<()> {
|
|
//! // Create client suite with both services
|
|
//! let client_suite = TliClientBuilder::new()
|
|
//! .with_service_endpoint("trading_service".to_string(), "http://localhost:50051".to_string())
|
|
//! .with_service_endpoint("backtesting_service".to_string(), "http://localhost:50052".to_string())
|
|
//! .with_trading_config(TradingClientConfig::default())
|
|
//! .with_backtesting_config(BacktestingClientConfig::default())
|
|
//! .build()
|
|
//! .await?;
|
|
//!
|
|
//! // Use trading client
|
|
//! if let Some(trading_client) = &client_suite.trading_client {
|
|
//! // Submit order with integrated risk management
|
|
//! let order_request = SubmitOrderRequest {
|
|
//! symbol: "AAPL".to_string(),
|
|
//! side: OrderSide::Buy as i32,
|
|
//! order_type: OrderType::Market as i32,
|
|
//! quantity: 100.0,
|
|
//! client_order_id: "order_123".to_string(),
|
|
//! ..Default::default()
|
|
//! };
|
|
//!
|
|
//! let response = trading_client.submit_order(order_request).await?;
|
|
//! println!("Order submitted: {:?}", response);
|
|
//! }
|
|
//!
|
|
//! // Shutdown
|
|
//! client_suite.shutdown().await;
|
|
//! Ok(())
|
|
//! }
|
|
//! ```
|
|
|
|
// Core modules
|
|
pub mod client;
|
|
// pub mod config_client; // Config client removed - use gRPC ConfigurationService instead
|
|
pub mod dashboard;
|
|
pub mod dashboards;
|
|
pub mod error;
|
|
// pub mod health; // Health server module removed - TLI is pure client
|
|
pub mod types;
|
|
pub mod ui;
|
|
// pub mod auth; // Auth functionality removed - TLI is pure client
|
|
// Vault functionality moved to shared config crate - use config::VaultSecrets instead
|
|
|
|
// Event system for client-side event handling and streaming
|
|
pub mod events;
|
|
|
|
// Placeholder modules - database module removed (should only exist in services)
|
|
pub mod utils {}
|
|
pub mod constants {}
|
|
|
|
// Terminal UI modules now enabled
|
|
|
|
#[cfg(test)]
|
|
pub mod tests;
|
|
|
|
/// TLI version information
|
|
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
|
|
/// TLI build information
|
|
pub const BUILD_INFO: BuildInfo = BuildInfo {
|
|
version: VERSION,
|
|
git_hash: match option_env!("GIT_HASH") {
|
|
Some(hash) => hash,
|
|
None => "unknown",
|
|
},
|
|
build_date: match option_env!("BUILD_DATE") {
|
|
Some(date) => date,
|
|
None => "unknown",
|
|
},
|
|
features: &[
|
|
#[cfg(feature = "tls")]
|
|
"tls",
|
|
#[cfg(feature = "metrics")]
|
|
"metrics",
|
|
#[cfg(feature = "tracing")]
|
|
"tracing",
|
|
],
|
|
};
|
|
|
|
/// Build information structure
|
|
#[derive(Debug, Clone)]
|
|
pub struct BuildInfo {
|
|
pub version: &'static str,
|
|
pub git_hash: &'static str,
|
|
pub build_date: &'static str,
|
|
pub features: &'static [&'static str],
|
|
}
|
|
|
|
impl std::fmt::Display for BuildInfo {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"TLI v{} ({}), built on {}, features: [{}]",
|
|
self.version,
|
|
self.git_hash,
|
|
self.build_date,
|
|
self.features.join(", ")
|
|
)
|
|
}
|
|
}
|
|
|
|
// Include generated protobuf code
|
|
pub mod proto {
|
|
pub mod trading {
|
|
tonic::include_proto!("foxhunt.tli");
|
|
}
|
|
|
|
pub mod health {
|
|
tonic::include_proto!("grpc.health.v1");
|
|
}
|
|
|
|
pub mod ml {
|
|
tonic::include_proto!("foxhunt.ml");
|
|
}
|
|
|
|
pub mod config {
|
|
tonic::include_proto!("foxhunt.config");
|
|
}
|
|
}
|
|
|
|
// Re-export main client components
|
|
// pub use ui::{EnhancedTerminalUI, TerminalUI, TliClient, ServiceHealth};
|
|
pub use client::{
|
|
// Backtesting client
|
|
BacktestingClient,
|
|
BacktestingClientConfig,
|
|
// Client infrastructure
|
|
ClientFactory,
|
|
ClientStats,
|
|
ConnectionConfig,
|
|
ConnectionManager,
|
|
ConnectionStats,
|
|
EventStreamConfig,
|
|
EventStreamManager,
|
|
EventType,
|
|
// ML training client
|
|
MLTrainingClient,
|
|
MLTrainingClientConfig,
|
|
MLTrainingStats,
|
|
ManagedConnection,
|
|
MarketDataConfig,
|
|
MonitoringConfig,
|
|
OrderContext,
|
|
OrderValidationConfig,
|
|
ResourceMonitoringEvent,
|
|
RiskManagementConfig,
|
|
TliClientBuilder,
|
|
TliClientSuite,
|
|
TliEvent,
|
|
// Trading client (handles ALL operations)
|
|
TradingClient,
|
|
TradingClientConfig,
|
|
TrainingJobContext,
|
|
TrainingProgressEvent,
|
|
};
|
|
|
|
pub use error::{TliError, TliResult};
|
|
// HealthServer removed - TLI is pure client, no server components
|
|
// pub use health::{HealthConfig, HealthServer, HealthStatus};
|
|
pub use types::*;
|
|
|
|
/// Common imports for TLI module consumers
|
|
pub mod prelude {
|
|
// Client infrastructure
|
|
pub use crate::client::{
|
|
BacktestingClient, BacktestingClientConfig, ClientFactory, ConnectionConfig,
|
|
ConnectionManager, EventStreamManager, EventType, TliClientBuilder, TliClientSuite,
|
|
TliEvent, TradingClient, TradingClientConfig,
|
|
};
|
|
// Error handling
|
|
pub use crate::error::*;
|
|
// Dashboard and UI components (with aliases to avoid conflicts)
|
|
pub use crate::dashboard::{
|
|
Dashboard, DashboardEvent, DashboardType,
|
|
ConfigUpdate as DashboardConfigUpdate, // Alias to avoid conflict with proto::config::ConfigUpdate
|
|
SystemStatusEvent as DashboardSystemStatusEvent, // Alias to avoid conflict with proto::trading::SystemStatusEvent
|
|
PredictionType as DashboardPredictionType, // Alias to avoid conflict with proto::ml::PredictionType
|
|
};
|
|
pub use crate::ui::*;
|
|
// Type definitions
|
|
pub use crate::types::*;
|
|
// Protocol definitions (with aliases to avoid conflicts)
|
|
// NOTE: TLI is a pure client - no ConfigServiceClient needed
|
|
pub use crate::proto::config::{
|
|
CategoriesResponse, ConfigResponse,
|
|
ConfigUpdate as ProtoConfigUpdate, // Alias to avoid conflict with dashboard::ConfigUpdate
|
|
Empty as ConfigEmpty, // Alias to avoid conflict with proto::ml::Empty
|
|
};
|
|
pub use crate::proto::ml::{
|
|
ml_service_client::MlServiceClient,
|
|
ml_training_service_client::MlTrainingServiceClient,
|
|
PredictionResponse, ModelPerformanceRequest,
|
|
PredictionType as ProtoMLPredictionType, // Alias to avoid conflict with dashboard::PredictionType
|
|
Empty as MLEmpty, // Alias to avoid conflict with proto::config::Empty
|
|
};
|
|
pub use crate::proto::trading::{
|
|
trading_service_client::TradingServiceClient,
|
|
backtesting_service_client::BacktestingServiceClient,
|
|
GetPositionsRequest, GetPositionsResponse, SubmitOrderRequest, SubmitOrderResponse,
|
|
SystemStatusEvent as ProtoSystemStatusEvent, // Alias to avoid conflict with dashboard::SystemStatusEvent
|
|
};
|
|
// ML training client
|
|
pub use crate::client::{
|
|
MLTrainingClient, MLTrainingClientConfig, MLTrainingStats, ResourceMonitoringEvent,
|
|
TrainingJobContext, TrainingProgressEvent,
|
|
};
|
|
// UI components (disabled due to compilation issues)
|
|
// pub use crate::ui::*;
|
|
}
|