Adds a new CLI subcommand that connects to the monitoring service via gRPC to display live training metrics. Supports single-snapshot mode (--once), model filtering (--model), and configurable streaming interval. Renders per-model epoch/loss table, GPU telemetry, hyperopt progress, and health counters. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
260 lines
10 KiB
Rust
260 lines
10 KiB
Rust
#![deny(clippy::unwrap_used, clippy::expect_used)]
|
|
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used))]
|
|
#![allow(missing_docs)] // Internal implementation details
|
|
#![allow(missing_debug_implementations)] // Not all types need Debug
|
|
#![allow(unused_crate_dependencies)] // Dev dependencies not used in lib.rs
|
|
// FXT CLI domain lints
|
|
#![allow(clippy::module_name_repetitions)] // Module-prefixed types provide clarity
|
|
#![allow(clippy::integer_division)] // Integer division is intentional in CLI display
|
|
#![allow(clippy::cognitive_complexity)] // CLI command handling is complex
|
|
#![allow(clippy::manual_let_else)] // if-let pattern preferred in CLI error paths
|
|
#![allow(clippy::unnecessary_wraps)] // Result wrapping needed for CLI commands
|
|
#![allow(clippy::similar_names)] // CLI variables often have similar names
|
|
#![allow(clippy::missing_const_for_fn)] // Const fn not critical for CLI code
|
|
#![allow(clippy::too_many_lines)] // CLI command functions can be long
|
|
#![allow(clippy::doc_markdown)] // Technical terms in doc comments
|
|
#![allow(clippy::must_use_candidate)] // Not all functions need must_use
|
|
#![allow(clippy::missing_errors_doc)] // Internal CLI APIs don't need full error docs
|
|
#![allow(clippy::default_numeric_fallback)] // Numeric literals are contextually typed
|
|
#![allow(clippy::unused_self)] // Self parameter needed for trait consistency
|
|
#![allow(clippy::unused_async)] // Async needed for trait implementations
|
|
#![allow(clippy::too_many_arguments)] // CLI command functions need many parameters
|
|
#![allow(clippy::indexing_slicing)] // Encryption code uses validated slice indices
|
|
#![allow(clippy::wildcard_in_or_patterns)] // Wildcard patterns in command matching
|
|
#![allow(clippy::redundant_pattern_matching)] // Explicit pattern matching preferred
|
|
|
|
//! 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
|
|
//! ```text
|
|
//! 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 fxt::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(())
|
|
//! }
|
|
//! ```
|
|
|
|
// Suppress false-positive unused extern crate warnings for dependencies used in modules
|
|
use chrono as _;
|
|
use clap as _;
|
|
use colored as _;
|
|
use common as _;
|
|
use dirs as _; // Used in config module for home directory
|
|
use futures_util as _;
|
|
use prost as _;
|
|
use rust_decimal as _;
|
|
use serde as _;
|
|
use serde_json as _;
|
|
use tabled as _;
|
|
use thiserror as _;
|
|
use toml as _; // Used in config module for TOML parsing
|
|
use tonic as _;
|
|
use tracing_subscriber as _;
|
|
use uuid as _;
|
|
|
|
// Core modules
|
|
pub mod auth;
|
|
pub mod client;
|
|
pub mod commands;
|
|
pub mod config; // Configuration file support (~/.foxhunt/config.toml)
|
|
pub mod error;
|
|
pub mod types;
|
|
|
|
// Prelude module for convenient imports
|
|
pub mod prelude;
|
|
|
|
// Placeholder modules - database module removed (should only exist in services)
|
|
/// Utility functions and helpers for TLI operations
|
|
///
|
|
/// This module contains shared utility functions used across the TLI client,
|
|
/// including formatting helpers, validation utilities, and common operations.
|
|
pub mod utils {}
|
|
|
|
/// Constants and configuration values for TLI
|
|
///
|
|
/// This module contains compile-time constants, default values, and configuration
|
|
/// parameters used throughout the TLI client application.
|
|
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: &[
|
|
// TLI features are defined by dependencies, not cargo features
|
|
"tonic-tls",
|
|
"grpc-client",
|
|
],
|
|
};
|
|
|
|
/// Build information structure
|
|
///
|
|
/// Contains compile-time information about the TLI binary including version,
|
|
/// source control metadata, and enabled feature flags for debugging and support.
|
|
#[derive(Debug, Clone)]
|
|
pub struct BuildInfo {
|
|
/// Semantic version string (e.g., "1.0.0")
|
|
pub version: &'static str,
|
|
/// Git commit hash from build time
|
|
pub git_hash: &'static str,
|
|
/// ISO 8601 build timestamp
|
|
pub build_date: &'static str,
|
|
/// List of enabled Cargo feature flags
|
|
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(", ")
|
|
)
|
|
}
|
|
}
|
|
|
|
/// Generated protobuf code for gRPC client interfaces
|
|
///
|
|
/// This module contains all the auto-generated protobuf types and service clients
|
|
/// used for communicating with the Foxhunt HFT system services via gRPC.
|
|
pub mod proto {
|
|
/// Trading service protobuf definitions
|
|
///
|
|
/// Contains all message types and service interfaces for the trading service,
|
|
/// including order management, position tracking, and real-time market data.
|
|
#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)]
|
|
pub mod trading {
|
|
tonic::include_proto!("foxhunt.tli");
|
|
}
|
|
|
|
/// Health check service protobuf definitions
|
|
///
|
|
/// Standard gRPC health check service for monitoring service availability
|
|
/// and connection status across all backend services.
|
|
#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)]
|
|
pub mod health {
|
|
tonic::include_proto!("grpc.health.v1");
|
|
}
|
|
|
|
/// ML training service protobuf definitions
|
|
///
|
|
/// Contains message types and service interfaces for machine learning
|
|
/// model training, evaluation, and inference operations.
|
|
#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)]
|
|
pub mod ml {
|
|
tonic::include_proto!("foxhunt.ml");
|
|
}
|
|
|
|
/// Configuration service protobuf definitions
|
|
///
|
|
/// Contains message types and service interfaces for system configuration
|
|
/// management, settings updates, and runtime parameter control.
|
|
#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)]
|
|
pub mod config {
|
|
tonic::include_proto!("foxhunt.config");
|
|
}
|
|
|
|
/// ML Training service protobuf definitions
|
|
///
|
|
/// Contains message types and service interfaces for machine learning
|
|
/// training job management, hyperparameter tuning, and training monitoring.
|
|
#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)]
|
|
pub mod ml_training {
|
|
tonic::include_proto!("ml_training");
|
|
}
|
|
|
|
/// Trading Agent service protobuf definitions
|
|
///
|
|
/// Contains message types and service interfaces for trading agent operations
|
|
/// including universe selection, asset selection, and portfolio allocation.
|
|
#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)]
|
|
pub mod trading_agent {
|
|
tonic::include_proto!("trading_agent");
|
|
}
|
|
|
|
/// Broker Gateway service protobuf definitions
|
|
#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)]
|
|
pub mod broker_gateway {
|
|
tonic::include_proto!("broker_gateway");
|
|
}
|
|
|
|
/// Monitoring service protobuf definitions
|
|
///
|
|
/// Contains message types and service interfaces for live training metrics,
|
|
/// GPU telemetry, and streaming monitoring data from Prometheus.
|
|
#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)]
|
|
pub mod monitoring {
|
|
tonic::include_proto!("monitoring");
|
|
}
|
|
}
|