195 lines
5.9 KiB
Rust
195 lines
5.9 KiB
Rust
#![allow(missing_docs)] // Internal service implementation details
|
|
// Trading service domain lints: generated protobuf code and complex service logic
|
|
#![allow(clippy::mixed_attributes_style)] // Generated protobuf code uses mixed attributes
|
|
#![allow(clippy::should_implement_trait)] // Custom from_str methods for event types
|
|
#![allow(clippy::type_complexity)] // Complex types in async service handlers
|
|
#![allow(clippy::if_same_then_else)] // Intentional identical branches for fallback logic
|
|
#![allow(clippy::manual_clamp)] // Explicit min/max preferred in service code
|
|
#![allow(clippy::too_many_arguments)] // Service constructors need many parameters
|
|
#![allow(clippy::needless_range_loop)] // Index-based loops for matrix operations
|
|
#![allow(clippy::unnecessary_fallible_conversions)] // Explicit conversion for type safety
|
|
//! Trading Service - Standalone HFT Trading System
|
|
//!
|
|
//! This service contains ALL business logic for the Foxhunt HFT system:
|
|
//! - Complete trading operations with integrated risk management
|
|
//! - ML model integration and predictions
|
|
//! - Real-time market data processing
|
|
//! - PostgreSQL-based configuration management with hot-reload
|
|
//! - Event streaming for TLI clients
|
|
//! - System monitoring and health checks
|
|
//!
|
|
//! The service exposes gRPC APIs for all functionality and maintains
|
|
//! state using PostgreSQL for configuration and in-memory structures
|
|
//! for high-frequency operations.
|
|
|
|
#![deny(clippy::unwrap_used, clippy::expect_used)]
|
|
|
|
/// Generated protobuf types and gRPC services
|
|
pub mod proto {
|
|
/// Trading service protobuf definitions
|
|
pub mod trading {
|
|
tonic::include_proto!("trading");
|
|
}
|
|
|
|
/// Risk management protobuf definitions
|
|
pub mod risk {
|
|
tonic::include_proto!("risk");
|
|
}
|
|
|
|
/// ML service protobuf definitions
|
|
pub mod ml {
|
|
tonic::include_proto!("ml");
|
|
}
|
|
|
|
/// Configuration service protobuf definitions
|
|
pub mod config {
|
|
tonic::include_proto!("config");
|
|
}
|
|
|
|
/// Monitoring service protobuf definitions
|
|
pub mod monitoring {
|
|
tonic::include_proto!("monitoring");
|
|
}
|
|
|
|
/// ML Training Service client definitions (for retrain forwarding)
|
|
pub mod ml_training {
|
|
tonic::include_proto!("ml_training");
|
|
}
|
|
}
|
|
|
|
/// Authentication interceptor with mTLS, JWT, and API key support
|
|
pub mod auth_interceptor;
|
|
|
|
/// TLS configuration for Trading Service with mutual TLS
|
|
pub mod tls_config;
|
|
|
|
/// Real-time event streaming system
|
|
pub mod event_streaming;
|
|
|
|
/// Event persistence for compliance and audit trail
|
|
pub mod event_persistence;
|
|
|
|
/// Error types and utilities
|
|
pub mod error;
|
|
|
|
/// Kill switch integration for regulatory compliance
|
|
pub mod kill_switch_integration;
|
|
|
|
/// SOX and MiFID II compliance audit trail service
|
|
pub mod compliance_service;
|
|
|
|
/// Advanced rate limiting with per-user, per-IP, and global limits
|
|
pub mod rate_limiter;
|
|
|
|
/// Repository trait definitions for clean architecture
|
|
pub mod repositories;
|
|
|
|
/// Postgre`SQL` repository implementations
|
|
pub mod repository_impls;
|
|
|
|
/// High-precision latency recording with HDR histogram
|
|
pub mod latency_recorder;
|
|
|
|
/// Service implementations for gRPC endpoints
|
|
pub mod services;
|
|
|
|
/// Performance soak test for sub-50μs latency validation
|
|
pub mod soak_test;
|
|
|
|
/// Service state management and business logic
|
|
pub mod state;
|
|
|
|
/// Utility functions and helpers
|
|
pub mod utils;
|
|
|
|
/// Prometheus metrics for ML model monitoring
|
|
pub mod ml_metrics;
|
|
|
|
/// Comprehensive Prometheus metrics for ML trading operations
|
|
pub mod metrics;
|
|
|
|
/// Prometheus metrics server for trading operations
|
|
pub mod metrics_server;
|
|
|
|
/// Streaming infrastructure and `HTTP`/2 optimizations
|
|
pub mod streaming;
|
|
|
|
/// Core trading engine components (exposed for testing)
|
|
#[doc(hidden)]
|
|
pub mod core;
|
|
|
|
/// Test utilities for configurable test data
|
|
#[cfg(test)]
|
|
pub mod test_utils;
|
|
|
|
/// Test market data generator for E2E testing (mock data)
|
|
pub mod test_market_data_generator;
|
|
|
|
/// DBN-based market data generator for E2E testing (real data)
|
|
pub mod dbn_market_data_generator;
|
|
|
|
/// Bridge adapter: wraps `ModelInferenceAdapter` into `MLModel` for ensemble use
|
|
pub mod adapter_bridge;
|
|
|
|
/// Ensemble coordinator for ML model aggregation
|
|
pub mod ensemble_coordinator;
|
|
|
|
/// Ensemble-specific Prometheus metrics for production observability
|
|
pub mod ensemble_metrics;
|
|
|
|
/// Ensemble risk manager for ML production trading
|
|
pub mod ensemble_risk_manager;
|
|
|
|
/// Ensemble audit logger for compliance and traceability
|
|
pub mod ensemble_audit_logger;
|
|
|
|
/// Ensemble rollback automation for failure recovery
|
|
pub mod rollback_automation;
|
|
|
|
/// Paper trading executor for prediction consumption
|
|
pub mod paper_trading_executor;
|
|
|
|
/// Trading pipeline message types and stage trait
|
|
pub mod pipeline;
|
|
|
|
/// System state observability snapshot for Prometheus/Grafana
|
|
pub mod observability;
|
|
|
|
/// Hot-swap automation for trained model deployment
|
|
pub mod hot_swap_automation;
|
|
|
|
/// A/B testing pipeline for automated model deployment decisions
|
|
pub mod ab_testing_pipeline;
|
|
|
|
/// ML performance metrics tracking and analysis
|
|
pub mod ml_performance_metrics;
|
|
|
|
/// Background prediction generation loop (60s interval)
|
|
pub mod prediction_generation_loop;
|
|
|
|
/// Portfolio allocation module for capital distribution across assets
|
|
pub mod allocation;
|
|
|
|
/// Asset selection module for choosing instruments from universe
|
|
pub mod assets;
|
|
|
|
/// Feature extraction for ML model input (26 features from OHLCV)
|
|
/// Health check endpoints for Kubernetes probes
|
|
pub mod health;
|
|
|
|
/// P&L attribution: decomposes realized trade P&L into per-model contributions
|
|
pub mod attribution;
|
|
|
|
/// Autonomous feedback loop: weight/gate optimization with kill switch
|
|
pub mod feedback_loop;
|
|
|
|
/// QuestDB-backed metrics provider for the feedback loop
|
|
pub mod questdb_metrics;
|
|
|
|
// Re-export for tests
|
|
pub use ensemble_coordinator::EnsembleCoordinator;
|
|
pub use paper_trading_executor::PaperTradingExecutor;
|
|
|
|
// Re-export paper trading types for testing
|
|
pub use paper_trading_executor::{Action, Order, SignalSource, TradingSignal};
|