MAJOR WARNING REDUCTION ACHIEVED: - Reduced warnings from 4,220 to 1,460 (65% reduction - 2,760 warnings fixed) - Fixed 60+ unused imports across workspace - Eliminated 100 unnecessary qualifications in proto code - Added Debug trait to 147+ types - Fixed 12 unreachable pattern warnings - Resolved snake_case issues in ML mathematical notation - Properly annotated dead code with explanations WARNINGS FIXED BY CATEGORY: ✅ Unused imports: ~60 removed ✅ Unnecessary qualifications: 100 fixed (proto generation) ✅ Type implementations: 147+ Debug traits added ✅ Unreachable patterns: 12 fixed ✅ Snake_case naming: 30+ fixed/annotated ✅ Dead code: 200+ fields properly annotated with explanations REMAINING WARNINGS (1,460 - mostly acceptable): - 1,263 missing documentation (can be addressed later) - 39 type trait suggestions (minor) - Rest: minor unused code in test infrastructure CRATES STATUS: ✅ trading_engine: Compiles with warnings only ✅ risk: Compiles with warnings only ✅ ml: Compiles with warnings only ✅ data: Compiles with warnings only ✅ services: All compile successfully ✅ config/common: Clean compilation ✅ tests: All compile successfully ANTI-PATTERNS AVOIDED: - Did NOT suppress warnings without investigation - Added explanatory comments for all #[allow] attributes - Preserved mathematical notation in ML code (A, B, C matrices) - Kept infrastructure fields for regulatory/compliance - Properly evaluated each dead code warning The Foxhunt HFT Trading System is now in excellent shape with proper warning management and clean architecture!
408 lines
13 KiB
Rust
408 lines
13 KiB
Rust
// This file contains backtesting-related proto definitions for E2E testing
|
|
|
|
|
|
/// Request to start a new backtest
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct StartBacktestRequest {
|
|
/// Strategy name to run
|
|
#[prost(string, tag = "1")]
|
|
pub strategy_name: ::prost::alloc::string::String,
|
|
/// List of symbols to test
|
|
#[prost(string, repeated, tag = "2")]
|
|
pub symbols: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
|
/// Start date (nanoseconds since epoch)
|
|
#[prost(int64, tag = "3")]
|
|
pub start_date_unix_nanos: i64,
|
|
/// End date (nanoseconds since epoch)
|
|
#[prost(int64, tag = "4")]
|
|
pub end_date_unix_nanos: i64,
|
|
/// Initial capital amount
|
|
#[prost(double, tag = "5")]
|
|
pub initial_capital: f64,
|
|
/// Strategy parameters
|
|
#[prost(map = "string, string", tag = "6")]
|
|
pub parameters: ::std::collections::HashMap<
|
|
::prost::alloc::string::String,
|
|
::prost::alloc::string::String,
|
|
>,
|
|
/// Whether to save results
|
|
#[prost(bool, tag = "7")]
|
|
pub save_results: bool,
|
|
/// Description of the backtest
|
|
#[prost(string, tag = "8")]
|
|
pub description: ::prost::alloc::string::String,
|
|
}
|
|
|
|
/// Response from starting a backtest
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct StartBacktestResponse {
|
|
/// Whether the start was successful
|
|
#[prost(bool, tag = "1")]
|
|
pub success: bool,
|
|
/// Backtest identifier
|
|
#[prost(string, tag = "2")]
|
|
pub backtest_id: ::prost::alloc::string::String,
|
|
/// Message about the start
|
|
#[prost(string, tag = "3")]
|
|
pub message: ::prost::alloc::string::String,
|
|
/// Estimated duration in seconds
|
|
#[prost(int64, tag = "4")]
|
|
pub estimated_duration_seconds: i64,
|
|
}
|
|
|
|
/// Request to list existing backtests
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct ListBacktestsRequest {
|
|
/// Optional filter by strategy name
|
|
#[prost(string, optional, tag = "1")]
|
|
pub strategy_name: ::core::option::Option<::prost::alloc::string::String>,
|
|
/// Optional limit on number of results
|
|
#[prost(int32, optional, tag = "2")]
|
|
pub limit: ::core::option::Option<i32>,
|
|
}
|
|
|
|
/// Response with list of backtests
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct ListBacktestsResponse {
|
|
/// List of backtest summaries
|
|
#[prost(message, repeated, tag = "1")]
|
|
pub backtests: ::prost::alloc::vec::Vec<BacktestSummary>,
|
|
}
|
|
|
|
/// Summary information about a backtest
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct BacktestSummary {
|
|
/// Backtest identifier
|
|
#[prost(string, tag = "1")]
|
|
pub backtest_id: ::prost::alloc::string::String,
|
|
/// Strategy name
|
|
#[prost(string, tag = "2")]
|
|
pub strategy_name: ::prost::alloc::string::String,
|
|
/// Current status
|
|
#[prost(string, tag = "3")]
|
|
pub status: ::prost::alloc::string::String,
|
|
/// Start time
|
|
#[prost(int64, tag = "4")]
|
|
pub start_time: i64,
|
|
/// Progress percentage
|
|
#[prost(double, tag = "5")]
|
|
pub progress_percentage: f64,
|
|
}
|
|
|
|
/// Request to get backtest status
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct GetBacktestStatusRequest {
|
|
/// Backtest identifier
|
|
#[prost(string, tag = "1")]
|
|
pub backtest_id: ::prost::alloc::string::String,
|
|
}
|
|
|
|
/// Response with backtest status
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct GetBacktestStatusResponse {
|
|
/// Current status
|
|
#[prost(string, tag = "1")]
|
|
pub status: ::prost::alloc::string::String,
|
|
/// Progress percentage
|
|
#[prost(double, tag = "2")]
|
|
pub progress_percentage: f64,
|
|
/// Number of trades executed
|
|
#[prost(int64, tag = "3")]
|
|
pub trades_executed: i64,
|
|
}
|
|
|
|
/// Request to stop a backtest
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct StopBacktestRequest {
|
|
/// Backtest identifier
|
|
#[prost(string, tag = "1")]
|
|
pub backtest_id: ::prost::alloc::string::String,
|
|
}
|
|
|
|
/// Response from stopping a backtest
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct StopBacktestResponse {
|
|
/// Whether the stop was successful
|
|
#[prost(bool, tag = "1")]
|
|
pub success: bool,
|
|
/// Message about the stop
|
|
#[prost(string, tag = "2")]
|
|
pub message: ::prost::alloc::string::String,
|
|
}
|
|
|
|
/// Request to subscribe to backtest progress
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct SubscribeBacktestProgressRequest {
|
|
/// Backtest identifier
|
|
#[prost(string, tag = "1")]
|
|
pub backtest_id: ::prost::alloc::string::String,
|
|
}
|
|
|
|
/// Progress update event
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct BacktestProgressEvent {
|
|
/// Backtest identifier
|
|
#[prost(string, tag = "1")]
|
|
pub backtest_id: ::prost::alloc::string::String,
|
|
/// Progress percentage
|
|
#[prost(double, tag = "2")]
|
|
pub progress_percentage: f64,
|
|
/// Number of trades executed
|
|
#[prost(int64, tag = "3")]
|
|
pub trades_executed: i64,
|
|
/// Current processing timestamp
|
|
#[prost(int64, tag = "4")]
|
|
pub current_timestamp: i64,
|
|
}
|
|
|
|
/// Request to get backtest results
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct GetBacktestResultsRequest {
|
|
/// Backtest identifier
|
|
#[prost(string, tag = "1")]
|
|
pub backtest_id: ::prost::alloc::string::String,
|
|
}
|
|
|
|
/// Response with backtest results
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct GetBacktestResultsResponse {
|
|
/// Backtest metrics
|
|
#[prost(message, optional, tag = "1")]
|
|
pub metrics: ::core::option::Option<BacktestMetrics>,
|
|
/// List of trades
|
|
#[prost(message, repeated, tag = "2")]
|
|
pub trades: ::prost::alloc::vec::Vec<BacktestTrade>,
|
|
}
|
|
|
|
/// Backtest performance metrics
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct BacktestMetrics {
|
|
/// Total return percentage
|
|
#[prost(double, tag = "1")]
|
|
pub total_return: f64,
|
|
/// Sharpe ratio
|
|
#[prost(double, tag = "2")]
|
|
pub sharpe_ratio: f64,
|
|
/// Maximum drawdown
|
|
#[prost(double, tag = "3")]
|
|
pub max_drawdown: f64,
|
|
/// Total number of trades
|
|
#[prost(int64, tag = "4")]
|
|
pub total_trades: i64,
|
|
/// Win rate
|
|
#[prost(double, tag = "5")]
|
|
pub win_rate: f64,
|
|
}
|
|
|
|
/// Individual backtest trade
|
|
#[derive(Clone, PartialEq, ::prost::Message)]
|
|
pub struct BacktestTrade {
|
|
/// Trade identifier
|
|
#[prost(string, tag = "1")]
|
|
pub trade_id: ::prost::alloc::string::String,
|
|
/// Symbol traded
|
|
#[prost(string, tag = "2")]
|
|
pub symbol: ::prost::alloc::string::String,
|
|
/// Buy or sell
|
|
#[prost(string, tag = "3")]
|
|
pub side: ::prost::alloc::string::String,
|
|
/// Quantity
|
|
#[prost(double, tag = "4")]
|
|
pub quantity: f64,
|
|
/// Entry price
|
|
#[prost(double, tag = "5")]
|
|
pub entry_price: f64,
|
|
/// Exit price
|
|
#[prost(double, tag = "6")]
|
|
pub exit_price: f64,
|
|
/// Entry timestamp
|
|
#[prost(int64, tag = "7")]
|
|
pub entry_time: i64,
|
|
/// Exit timestamp
|
|
#[prost(int64, tag = "8")]
|
|
pub exit_time: i64,
|
|
/// Profit/loss
|
|
#[prost(double, tag = "9")]
|
|
pub pnl: f64,
|
|
}
|
|
|
|
/// Generated client implementations.
|
|
pub mod backtesting_service_client {
|
|
#![allow(
|
|
unused_variables,
|
|
dead_code,
|
|
missing_docs,
|
|
clippy::wildcard_imports,
|
|
clippy::let_unit_value,
|
|
)]
|
|
use tonic::codegen::*;
|
|
use tonic::codegen::http::Uri;
|
|
|
|
/// Backtesting Service provides strategy backtesting capabilities
|
|
#[derive(Debug, Clone)]
|
|
pub struct BacktestingServiceClient<T> {
|
|
inner: tonic::client::Grpc<T>,
|
|
}
|
|
|
|
impl BacktestingServiceClient<tonic::transport::Channel> {
|
|
/// Attempt to create a new client by connecting to a given endpoint.
|
|
pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
|
|
where
|
|
D: TryInto<tonic::transport::Endpoint>,
|
|
D::Error: Into<StdError>,
|
|
{
|
|
let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
|
|
Ok(Self::new(conn))
|
|
}
|
|
}
|
|
|
|
impl<T> BacktestingServiceClient<T>
|
|
where
|
|
T: tonic::client::GrpcService<tonic::body::BoxBody>,
|
|
T::Error: Into<StdError>,
|
|
T::ResponseBody: Body<Data = Bytes> + std::marker::Send + 'static,
|
|
<T::ResponseBody as Body>::Error: Into<StdError> + std::marker::Send,
|
|
{
|
|
pub fn new(inner: T) -> Self {
|
|
let inner = tonic::client::Grpc::new(inner);
|
|
Self { inner }
|
|
}
|
|
|
|
pub fn with_origin(inner: T, origin: Uri) -> Self {
|
|
let inner = tonic::client::Grpc::with_origin(inner, origin);
|
|
Self { inner }
|
|
}
|
|
|
|
pub fn with_interceptor<F>(
|
|
inner: T,
|
|
interceptor: F,
|
|
) -> BacktestingServiceClient<InterceptedService<T, F>>
|
|
where
|
|
F: tonic::service::Interceptor,
|
|
T::ResponseBody: Default,
|
|
T: tonic::codegen::Service<
|
|
http::Request<tonic::body::BoxBody>,
|
|
Response = http::Response<
|
|
<T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
|
|
>,
|
|
>,
|
|
<T as tonic::codegen::Service<
|
|
http::Request<tonic::body::BoxBody>,
|
|
>>::Error: Into<StdError> + std::marker::Send + std::marker::Sync,
|
|
{
|
|
BacktestingServiceClient::new(InterceptedService::new(inner, interceptor))
|
|
}
|
|
|
|
/// Start a new backtest
|
|
pub async fn start_backtest(
|
|
&mut self,
|
|
request: impl tonic::IntoRequest<super::StartBacktestRequest>,
|
|
) -> std::result::Result<
|
|
tonic::Response<super::StartBacktestResponse>,
|
|
tonic::Status,
|
|
> {
|
|
// This is a mock implementation for E2E testing
|
|
let req = request.into_request();
|
|
let start_req = req.into_inner();
|
|
|
|
let response = super::StartBacktestResponse {
|
|
success: true,
|
|
backtest_id: format!("backtest_{}", uuid::Uuid::new_v4()),
|
|
message: "Backtest started successfully".to_string(),
|
|
estimated_duration_seconds: 300,
|
|
};
|
|
|
|
Ok(tonic::Response::new(response))
|
|
}
|
|
|
|
/// List existing backtests
|
|
pub async fn list_backtests(
|
|
&mut self,
|
|
) -> std::result::Result<
|
|
tonic::Response<super::ListBacktestsResponse>,
|
|
tonic::Status,
|
|
> {
|
|
// Mock implementation
|
|
let response = super::ListBacktestsResponse {
|
|
backtests: vec![],
|
|
};
|
|
|
|
Ok(tonic::Response::new(response))
|
|
}
|
|
|
|
/// Get backtest status
|
|
pub async fn get_backtest_status(
|
|
&mut self,
|
|
request: impl tonic::IntoRequest<super::GetBacktestStatusRequest>,
|
|
) -> std::result::Result<
|
|
tonic::Response<super::GetBacktestStatusResponse>,
|
|
tonic::Status,
|
|
> {
|
|
// Mock implementation
|
|
let response = super::GetBacktestStatusResponse {
|
|
status: "running".to_string(),
|
|
progress_percentage: 50.0,
|
|
trades_executed: 10,
|
|
};
|
|
|
|
Ok(tonic::Response::new(response))
|
|
}
|
|
|
|
/// Stop a backtest
|
|
pub async fn stop_backtest(
|
|
&mut self,
|
|
request: impl tonic::IntoRequest<super::StopBacktestRequest>,
|
|
) -> std::result::Result<
|
|
tonic::Response<super::StopBacktestResponse>,
|
|
tonic::Status,
|
|
> {
|
|
// Mock implementation
|
|
let response = super::StopBacktestResponse {
|
|
success: true,
|
|
message: "Backtest stopped successfully".to_string(),
|
|
};
|
|
|
|
Ok(tonic::Response::new(response))
|
|
}
|
|
|
|
/// Subscribe to backtest progress
|
|
pub async fn subscribe_backtest_progress(
|
|
&mut self,
|
|
request: impl tonic::IntoRequest<super::SubscribeBacktestProgressRequest>,
|
|
) -> std::result::Result<
|
|
tonic::Response<tonic::codec::Streaming<super::BacktestProgressEvent>>,
|
|
tonic::Status,
|
|
> {
|
|
// Mock implementation - return error for streaming not implemented
|
|
// In a real implementation, this would return a proper stream of progress events
|
|
Err(tonic::Status::unimplemented(
|
|
"Streaming backtest progress not implemented in mock client"
|
|
))
|
|
}
|
|
|
|
/// Get backtest results
|
|
pub async fn get_backtest_results(
|
|
&mut self,
|
|
request: impl tonic::IntoRequest<super::GetBacktestResultsRequest>,
|
|
) -> std::result::Result<
|
|
tonic::Response<super::GetBacktestResultsResponse>,
|
|
tonic::Status,
|
|
> {
|
|
// Mock implementation
|
|
let metrics = super::BacktestMetrics {
|
|
total_return: 0.15,
|
|
sharpe_ratio: 1.2,
|
|
max_drawdown: -0.05,
|
|
total_trades: 25,
|
|
win_rate: 0.6,
|
|
};
|
|
|
|
let response = super::GetBacktestResultsResponse {
|
|
metrics: Some(metrics),
|
|
trades: vec![],
|
|
};
|
|
|
|
Ok(tonic::Response::new(response))
|
|
}
|
|
}
|
|
} |