From c112d34fecbfbf64b0c3ac6eb1b263ded401eb86 Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Tue, 3 Mar 2026 20:48:21 +0100 Subject: [PATCH] refactor: point fxt build.rs at proto/ root, delete fat-client protos fxt now compiles from the same service protos as all backend services. Deleted 8 fat-client protos (3,286 lines) from bin/fxt/proto/. Updated include_proto! macros to use new package names (trading, ml, config instead of foxhunt.tli, foxhunt.ml, foxhunt.config). Added risk, data_acquisition, and config_service proto modules. Fixed duplicate include_proto in agent.rs to use crate::proto. Existing command implementations will be rewritten to use new proto types in Task 6. Co-Authored-By: Claude Opus 4.6 --- bin/fxt/build.rs | 57 +- bin/fxt/proto/broker_gateway.proto | 212 ------- bin/fxt/proto/config.proto | 422 -------------- bin/fxt/proto/health.proto | 32 -- bin/fxt/proto/ml.proto | 516 ----------------- bin/fxt/proto/ml_training.proto | 454 --------------- bin/fxt/proto/monitoring.proto | 140 ----- bin/fxt/proto/trading.proto | 895 ----------------------------- bin/fxt/proto/trading_agent.proto | 615 -------------------- bin/fxt/src/commands/agent.rs | 8 +- bin/fxt/src/lib.rs | 65 +-- 11 files changed, 66 insertions(+), 3350 deletions(-) delete mode 100644 bin/fxt/proto/broker_gateway.proto delete mode 100644 bin/fxt/proto/config.proto delete mode 100644 bin/fxt/proto/health.proto delete mode 100644 bin/fxt/proto/ml.proto delete mode 100644 bin/fxt/proto/ml_training.proto delete mode 100644 bin/fxt/proto/monitoring.proto delete mode 100644 bin/fxt/proto/trading.proto delete mode 100644 bin/fxt/proto/trading_agent.proto diff --git a/bin/fxt/build.rs b/bin/fxt/build.rs index f46baa51d..95c2aaf3f 100644 --- a/bin/fxt/build.rs +++ b/bin/fxt/build.rs @@ -1,41 +1,48 @@ -// use prost_build as _; // Not directly used - fn main() -> Result<(), Box> { - // Configure tonic-prost-build for proto compilation (Tonic 0.14+) - // Note: Server code enabled for E2E tests (mock gRPC servers) + // proto/ at workspace root — single source of truth for all services. + // Note: fxt_trading.proto (package foxhunt.tli) is excluded — it is the + // legacy fat-client proto kept only for API Gateway backward compatibility. + let proto_root = "../../proto"; + tonic_prost_build::configure() .build_server(true) // Required for E2E test mock servers .build_client(true) - // Force correct protobuf attributes for all messages .type_attribute(".", "#[derive(serde::Serialize, serde::Deserialize)]") - // Suppress warnings in generated code .server_mod_attribute(".", "#[allow(unused_qualifications)]") .client_mod_attribute(".", "#[allow(unused_qualifications)]") - // Enable proper protobuf derives .protoc_arg("--experimental_allow_proto3_optional") .compile_protos( &[ - "proto/trading.proto", - "proto/health.proto", - "proto/ml.proto", - "proto/config.proto", - "proto/ml_training.proto", - "proto/trading_agent.proto", - "proto/broker_gateway.proto", - "proto/monitoring.proto", + &format!("{proto_root}/trading.proto"), + &format!("{proto_root}/health.proto"), + &format!("{proto_root}/ml.proto"), + &format!("{proto_root}/config.proto"), + &format!("{proto_root}/ml_training.proto"), + &format!("{proto_root}/trading_agent.proto"), + &format!("{proto_root}/broker_gateway.proto"), + &format!("{proto_root}/monitoring.proto"), + &format!("{proto_root}/risk.proto"), + &format!("{proto_root}/data_acquisition.proto"), + &format!("{proto_root}/config_service.proto"), ], - &["proto"], + &[proto_root], )?; - // Tell cargo to recompile if proto files change - println!("cargo:rerun-if-changed=proto/trading.proto"); - println!("cargo:rerun-if-changed=proto/health.proto"); - println!("cargo:rerun-if-changed=proto/ml.proto"); - println!("cargo:rerun-if-changed=proto/config.proto"); - println!("cargo:rerun-if-changed=proto/ml_training.proto"); - println!("cargo:rerun-if-changed=proto/trading_agent.proto"); - println!("cargo:rerun-if-changed=proto/broker_gateway.proto"); - println!("cargo:rerun-if-changed=proto/monitoring.proto"); + for proto in &[ + "trading", + "health", + "ml", + "config", + "ml_training", + "trading_agent", + "broker_gateway", + "monitoring", + "risk", + "data_acquisition", + "config_service", + ] { + println!("cargo:rerun-if-changed={proto_root}/{proto}.proto"); + } Ok(()) } diff --git a/bin/fxt/proto/broker_gateway.proto b/bin/fxt/proto/broker_gateway.proto deleted file mode 100644 index 5677dfa76..000000000 --- a/bin/fxt/proto/broker_gateway.proto +++ /dev/null @@ -1,212 +0,0 @@ -// Broker Gateway Service - FIX Order Routing Protocol -// -// This service handles all broker communication via FIX 4.2/4.4 protocol -// for order routing, execution management, and account state synchronization. - -syntax = "proto3"; - -package broker_gateway; - -// ============================================================================ -// Broker Gateway Service -// ============================================================================ - -service BrokerGatewayService { - // Route order to broker via FIX protocol - rpc RouteOrder(RouteOrderRequest) returns (RouteOrderResponse); - - // Cancel existing order - rpc CancelOrder(CancelOrderRequest) returns (CancelOrderResponse); - - // Get current account state (balance, margin, positions) - rpc GetAccountState(GetAccountStateRequest) returns (GetAccountStateResponse); - - // Get all positions for account - rpc GetPositions(GetPositionsRequest) returns (GetPositionsResponse); - - // Get FIX session status - rpc GetSessionStatus(GetSessionStatusRequest) returns (GetSessionStatusResponse); - - // Stream real-time executions from broker - rpc StreamExecutions(StreamExecutionsRequest) returns (stream ExecutionEvent); - - // Health check - rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse); -} - -// ============================================================================ -// Order Routing -// ============================================================================ - -message RouteOrderRequest { - string symbol = 1; // ES, NQ, etc. - OrderSide side = 2; // BUY, SELL - double quantity = 3; // Number of contracts - OrderType order_type = 4; // MARKET, LIMIT, STOP, STOP_LIMIT - optional double price = 5; // Limit price (required for LIMIT orders) - optional double stop_price = 6; // Stop price (required for STOP orders) - string account_id = 7; // AMP account identifier - map metadata = 8; // Strategy, model_name, etc. -} - -message RouteOrderResponse { - string broker_order_id = 1; // Broker-assigned OrderID (Tag 37, filled after ack) - string client_order_id = 2; // Our ClOrdID (Tag 11) - OrderStatus status = 3; // PENDING_SUBMIT, SUBMITTED, etc. - int64 submitted_at = 4; // Timestamp (nanoseconds) - string message = 5; // Success/error message -} - -message CancelOrderRequest { - string client_order_id = 1; // Order to cancel - string account_id = 2; // Account verification -} - -message CancelOrderResponse { - bool success = 1; - string message = 2; - OrderStatus new_status = 3; // CANCEL_PENDING, CANCELLED, etc. -} - -// ============================================================================ -// Account & Position Management -// ============================================================================ - -message GetAccountStateRequest { - string account_id = 1; -} - -message GetAccountStateResponse { - string account_id = 1; - double cash_balance = 2; - double equity = 3; - double margin_used = 4; - double margin_available = 5; - double buying_power = 6; - double unrealized_pnl = 7; - double realized_pnl = 8; - int64 last_updated = 9; // Timestamp (nanoseconds) -} - -message GetPositionsRequest { - string account_id = 1; - optional string symbol = 2; // Filter by symbol (optional) -} - -message GetPositionsResponse { - repeated Position positions = 1; - double total_equity = 2; - double total_exposure = 3; - double leverage_ratio = 4; - int64 timestamp = 5; -} - -message Position { - string symbol = 1; - double quantity = 2; // Positive = long, negative = short - double average_price = 3; - double market_value = 4; - double unrealized_pnl = 5; -} - -// ============================================================================ -// Session Management -// ============================================================================ - -message GetSessionStatusRequest { - optional string session_id = 1; // Optional: default to active session -} - -message GetSessionStatusResponse { - string session_id = 1; - SessionState state = 2; - int64 sender_seq_num = 3; // Current outgoing sequence - int64 target_seq_num = 4; // Expected incoming sequence - int64 last_heartbeat_sent = 5; // Timestamp (nanoseconds) - int64 last_heartbeat_received = 6; // Timestamp (nanoseconds) - double heartbeat_rtt_ms = 7; // Round-trip time in milliseconds - int64 connected_at = 8; // Timestamp (nanoseconds) - map details = 9; // Additional session info -} - -// ============================================================================ -// Execution Streaming -// ============================================================================ - -message StreamExecutionsRequest { - optional string account_id = 1; // Filter by account - optional string symbol = 2; // Filter by symbol -} - -message ExecutionEvent { - string execution_id = 1; // ExecID (Tag 17) - string broker_order_id = 2; // OrderID (Tag 37) - string client_order_id = 3; // ClOrdID (Tag 11) - string symbol = 4; - OrderSide side = 5; - ExecutionType exec_type = 6; // NEW, TRADE, CANCELED, REJECTED - OrderStatus order_status = 7; // Order status after this execution - double last_qty = 8; // Quantity filled (Tag 32) - double last_price = 9; // Fill price (Tag 31) - double cum_qty = 10; // Total filled (Tag 14) - double avg_price = 11; // Average fill price (Tag 6) - int64 transact_time = 12; // Execution timestamp - optional string text = 13; // Reject reason (if applicable) -} - -// ============================================================================ -// Health Check -// ============================================================================ - -message HealthCheckRequest {} - -message HealthCheckResponse { - bool healthy = 1; - string message = 2; - map details = 3; -} - -// ============================================================================ -// Enums -// ============================================================================ - -enum OrderSide { - ORDER_SIDE_UNSPECIFIED = 0; - ORDER_SIDE_BUY = 1; - ORDER_SIDE_SELL = 2; -} - -enum OrderType { - ORDER_TYPE_UNSPECIFIED = 0; - ORDER_TYPE_MARKET = 1; - ORDER_TYPE_LIMIT = 2; - ORDER_TYPE_STOP = 3; - ORDER_TYPE_STOP_LIMIT = 4; -} - -enum OrderStatus { - ORDER_STATUS_UNSPECIFIED = 0; - ORDER_STATUS_PENDING_SUBMIT = 1; - ORDER_STATUS_SUBMITTED = 2; - ORDER_STATUS_PARTIALLY_FILLED = 3; - ORDER_STATUS_FILLED = 4; - ORDER_STATUS_CANCEL_PENDING = 5; - ORDER_STATUS_CANCELLED = 6; - ORDER_STATUS_REJECTED = 7; -} - -enum ExecutionType { - EXECUTION_TYPE_UNSPECIFIED = 0; - EXECUTION_TYPE_NEW = 1; // Order accepted - EXECUTION_TYPE_TRADE = 2; // Partial or full fill - EXECUTION_TYPE_CANCELED = 3; // Order canceled - EXECUTION_TYPE_REJECTED = 4; // Order rejected -} - -enum SessionState { - SESSION_STATE_DISCONNECTED = 0; - SESSION_STATE_CONNECTED = 1; - SESSION_STATE_LOGGING_IN = 2; - SESSION_STATE_ACTIVE = 3; - SESSION_STATE_LOGGING_OUT = 4; -} diff --git a/bin/fxt/proto/config.proto b/bin/fxt/proto/config.proto deleted file mode 100644 index afbdd9b8b..000000000 --- a/bin/fxt/proto/config.proto +++ /dev/null @@ -1,422 +0,0 @@ -syntax = "proto3"; - -package foxhunt.config; - -// Configuration Service - SQLite-Based Configuration Management -service ConfigurationService { - // Configuration CRUD operations - rpc GetConfiguration(ConfigRequest) returns (ConfigResponse); - rpc UpdateConfiguration(UpdateConfigRequest) returns (UpdateResponse); - rpc DeleteConfiguration(DeleteConfigRequest) returns (DeleteResponse); - rpc ListCategories(Empty) returns (CategoriesResponse); - - // Real-time configuration updates - rpc StreamConfigChanges(Empty) returns (stream ConfigChangeResponse); - - // Configuration management - rpc ValidateConfiguration(ValidateRequest) returns (ValidationResponse); - rpc GetConfigurationHistory(HistoryRequest) returns (HistoryResponse); - rpc RollbackConfiguration(RollbackRequest) returns (RollbackResponse); - rpc ExportConfiguration(ExportRequest) returns (ExportResponse); - rpc ImportConfiguration(ImportRequest) returns (ImportResponse); - - // Schema management - rpc GetConfigSchema(SchemaRequest) returns (SchemaResponse); - rpc UpdateConfigSchema(UpdateSchemaRequest) returns (UpdateSchemaResponse); - - // Environment management - rpc GetActiveEnvironment(Empty) returns (EnvironmentResponse); - rpc SwitchEnvironment(SwitchEnvironmentRequest) returns (SwitchEnvironmentResponse); - rpc ListEnvironments(Empty) returns (EnvironmentsResponse); - - // Backup and restore - rpc BackupConfiguration(BackupRequest) returns (BackupResponse); - rpc RestoreConfiguration(RestoreRequest) returns (RestoreResponse); -} - -// Configuration requests and responses -message ConfigRequest { - repeated string keys = 1; // Empty to get all config - optional string category = 2; // Filter by category - optional string environment = 3; // Specific environment, default is active - bool include_sensitive = 4; // Include encrypted/sensitive values -} - -message ConfigResponse { - repeated ConfigSetting settings = 1; - string environment = 2; - int64 version = 3; - int64 last_updated_unix_nanos = 4; -} - -message ConfigSetting { - int64 id = 1; - string category = 2; - string key = 3; - string value = 4; - ConfigDataType data_type = 5; - bool hot_reload = 6; - string validation_rule = 7; - string description = 8; - string default_value = 9; - bool required = 10; - bool sensitive = 11; - string environment_override = 12; - optional double min_value = 13; - optional double max_value = 14; - repeated string enum_values = 15; - repeated int64 depends_on = 16; - repeated string tags = 17; - int32 display_order = 18; - int64 created_at_unix_nanos = 19; - int64 modified_at_unix_nanos = 20; -} - -message UpdateConfigRequest { - repeated ConfigUpdate updates = 1; - string changed_by = 2; - string reason = 3; - bool validate_before_update = 4; -} - -message ConfigUpdate { - string key = 1; - string value = 2; - optional string category = 3; -} - -message UpdateResponse { - bool success = 1; - string message = 2; - repeated string updated_keys = 3; - repeated ValidationError validation_errors = 4; - int64 new_version = 5; -} - -message DeleteConfigRequest { - repeated string keys = 1; - string reason = 2; - string deleted_by = 3; -} - -message DeleteResponse { - bool success = 1; - string message = 2; - repeated string deleted_keys = 3; - repeated string failed_keys = 4; -} - -message CategoriesResponse { - repeated ConfigCategory categories = 1; -} - -message ConfigCategory { - int64 id = 1; - string name = 2; - string description = 3; - optional int64 parent_id = 4; - int32 display_order = 5; - string icon = 6; - int64 created_at_unix_nanos = 7; - repeated ConfigCategory children = 8; - int32 setting_count = 9; -} - -// Real-time configuration streaming -message ConfigChangeResponse { - ConfigChangeType change_type = 1; - ConfigSetting setting = 2; - string old_value = 3; - string new_value = 4; - string changed_by = 5; - string reason = 6; - int64 timestamp_unix_nanos = 7; - bool hot_reload_applied = 8; -} - -// Configuration validation -message ValidateRequest { - repeated ConfigValidation validations = 1; - bool check_dependencies = 2; -} - -message ConfigValidation { - string key = 1; - string value = 2; - optional string category = 3; -} - -message ValidationResponse { - bool valid = 1; - repeated ValidationError errors = 2; - repeated ValidationWarning warnings = 3; -} - -message ValidationError { - string key = 1; - string message = 2; - ValidationErrorType error_type = 3; - string expected_format = 4; -} - -message ValidationWarning { - string key = 1; - string message = 2; - ValidationWarningType warning_type = 3; -} - -// Configuration history -message HistoryRequest { - optional string key = 1; // Specific key or all - optional int64 start_time_unix_nanos = 2; - optional int64 end_time_unix_nanos = 3; - optional string changed_by = 4; - uint32 limit = 5; // Default: 100 - uint32 offset = 6; -} - -message HistoryResponse { - repeated ConfigHistoryEntry entries = 1; - uint32 total_count = 2; -} - -message ConfigHistoryEntry { - int64 id = 1; - int64 setting_id = 2; - string key = 3; - string old_value = 4; - string new_value = 5; - string change_reason = 6; - string changed_by = 7; - int64 changed_at_unix_nanos = 8; - string change_source = 9; - string validation_result = 10; - optional int64 rollback_id = 11; -} - -// Configuration rollback -message RollbackRequest { - oneof target { - int64 history_entry_id = 1; // Rollback to specific change - int64 timestamp_unix_nanos = 2; // Rollback to point in time - int64 version = 3; // Rollback to version - } - string reason = 4; - string rolled_back_by = 5; - bool validate_before_rollback = 6; -} - -message RollbackResponse { - bool success = 1; - string message = 2; - repeated string rolled_back_keys = 3; - int64 rollback_id = 4; - int64 new_version = 5; -} - -// Configuration export/import -message ExportRequest { - repeated string categories = 1; // Empty for all - repeated string keys = 2; // Specific keys - string environment = 3; // Default: active - ExportFormat format = 4; - bool include_sensitive = 5; - bool include_metadata = 6; -} - -message ExportResponse { - bytes data = 1; - ExportFormat format = 2; - string filename = 3; - int32 setting_count = 4; - int64 exported_at_unix_nanos = 5; -} - -message ImportRequest { - bytes data = 1; - ExportFormat format = 2; - ImportStrategy strategy = 3; - string imported_by = 4; - bool validate_before_import = 5; - bool dry_run = 6; -} - -message ImportResponse { - bool success = 1; - string message = 2; - ImportSummary summary = 3; - repeated ValidationError validation_errors = 4; -} - -message ImportSummary { - int32 total_settings = 1; - int32 created_settings = 2; - int32 updated_settings = 3; - int32 skipped_settings = 4; - int32 failed_settings = 5; - repeated string created_keys = 6; - repeated string updated_keys = 7; - repeated string failed_keys = 8; -} - -// Schema management -message SchemaRequest { - optional string category = 1; // Specific category schema -} - -message SchemaResponse { - repeated ConfigSchema schemas = 1; -} - -message ConfigSchema { - string name = 1; - string schema_definition = 2; // JSON schema - string description = 3; - int64 created_at_unix_nanos = 4; -} - -message UpdateSchemaRequest { - string name = 1; - string schema_definition = 2; - string description = 3; -} - -message UpdateSchemaResponse { - bool success = 1; - string message = 2; -} - -// Environment management -message EnvironmentResponse { - ConfigEnvironment environment = 1; -} - -message ConfigEnvironment { - int64 id = 1; - string name = 2; - string description = 3; - bool is_active = 4; - int64 created_at_unix_nanos = 5; - int32 override_count = 6; -} - -message SwitchEnvironmentRequest { - string environment_name = 1; - string reason = 2; - string switched_by = 3; -} - -message SwitchEnvironmentResponse { - bool success = 1; - string message = 2; - string old_environment = 3; - string new_environment = 4; - int32 settings_affected = 5; -} - -message EnvironmentsResponse { - repeated ConfigEnvironment environments = 1; -} - -// Backup and restore -message BackupRequest { - string backup_name = 1; - string description = 2; - repeated string categories = 3; // Empty for all - bool include_history = 4; - bool compress = 5; -} - -message BackupResponse { - bool success = 1; - string message = 2; - string backup_id = 3; - string backup_path = 4; - int64 backup_size_bytes = 5; - int64 created_at_unix_nanos = 6; -} - -message RestoreRequest { - string backup_id = 1; - RestoreStrategy strategy = 2; - string restored_by = 3; - bool validate_before_restore = 4; -} - -message RestoreResponse { - bool success = 1; - string message = 2; - RestoreSummary summary = 3; -} - -message RestoreSummary { - int32 total_settings = 1; - int32 restored_settings = 2; - int32 skipped_settings = 3; - int32 failed_settings = 4; - string backup_version = 5; - int64 backup_created_at_unix_nanos = 6; -} - -// Empty message for parameterless requests -message Empty {} - -// Enums -enum ConfigDataType { - CONFIG_DATA_TYPE_UNSPECIFIED = 0; - CONFIG_DATA_TYPE_STRING = 1; - CONFIG_DATA_TYPE_NUMBER = 2; - CONFIG_DATA_TYPE_BOOLEAN = 3; - CONFIG_DATA_TYPE_JSON = 4; - CONFIG_DATA_TYPE_ENCRYPTED = 5; -} - -enum ConfigChangeType { - CONFIG_CHANGE_TYPE_UNSPECIFIED = 0; - CONFIG_CHANGE_TYPE_CREATED = 1; - CONFIG_CHANGE_TYPE_UPDATED = 2; - CONFIG_CHANGE_TYPE_DELETED = 3; - CONFIG_CHANGE_TYPE_ROLLBACK = 4; -} - -enum ValidationErrorType { - VALIDATION_ERROR_TYPE_UNSPECIFIED = 0; - VALIDATION_ERROR_TYPE_REQUIRED = 1; - VALIDATION_ERROR_TYPE_FORMAT = 2; - VALIDATION_ERROR_TYPE_RANGE = 3; - VALIDATION_ERROR_TYPE_ENUM = 4; - VALIDATION_ERROR_TYPE_DEPENDENCY = 5; - VALIDATION_ERROR_TYPE_CUSTOM = 6; -} - -enum ValidationWarningType { - VALIDATION_WARNING_TYPE_UNSPECIFIED = 0; - VALIDATION_WARNING_TYPE_DEPRECATED = 1; - VALIDATION_WARNING_TYPE_PERFORMANCE = 2; - VALIDATION_WARNING_TYPE_SECURITY = 3; - VALIDATION_WARNING_TYPE_COMPATIBILITY = 4; -} - -enum ExportFormat { - EXPORT_FORMAT_UNSPECIFIED = 0; - EXPORT_FORMAT_JSON = 1; - EXPORT_FORMAT_YAML = 2; - EXPORT_FORMAT_TOML = 3; - EXPORT_FORMAT_CSV = 4; - EXPORT_FORMAT_SQL = 5; -} - -enum ImportStrategy { - IMPORT_STRATEGY_UNSPECIFIED = 0; - IMPORT_STRATEGY_MERGE = 1; - IMPORT_STRATEGY_REPLACE = 2; - IMPORT_STRATEGY_UPDATE_ONLY = 3; - IMPORT_STRATEGY_CREATE_ONLY = 4; -} - -enum RestoreStrategy { - RESTORE_STRATEGY_UNSPECIFIED = 0; - RESTORE_STRATEGY_FULL_REPLACE = 1; - RESTORE_STRATEGY_MERGE = 2; - RESTORE_STRATEGY_SELECTIVE = 3; -} \ No newline at end of file diff --git a/bin/fxt/proto/health.proto b/bin/fxt/proto/health.proto deleted file mode 100644 index 71add527a..000000000 --- a/bin/fxt/proto/health.proto +++ /dev/null @@ -1,32 +0,0 @@ -syntax = "proto3"; - -package grpc.health.v1; - -// Health check service definition -service Health { - // Check the health status of the service - rpc Check(HealthCheckRequest) returns (HealthCheckResponse); - - // Watch for health status changes - rpc Watch(HealthCheckRequest) returns (stream HealthCheckResponse); -} - -// Health check request -message HealthCheckRequest { - // Service name to check (empty for overall service health) - string service = 1; -} - -// Health check response -message HealthCheckResponse { - // Health status - ServingStatus status = 1; -} - -// Serving status enum -enum ServingStatus { - UNKNOWN = 0; - SERVING = 1; - NOT_SERVING = 2; - SERVICE_UNKNOWN = 3; // Used when the requested service is unknown -} \ No newline at end of file diff --git a/bin/fxt/proto/ml.proto b/bin/fxt/proto/ml.proto deleted file mode 100644 index f41744944..000000000 --- a/bin/fxt/proto/ml.proto +++ /dev/null @@ -1,516 +0,0 @@ -syntax = "proto3"; - -package foxhunt.ml; - -// ML Service - Model Insights & Predictions -service MLService { - // Real-time ML streams - rpc StreamModelPredictions(ModelRequest) returns (stream PredictionResponse); - rpc StreamSignalStrength(SignalRequest) returns (stream SignalResponse); - rpc StreamModelMetrics(MetricsRequest) returns (stream ModelMetricsResponse); - - // Model management - rpc GetModelPerformance(ModelPerformanceRequest) returns (ModelPerformanceResponse); - rpc GetEnsembleVote(EnsembleRequest) returns (EnsembleResponse); - rpc GetFeatureImportance(FeatureRequest) returns (FeatureResponse); - rpc RetrainModel(RetrainRequest) returns (RetrainResponse); - - // Model status - rpc GetModelStatus(ModelStatusRequest) returns (ModelStatusResponse); - rpc GetAvailableModels(Empty) returns (AvailableModelsResponse); -} - -// ML Training Service - Dedicated Training Management -service MLTrainingService { - // Training job management - rpc StartTraining(StartTrainingRequest) returns (TrainingJob); - rpc StopTraining(StopTrainingRequest) returns (TrainingJob); - rpc ListTrainingJobs(ListTrainingJobsRequest) returns (ListTrainingJobsResponse); - - // Real-time training monitoring (streaming) - rpc WatchTrainingProgress(WatchTrainingRequest) returns (stream TrainingProgressUpdate); - - // Training configuration and validation - rpc ValidateTrainingConfig(TrainingConfigRequest) returns (TrainingConfigResponse); - rpc GetTrainingTemplates(TrainingTemplatesRequest) returns (TrainingTemplatesResponse); - - // Resource management - rpc GetResourceUtilization(ResourceRequest) returns (ResourceResponse); - rpc StreamResourceMetrics(ResourceRequest) returns (stream ResourceMetricsUpdate); -} - -// Real-time streaming requests -message ModelRequest { - repeated string model_names = 1; // Empty for all models - repeated string symbols = 2; // Empty for all symbols - uint32 update_interval_seconds = 3; // Default: 1 second -} - -message PredictionResponse { - string model_name = 1; - string symbol = 2; - PredictionType prediction = 3; - double confidence = 4; - int64 timestamp_unix_nanos = 5; - repeated double features = 6; - double signal_strength = 7; - ModelState model_state = 8; -} - -message SignalRequest { - repeated string symbols = 1; - uint32 lookback_minutes = 2; // Signal strength lookback - SignalAggregationType aggregation = 3; -} - -message SignalResponse { - string symbol = 1; - double signal_strength = 2; // -1.0 to 1.0 (bearish to bullish) - SignalDirection direction = 3; - double confidence = 4; - repeated ModelSignal model_signals = 5; - int64 timestamp_unix_nanos = 6; -} - -message ModelSignal { - string model_name = 1; - double signal = 2; - double weight = 3; - ModelState state = 4; -} - -message MetricsRequest { - repeated string model_names = 1; - MetricType metric_type = 2; - uint32 update_interval_seconds = 3; -} - -message ModelMetricsResponse { - string model_name = 1; - double accuracy = 2; - double precision = 3; - double recall = 4; - double f1_score = 5; - double sharpe_ratio = 6; - double win_rate = 7; - uint64 predictions_made = 8; - int64 last_training_unix_nanos = 9; - ModelState state = 10; - int64 timestamp_unix_nanos = 11; -} - -// Model management requests -message ModelPerformanceRequest { - string model_name = 1; - optional int64 start_time_unix_nanos = 2; - optional int64 end_time_unix_nanos = 3; - repeated string symbols = 4; // Empty for all -} - -message ModelPerformanceResponse { - string model_name = 1; - PerformanceMetrics overall = 2; - repeated SymbolPerformance by_symbol = 3; - repeated TimeseriesMetric timeseries = 4; - ModelConfig config = 5; -} - -message PerformanceMetrics { - double accuracy = 1; - double precision = 2; - double recall = 3; - double f1_score = 4; - double auc_roc = 5; - double sharpe_ratio = 6; - double calmar_ratio = 7; - double max_drawdown = 8; - double win_rate = 9; - double avg_return_per_trade = 10; - uint64 total_predictions = 11; - uint64 correct_predictions = 12; -} - -message SymbolPerformance { - string symbol = 1; - PerformanceMetrics metrics = 2; - uint64 trade_count = 3; - double total_return = 4; -} - -message TimeseriesMetric { - int64 timestamp_unix_nanos = 1; - double accuracy = 2; - double signal_strength = 3; - double volatility = 4; -} - -message EnsembleRequest { - repeated string symbols = 1; - repeated string model_names = 2; // Empty for all models - EnsembleMethod method = 3; -} - -message EnsembleResponse { - repeated EnsembleVote votes = 1; - EnsembleMethod method_used = 2; - double overall_confidence = 3; - int64 timestamp_unix_nanos = 4; -} - -message EnsembleVote { - string symbol = 1; - PredictionType consensus = 2; - double confidence = 3; - repeated ModelVote model_votes = 4; - double signal_strength = 5; -} - -message ModelVote { - string model_name = 1; - PredictionType prediction = 2; - double confidence = 3; - double weight = 4; - ModelState state = 5; -} - -message FeatureRequest { - string model_name = 1; - optional string symbol = 2; - FeatureImportanceType type = 3; -} - -message FeatureResponse { - string model_name = 1; - repeated FeatureImportance features = 2; - FeatureImportanceType type = 3; - int64 computed_at_unix_nanos = 4; -} - -message FeatureImportance { - string feature_name = 1; - double importance_score = 2; - double rank = 3; - FeatureCategory category = 4; - string description = 5; -} - -message RetrainRequest { - string model_name = 1; - repeated string symbols = 2; - int64 start_data_unix_nanos = 3; - int64 end_data_unix_nanos = 4; - map hyperparameters = 5; - bool force_retrain = 6; -} - -message RetrainResponse { - bool success = 1; - string message = 2; - string job_id = 3; - int64 estimated_completion_unix_nanos = 4; - TrainingStatus status = 5; -} - -message ModelStatusRequest { - repeated string model_names = 1; // Empty for all models -} - -message ModelStatusResponse { - repeated ModelStatus models = 1; - int64 timestamp_unix_nanos = 2; -} - -message ModelStatus { - string model_name = 1; - ModelState state = 2; - ModelType type = 3; - string version = 4; - int64 last_trained_unix_nanos = 5; - int64 last_prediction_unix_nanos = 6; - PerformanceMetrics current_performance = 7; - repeated string supported_symbols = 8; - ModelConfig config = 9; - string description = 10; -} - -message ModelConfig { - string model_type = 1; - map hyperparameters = 2; - repeated string features = 3; - uint32 lookback_window = 4; - uint32 prediction_horizon = 5; - double confidence_threshold = 6; -} - -message AvailableModelsResponse { - repeated AvailableModel models = 1; - uint32 total_count = 2; - int64 timestamp_unix_nanos = 3; -} - -message AvailableModel { - string model_name = 1; - string display_name = 2; - ModelType type = 3; - string description = 4; - repeated string supported_symbols = 5; - ModelState state = 6; - string version = 7; - PerformanceMetrics performance_summary = 8; -} - -// Empty message for parameterless requests -message Empty {} - -// Enums -enum PredictionType { - PREDICTION_TYPE_UNSPECIFIED = 0; - PREDICTION_TYPE_BUY = 1; - PREDICTION_TYPE_SELL = 2; - PREDICTION_TYPE_HOLD = 3; - PREDICTION_TYPE_STRONG_BUY = 4; - PREDICTION_TYPE_STRONG_SELL = 5; -} - -enum ModelState { - MODEL_STATE_UNSPECIFIED = 0; - MODEL_STATE_ACTIVE = 1; - MODEL_STATE_TRAINING = 2; - MODEL_STATE_LOADING = 3; - MODEL_STATE_ERROR = 4; - MODEL_STATE_DISABLED = 5; - MODEL_STATE_WARM_UP = 6; -} - -enum ModelType { - MODEL_TYPE_UNSPECIFIED = 0; - MODEL_TYPE_DQN = 1; - MODEL_TYPE_PPO = 2; - MODEL_TYPE_MAMBA = 3; - MODEL_TYPE_TRANSFORMER = 4; - MODEL_TYPE_LSTM = 5; - MODEL_TYPE_TFT = 6; - MODEL_TYPE_LIQUID = 7; - MODEL_TYPE_ENSEMBLE = 8; -} - -enum SignalDirection { - SIGNAL_DIRECTION_UNSPECIFIED = 0; - SIGNAL_DIRECTION_BULLISH = 1; - SIGNAL_DIRECTION_BEARISH = 2; - SIGNAL_DIRECTION_NEUTRAL = 3; -} - -enum SignalAggregationType { - SIGNAL_AGGREGATION_TYPE_UNSPECIFIED = 0; - SIGNAL_AGGREGATION_TYPE_WEIGHTED_AVERAGE = 1; - SIGNAL_AGGREGATION_TYPE_MAJORITY_VOTE = 2; - SIGNAL_AGGREGATION_TYPE_CONFIDENCE_WEIGHTED = 3; -} - -enum EnsembleMethod { - ENSEMBLE_METHOD_UNSPECIFIED = 0; - ENSEMBLE_METHOD_WEIGHTED_AVERAGE = 1; - ENSEMBLE_METHOD_MAJORITY_VOTE = 2; - ENSEMBLE_METHOD_STACKING = 3; - ENSEMBLE_METHOD_BAYESIAN = 4; -} - -enum FeatureImportanceType { - FEATURE_IMPORTANCE_TYPE_UNSPECIFIED = 0; - FEATURE_IMPORTANCE_TYPE_PERMUTATION = 1; - FEATURE_IMPORTANCE_TYPE_SHAP = 2; - FEATURE_IMPORTANCE_TYPE_GAIN = 3; - FEATURE_IMPORTANCE_TYPE_SPLIT = 4; -} - -enum FeatureCategory { - FEATURE_CATEGORY_UNSPECIFIED = 0; - FEATURE_CATEGORY_PRICE = 1; - FEATURE_CATEGORY_VOLUME = 2; - FEATURE_CATEGORY_TECHNICAL = 3; - FEATURE_CATEGORY_SENTIMENT = 4; - FEATURE_CATEGORY_MACRO = 5; - FEATURE_CATEGORY_TEMPORAL = 6; -} - -enum TrainingStatus { - TRAINING_STATUS_UNSPECIFIED = 0; - TRAINING_STATUS_QUEUED = 1; - TRAINING_STATUS_PREPARING = 2; // Resource allocation, data loading - TRAINING_STATUS_RUNNING = 3; - TRAINING_STATUS_COMPLETED = 4; - TRAINING_STATUS_FAILED = 5; - TRAINING_STATUS_STOPPING = 6; - TRAINING_STATUS_CANCELLED = 7; -} - -// New messages for MLTrainingService -message StartTrainingRequest { - string model_name = 1; - string dataset_id = 2; - TrainingHyperparameters hyperparameters = 3; - ResourceRequirements resource_requirements = 4; - repeated string tags = 5; - string description = 6; - bool auto_deploy = 7; // Auto-deploy on successful completion -} - -message StopTrainingRequest { - string job_id = 1; - bool force = 2; // Force stop without cleanup -} - -message ListTrainingJobsRequest { - optional string model_name = 1; - optional TrainingStatus status = 2; - optional int64 start_time_after = 3; - optional int64 start_time_before = 4; - repeated string tags = 5; - int32 limit = 6; - string cursor = 7; // For pagination -} - -message ListTrainingJobsResponse { - repeated TrainingJob jobs = 1; - string next_cursor = 2; - int32 total_count = 3; -} - -message TrainingJob { - string job_id = 1; - string model_name = 2; - TrainingStatus status = 3; - int64 start_time = 4; - optional int64 end_time = 5; - optional string resulting_model_id = 6; - TrainingHyperparameters hyperparameters = 7; - ResourceRequirements resource_requirements = 8; - repeated string tags = 9; - string description = 10; - TrainingMetrics current_metrics = 11; - optional string error_message = 12; - double progress_percentage = 13; -} - -message WatchTrainingRequest { - string job_id = 1; - bool include_logs = 2; - bool include_metrics = 3; -} - -message TrainingProgressUpdate { - string job_id = 1; - TrainingStatus status = 2; - int32 current_epoch = 3; - int32 total_epochs = 4; - double progress_percentage = 5; - TrainingMetrics metrics = 6; - optional string log_message = 7; - int64 timestamp = 8; - optional ResourceUtilization resource_usage = 9; -} - -message TrainingHyperparameters { - double learning_rate = 1; - int32 batch_size = 2; - int32 epochs = 3; - optional double dropout_rate = 4; - optional int32 hidden_layers = 5; - optional int32 hidden_units = 6; - map custom_params = 7; -} - -message ResourceRequirements { - int32 gpu_count = 1; - int32 cpu_cores = 2; - int64 memory_gb = 3; - optional string gpu_type = 4; // e.g., "V100", "A100" - int64 disk_gb = 5; -} - -message TrainingMetrics { - double loss = 1; - double accuracy = 2; - double validation_loss = 3; - double validation_accuracy = 4; - double learning_rate = 5; - map custom_metrics = 6; -} - -message ResourceUtilization { - double gpu_utilization = 1; // 0.0 to 1.0 - double gpu_memory_used = 2; // 0.0 to 1.0 - double cpu_utilization = 3; - double memory_used = 4; - double disk_used = 5; - int64 timestamp = 6; -} - -message TrainingConfigRequest { - string model_name = 1; - TrainingHyperparameters hyperparameters = 2; - ResourceRequirements resource_requirements = 3; -} - -message TrainingConfigResponse { - bool valid = 1; - repeated string validation_errors = 2; - repeated string validation_warnings = 3; - optional TrainingHyperparameters suggested_params = 4; - optional ResourceRequirements suggested_resources = 5; - double estimated_duration_hours = 6; -} - -message TrainingTemplatesRequest { - optional string model_type = 1; -} - -message TrainingTemplatesResponse { - repeated TrainingTemplate templates = 1; -} - -message TrainingTemplate { - string template_id = 1; - string name = 2; - string description = 3; - string model_type = 4; - TrainingHyperparameters default_hyperparameters = 5; - ResourceRequirements recommended_resources = 6; - repeated string supported_datasets = 7; -} - -message ResourceRequest { - // Empty for now, might add filtering later -} - -message ResourceResponse { - ResourceUtilization current_utilization = 1; - repeated ResourceUtilization gpu_utilization = 2; - int32 available_gpus = 3; - int32 total_gpus = 4; - repeated string active_training_jobs = 5; -} - -message ResourceMetricsUpdate { - ResourceUtilization utilization = 1; - repeated TrainingJob active_jobs = 2; - int64 timestamp = 3; -} - -enum MetricType { - METRIC_TYPE_UNSPECIFIED = 0; - METRIC_TYPE_ACCURACY = 1; - METRIC_TYPE_PERFORMANCE = 2; - METRIC_TYPE_LATENCY = 3; - METRIC_TYPE_ALL = 4; -} - -enum LogLevel { - LOG_LEVEL_UNSPECIFIED = 0; - LOG_LEVEL_DEBUG = 1; - LOG_LEVEL_INFO = 2; - LOG_LEVEL_WARNING = 3; - LOG_LEVEL_ERROR = 4; - LOG_LEVEL_CRITICAL = 5; -} \ No newline at end of file diff --git a/bin/fxt/proto/ml_training.proto b/bin/fxt/proto/ml_training.proto deleted file mode 100644 index 3e873e63d..000000000 --- a/bin/fxt/proto/ml_training.proto +++ /dev/null @@ -1,454 +0,0 @@ -syntax = "proto3"; - -package ml_training; - -// ML Training Service provides comprehensive machine learning model training capabilities for HFT systems. -// This service manages training jobs for MAMBA-2, TLOB transformers, DQN, PPO, Liquid Networks, and TFT models -// with real-time progress monitoring, resource management, and performance tracking. -service MLTrainingService { - // Training Job Management - // Initiates a new training job and returns job ID immediately - rpc StartTraining(StartTrainingRequest) returns (StartTrainingResponse); - - // Subscribe to real-time training progress and status updates - rpc SubscribeToTrainingStatus(SubscribeToTrainingStatusRequest) returns (stream TrainingStatusUpdate); - - // Stop a running training job (idempotent operation) - rpc StopTraining(StopTrainingRequest) returns (StopTrainingResponse); - - // Model and Job Discovery - // List available ML models with their training parameters - rpc ListAvailableModels(ListAvailableModelsRequest) returns (ListAvailableModelsResponse); - - // Get paginated list of training job history - rpc ListTrainingJobs(ListTrainingJobsRequest) returns (ListTrainingJobsResponse); - - // Get comprehensive details for a specific training job - rpc GetTrainingJobDetails(GetTrainingJobDetailsRequest) returns (GetTrainingJobDetailsResponse); - - // Service Health and Status - // Check service health and resource availability - rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse); - - // Hyperparameter Tuning Management - // Start a new hyperparameter tuning job using Optuna - rpc StartTuningJob(StartTuningJobRequest) returns (StartTuningJobResponse); - - // Get current status and best parameters from a tuning job - rpc GetTuningJobStatus(GetTuningJobStatusRequest) returns (GetTuningJobStatusResponse); - - // Stop a running hyperparameter tuning job - rpc StopTuningJob(StopTuningJobRequest) returns (StopTuningJobResponse); - - // INTERNAL: Train a single model instance with specific hyperparameters (called by Optuna subprocess) - rpc TrainModel(TrainModelRequest) returns (TrainModelResponse); - - // Stream real-time tuning progress updates (trial completion events) - rpc StreamTuningProgress(StreamProgressRequest) returns (stream ProgressUpdate); - - // Model promotion management - rpc ApproveModel(ApproveModelRequest) returns (ApproveModelResponse); - rpc RejectModel(RejectModelRequest) returns (RejectModelResponse); -} - -// --- Core Request/Response Messages --- - -// Request to start a new model training job -message StartTrainingRequest { - string model_type = 1; // Model type ("TLOB", "MAMBA_2", "DQN", "PPO", "LIQUID", "TFT") - DataSource data_source = 2; // Training data source configuration - Hyperparameters hyperparameters = 3; // Model-specific training parameters - bool use_gpu = 4; // Whether to use GPU acceleration - string description = 5; // Optional job description - map tags = 6; // Optional categorization tags -} - -message StartTrainingResponse { - string job_id = 1; - TrainingStatus status = 2; - string message = 3; -} - -message SubscribeToTrainingStatusRequest { - string job_id = 1; -} - -// Real-time training progress update streamed from server -message TrainingStatusUpdate { - string job_id = 1; // Training job identifier - TrainingStatus status = 2; // Current job status - float progress_percentage = 3; // Training progress (0.0 to 100.0) - uint32 current_epoch = 4; // Current training epoch - uint32 total_epochs = 5; // Total epochs planned - map metrics = 6; // Training metrics (loss, accuracy, sharpe_ratio, etc.) - string message = 7; // Human-readable status message - int64 timestamp = 8; // Update timestamp (Unix seconds) - FinancialMetrics financial_metrics = 9; // Financial performance metrics - ResourceUsage resource_usage = 10; // Current resource utilization -} - -message StopTrainingRequest { - string job_id = 1; - string reason = 2; // Optional reason for stopping -} - -message StopTrainingResponse { - bool success = 1; - string message = 2; -} - -message ListAvailableModelsRequest {} - -message ListAvailableModelsResponse { - repeated ModelDefinition models = 1; -} - -message ListTrainingJobsRequest { - uint32 page = 1; - uint32 page_size = 2; - TrainingStatus status_filter = 3; - string model_type_filter = 4; - int64 start_time = 5; // Unix timestamp in seconds - int64 end_time = 6; // Unix timestamp in seconds -} - -message ListTrainingJobsResponse { - repeated TrainingJobSummary jobs = 1; - uint32 total_count = 2; - uint32 page = 3; - uint32 page_size = 4; -} - -message GetTrainingJobDetailsRequest { - string job_id = 1; -} - -message GetTrainingJobDetailsResponse { - TrainingJobDetails job_details = 1; -} - -message HealthCheckRequest {} - -message HealthCheckResponse { - bool healthy = 1; - string message = 2; - map details = 3; -} - -// Request to start hyperparameter tuning job -message StartTuningJobRequest { - string model_type = 1; // Model type to tune ("TLOB", "MAMBA_2", "DQN", "PPO", "LIQUID", "TFT") - uint32 num_trials = 2; // Number of tuning trials to run - string config_path = 3; // Path to tuning configuration file (search space, objectives) - DataSource data_source = 4; // Training data source for all trials - bool use_gpu = 5; // Whether to use GPU acceleration - string description = 6; // Optional job description - map tags = 7; // Optional categorization tags -} - -message StartTuningJobResponse { - string job_id = 1; // Unique tuning job identifier - TuningJobStatus status = 2; // Initial job status - string message = 3; // Human-readable status message -} - -// Request to query tuning job status -message GetTuningJobStatusRequest { - string job_id = 1; // Tuning job identifier -} - -message GetTuningJobStatusResponse { - string job_id = 1; // Tuning job identifier - TuningJobStatus status = 2; // Current job status - uint32 current_trial = 3; // Current trial number (0-indexed) - uint32 total_trials = 4; // Total number of trials - map best_params = 5; // Best hyperparameters found so far - map best_metrics = 6; // Metrics for best parameters (sharpe_ratio, training_loss, etc.) - repeated TrialResult trial_history = 7; // Complete trial history - string message = 8; // Human-readable status message - int64 started_at = 9; // Job start time (Unix timestamp in seconds) - int64 updated_at = 10; // Last update time (Unix timestamp in seconds) -} - -// Request to stop a tuning job -message StopTuningJobRequest { - string job_id = 1; // Tuning job identifier - string reason = 2; // Optional reason for stopping -} - -message StopTuningJobResponse { - bool success = 1; // Whether stop was successful - string message = 2; // Human-readable status message - TuningJobStatus final_status = 3; // Final job status after stopping -} - -// INTERNAL: Request to train a model with specific hyperparameters (called by Optuna) -message TrainModelRequest { - string model_type = 1; // Model type ("TLOB", "MAMBA_2", "DQN", "PPO", "LIQUID", "TFT") - map hyperparameters = 2; // Hyperparameters to use for this trial - DataSource data_source = 3; // Training data source - bool use_gpu = 4; // Whether to use GPU acceleration - string trial_id = 5; // Optuna trial identifier for tracking -} - -message TrainModelResponse { - bool success = 1; // Whether training succeeded - float sharpe_ratio = 2; // Primary optimization objective (Sharpe ratio) - float training_loss = 3; // Final training loss - map validation_metrics = 4; // Additional validation metrics - string error_message = 5; // Error message if training failed - int64 training_duration_seconds = 6; // Total training time -} - -// Individual trial result for tuning job history -message TrialResult { - uint32 trial_number = 1; // Trial index - map params = 2; // Hyperparameters tested - float objective_value = 3; // Objective metric (e.g., Sharpe ratio) - map metrics = 4; // Additional metrics - TrialState state = 5; // Trial outcome state - int64 started_at = 6; // Trial start time (Unix timestamp in seconds) - int64 completed_at = 7; // Trial completion time (Unix timestamp in seconds) -} - -// Request to stream tuning progress updates -message StreamProgressRequest { - string job_id = 1; // Tuning job identifier to subscribe to -} - -// Real-time progress update streamed after each trial completes -message ProgressUpdate { - string job_id = 1; // Tuning job identifier - uint32 current_trial = 2; // Current trial number (0-indexed) - uint32 total_trials = 3; // Total number of trials - map trial_params = 4; // Current trial hyperparameters (as strings for display) - float trial_sharpe = 5; // Current trial's Sharpe ratio (objective value) - float best_sharpe_so_far = 6; // Best Sharpe ratio achieved so far - uint32 estimated_time_remaining = 7; // Estimated seconds until completion - TuningJobStatus status = 8; // Current job status - string message = 9; // Human-readable status message - int64 timestamp = 10; // Update timestamp (Unix seconds) - UpdateType update_type = 11; // Type of update (trial completion, heartbeat, job complete) -} - -// Type of progress update -enum UpdateType { - UPDATE_UNKNOWN = 0; // Unknown/unspecified - UPDATE_TRIAL_COMPLETE = 1; // Trial completed - UPDATE_HEARTBEAT = 2; // Keepalive heartbeat (no trial change) - UPDATE_JOB_COMPLETE = 3; // Job completed/stopped/failed -} - -// --- Enums --- - -// Current status of a training job -enum TrainingStatus { - UNKNOWN = 0; // Default/unknown status - PENDING = 1; // Job queued, waiting to start - RUNNING = 2; // Job currently executing - COMPLETED = 3; // Job finished successfully - FAILED = 4; // Job failed with error - STOPPED = 5; // Job manually stopped - PAUSED = 6; // Job temporarily paused -} - -// Status of a hyperparameter tuning job -enum TuningJobStatus { - TUNING_UNKNOWN = 0; // Default/unknown status - TUNING_PENDING = 1; // Job queued, waiting to start - TUNING_RUNNING = 2; // Job currently executing trials - TUNING_COMPLETED = 3; // Job finished all trials successfully - TUNING_FAILED = 4; // Job failed with error - TUNING_STOPPED = 5; // Job manually stopped before completion -} - -// Outcome state of an individual trial -enum TrialState { - TRIAL_UNKNOWN = 0; // Default/unknown state - TRIAL_RUNNING = 1; // Trial currently executing - TRIAL_COMPLETE = 2; // Trial completed successfully - TRIAL_PRUNED = 3; // Trial pruned by Optuna (early stopping) - TRIAL_FAILED = 4; // Trial failed with error -} - -// --- Data Structures --- - -message DataSource { - oneof source { - string historical_db_query = 1; - string real_time_stream_topic = 2; - string file_path = 3; - } - int64 start_time = 4; // Unix timestamp in seconds - int64 end_time = 5; // Unix timestamp in seconds -} - -// Provides type-safe hyperparameter configuration. -message Hyperparameters { - oneof model_params { - TlobParams tlob_params = 1; - MambaParams mamba_params = 2; - DqnParams dqn_params = 3; - PpoParams ppo_params = 4; - LiquidParams liquid_params = 5; - TftParams tft_params = 6; - } -} - -// TLOB (Time-Limit Order Book) Transformer parameters -message TlobParams { - uint32 epochs = 1; - float learning_rate = 2; - uint32 batch_size = 3; - uint32 sequence_length = 4; - uint32 hidden_dim = 5; - uint32 num_heads = 6; - uint32 num_layers = 7; - float dropout_rate = 8; - bool use_positional_encoding = 9; -} - -// MAMBA-2 State Space Model parameters -message MambaParams { - uint32 epochs = 1; - float learning_rate = 2; - uint32 batch_size = 3; - uint32 state_dim = 4; - uint32 hidden_dim = 5; - uint32 num_layers = 6; - float dt_min = 7; - float dt_max = 8; - bool use_cuda_kernels = 9; -} - -// DQN (Deep Q-Network) parameters -message DqnParams { - uint32 epochs = 1; - float learning_rate = 2; - uint32 batch_size = 3; - uint32 replay_buffer_size = 4; - float epsilon_start = 5; - float epsilon_end = 6; - uint32 epsilon_decay_steps = 7; - float gamma = 8; - uint32 target_update_frequency = 9; - bool use_double_dqn = 10; - bool use_dueling = 11; - bool use_prioritized_replay = 12; -} - -// PPO (Proximal Policy Optimization) parameters -message PpoParams { - uint32 epochs = 1; - float learning_rate = 2; - uint32 batch_size = 3; - float clip_ratio = 4; - float value_loss_coef = 5; - float entropy_coef = 6; - uint32 rollout_steps = 7; - uint32 minibatch_size = 8; - float gae_lambda = 9; -} - -// Liquid Network parameters -message LiquidParams { - uint32 epochs = 1; - float learning_rate = 2; - uint32 batch_size = 3; - uint32 num_neurons = 4; - float tau = 5; - float sigma = 6; - bool use_adaptive_tau = 7; -} - -// Temporal Fusion Transformer parameters -message TftParams { - uint32 epochs = 1; - float learning_rate = 2; - uint32 batch_size = 3; - uint32 hidden_dim = 4; - uint32 num_heads = 5; - uint32 num_layers = 6; - uint32 lookback_window = 7; - uint32 forecast_horizon = 8; - float dropout_rate = 9; -} - -message ModelDefinition { - string model_type = 1; - string description = 2; - Hyperparameters default_hyperparameters = 3; - repeated string required_features = 4; - uint32 estimated_training_time_minutes = 5; - bool requires_gpu = 6; -} - -message TrainingJobSummary { - string job_id = 1; - string model_type = 2; - TrainingStatus status = 3; - int64 created_at = 4; // Unix timestamp in seconds - int64 started_at = 5; // Unix timestamp in seconds - int64 completed_at = 6; // Unix timestamp in seconds - string description = 7; - float final_loss = 8; - float best_validation_score = 9; - map tags = 10; -} - -message TrainingJobDetails { - string job_id = 1; - string model_type = 2; - TrainingStatus status = 3; - int64 created_at = 4; // Unix timestamp in seconds - int64 started_at = 5; // Unix timestamp in seconds - int64 completed_at = 6; // Unix timestamp in seconds - string description = 7; - Hyperparameters hyperparameters = 8; - DataSource data_source = 9; - repeated TrainingStatusUpdate status_history = 10; - FinancialMetrics final_financial_metrics = 11; - string model_artifact_path = 12; - map tags = 13; - string error_message = 14; -} - -message FinancialMetrics { - float simulated_return = 1; - float sharpe_ratio = 2; - float max_drawdown = 3; - float hit_rate = 4; - float avg_prediction_error_bps = 5; - float risk_adjusted_return = 6; - float var_5pct = 7; - float expected_shortfall = 8; -} - -message ResourceUsage { - float cpu_usage_percent = 1; - float memory_usage_gb = 2; - float gpu_usage_percent = 3; - float gpu_memory_usage_gb = 4; - uint32 active_workers = 5; -} - -// Model promotion messages -message ApproveModelRequest { - string model_id = 1; - string promoted_to = 2; // e.g. "production", "staging", "canary" -} - -message ApproveModelResponse { - bool success = 1; - string message = 2; -} - -message RejectModelRequest { - string model_id = 1; - string reason = 2; -} - -message RejectModelResponse { - bool success = 1; - string message = 2; -} \ No newline at end of file diff --git a/bin/fxt/proto/monitoring.proto b/bin/fxt/proto/monitoring.proto deleted file mode 100644 index 157a89453..000000000 --- a/bin/fxt/proto/monitoring.proto +++ /dev/null @@ -1,140 +0,0 @@ -syntax = "proto3"; -package monitoring; - -service MonitoringService { - // Single snapshot of all active training sessions - rpc GetLiveTrainingMetrics(GetLiveTrainingMetricsRequest) - returns (GetLiveTrainingMetricsResponse); - - // Server-streaming: pushes updates every N seconds - rpc StreamTrainingMetrics(StreamTrainingMetricsRequest) - returns (stream GetLiveTrainingMetricsResponse); - - // Epoch history for a specific session (ring buffer, max 50 epochs) - rpc GetEpochHistory(GetEpochHistoryRequest) - returns (GetEpochHistoryResponse); -} - -message GetLiveTrainingMetricsRequest { - string model_filter = 1; // optional: "dqn", "ppo", etc. -} - -message StreamTrainingMetricsRequest { - string model_filter = 1; - uint32 interval_seconds = 2; // 0 = server default (3s) -} - -message GetLiveTrainingMetricsResponse { - repeated TrainingSession sessions = 1; - GpuSnapshot gpu = 2; - uint32 active_k8s_jobs = 3; - int64 timestamp = 4; -} - -message TrainingSession { - string model = 1; - string fold = 2; - bool is_hyperopt = 3; - - // Epoch/progress - float current_epoch = 4; - float epoch_loss = 5; - float validation_loss = 6; - - // Throughput - float batches_per_second = 7; - float batches_processed = 8; - float iteration_seconds = 9; - - // Eval metrics - float eval_accuracy = 10; - float eval_precision = 11; - float eval_recall = 12; - float eval_f1 = 13; - - // Checkpoint - float checkpoint_size_bytes = 14; - uint32 checkpoint_saves = 15; - uint32 checkpoint_failures = 16; - - // Health counters - uint32 nan_detected = 17; - uint32 gradient_explosions = 18; - uint32 feature_errors = 19; - - // Hyperopt fields (populated when is_hyperopt=true) - uint32 hyperopt_trial_current = 20; - uint32 hyperopt_trial_total = 21; - float hyperopt_best_objective = 22; - uint32 hyperopt_trials_failed = 23; - - // RL diagnostics - float q_value_mean = 24; - float q_value_max = 25; - float policy_entropy = 26; - float kl_divergence = 27; - float advantage_mean = 28; - uint32 replay_buffer_size = 29; - - // Gradient & training health - float gradient_norm = 30; - float learning_rate = 31; - float epoch_duration_seconds = 32; - - // Hyperopt intra-trial - uint32 hyperopt_trial_epoch = 33; - float hyperopt_trial_best_loss = 34; - float hyperopt_elapsed_seconds = 35; - - // Epoch-level financial metrics - float epoch_sharpe = 36; - float epoch_sortino = 37; - float epoch_win_rate = 38; - float epoch_max_drawdown = 39; - float epoch_profit_factor = 40; - float epoch_total_return = 41; - float epoch_avg_return = 42; - uint32 epoch_total_trades = 43; - // Action distribution - float action_buy_pct = 44; - float action_sell_pct = 45; - float action_hold_pct = 46; -} - -message GpuSnapshot { - float utilization_percent = 1; - float memory_used_mb = 2; - float memory_total_mb = 3; - float temperature_celsius = 4; - float power_watts = 5; -} - -message GetEpochHistoryRequest { - string model = 1; - string fold = 2; - uint32 max_epochs = 3; // 0 = all (up to 50) -} - -message EpochFinancialSnapshot { - uint32 epoch = 1; - float sharpe = 2; - float sortino = 3; - float win_rate = 4; - float max_drawdown = 5; - float profit_factor = 6; - float total_return = 7; - float avg_return = 8; - uint32 total_trades = 9; - float loss = 10; - float val_loss = 11; - float learning_rate = 12; - float action_buy_pct = 13; - float action_sell_pct = 14; - float action_hold_pct = 15; -} - -message GetEpochHistoryResponse { - string model = 1; - string fold = 2; - repeated EpochFinancialSnapshot epochs = 3; -} diff --git a/bin/fxt/proto/trading.proto b/bin/fxt/proto/trading.proto deleted file mode 100644 index 6c7fbaa07..000000000 --- a/bin/fxt/proto/trading.proto +++ /dev/null @@ -1,895 +0,0 @@ -syntax = "proto3"; - -package foxhunt.tli; - -// TLI Trading Service provides a unified client interface for all HFT trading operations. -// This service integrates trading, risk management, monitoring, and configuration capabilities -// into a single comprehensive API for the Terminal Line Interface (TLI) client application. -service TradingService { - // Core Trading Operations - // Submit a new trading order with validation - rpc SubmitOrder(SubmitOrderRequest) returns (SubmitOrderResponse); - - // Cancel an existing order by ID - rpc CancelOrder(CancelOrderRequest) returns (CancelOrderResponse); - - // Get current status of a specific order - rpc GetOrderStatus(GetOrderStatusRequest) returns (GetOrderStatusResponse); - - // Get account information and balances - rpc GetAccountInfo(GetAccountInfoRequest) returns (GetAccountInfoResponse); - - // Get current portfolio positions - rpc GetPositions(GetPositionsRequest) returns (GetPositionsResponse); - - // Subscribe to real-time market data feeds - rpc SubscribeMarketData(SubscribeMarketDataRequest) returns (stream MarketDataEvent); - - // Subscribe to real-time order status updates - rpc SubscribeOrderUpdates(SubscribeOrderUpdatesRequest) returns (stream OrderUpdateEvent); - - // Integrated Risk Management - // Calculate portfolio Value at Risk (VaR) - rpc GetVaR(GetVaRRequest) returns (GetVaRResponse); - - // Analyze position-level risk exposure - rpc GetPositionRisk(GetPositionRiskRequest) returns (GetPositionRiskResponse); - - // Validate order against risk limits before submission - rpc ValidateOrder(ValidateOrderRequest) returns (ValidateOrderResponse); - - // Get comprehensive portfolio risk metrics - rpc GetRiskMetrics(GetRiskMetricsRequest) returns (GetRiskMetricsResponse); - - // Subscribe to real-time risk alerts and violations - rpc SubscribeRiskAlerts(SubscribeRiskAlertsRequest) returns (stream RiskAlertEvent); - - // Emergency stop with immediate trading halt - rpc EmergencyStop(EmergencyStopRequest) returns (EmergencyStopResponse); - - // Integrated System Monitoring - // Get system performance metrics - rpc GetMetrics(GetMetricsRequest) returns (GetMetricsResponse); - - // Get latency performance statistics - rpc GetLatency(GetLatencyRequest) returns (GetLatencyResponse); - - // Get throughput and capacity metrics - rpc GetThroughput(GetThroughputRequest) returns (GetThroughputResponse); - - // Subscribe to real-time performance metrics - rpc SubscribeMetrics(SubscribeMetricsRequest) returns (stream MetricsEvent); - - // Integrated Configuration Management - // Update system parameters and settings - rpc UpdateParameters(UpdateParametersRequest) returns (UpdateParametersResponse); - - // Get current configuration values - rpc GetConfig(GetConfigRequest) returns (GetConfigResponse); - - // Subscribe to configuration changes - rpc SubscribeConfig(SubscribeConfigRequest) returns (stream ConfigEvent); - - // Integrated System Health Monitoring - // Get overall system health and service status - rpc GetSystemStatus(GetSystemStatusRequest) returns (GetSystemStatusResponse); - - // Subscribe to system status changes and alerts - rpc SubscribeSystemStatus(SubscribeSystemStatusRequest) returns (stream SystemStatusEvent); - - // ML Trading Operations - // Submit ML-powered trading order with ensemble predictions - rpc SubmitMLOrder(SubmitMLOrderRequest) returns (SubmitMLOrderResponse); - - // Get ML prediction history with outcomes - rpc GetMLPredictions(GetMLPredictionsRequest) returns (GetMLPredictionsResponse); - - // Get ML model performance metrics - rpc GetMLPerformance(GetMLPerformanceRequest) returns (GetMLPerformanceResponse); - - // Wave D: Regime Detection Operations - // Get current regime state for a symbol - rpc GetRegimeState(GetRegimeStateRequest) returns (GetRegimeStateResponse); - - // Get regime transition history for a symbol - rpc GetRegimeTransitions(GetRegimeTransitionsRequest) returns (GetRegimeTransitionsResponse); -} - -// Order submission request -message SubmitOrderRequest { - string symbol = 1; - OrderSide side = 2; - OrderType order_type = 3; - double quantity = 4; - optional double price = 5; - optional double stop_price = 6; - string time_in_force = 7; - string client_order_id = 8; -} - -// Order submission response -message SubmitOrderResponse { - bool success = 1; - string order_id = 2; - string message = 3; - int64 timestamp_unix_nanos = 4; -} - -// Order cancellation request -message CancelOrderRequest { - string order_id = 1; - string symbol = 2; -} - -// Order cancellation response -message CancelOrderResponse { - bool success = 1; - string message = 2; - int64 timestamp_unix_nanos = 3; -} - -// Order status request -message GetOrderStatusRequest { - string order_id = 1; -} - -// Order status response -message GetOrderStatusResponse { - string order_id = 1; - string symbol = 2; - OrderSide side = 3; - OrderType order_type = 4; - double quantity = 5; - double filled_quantity = 6; - double remaining_quantity = 7; - double average_price = 8; - OrderStatus status = 9; - int64 created_at_unix_nanos = 10; - int64 updated_at_unix_nanos = 11; -} - -// Account information request -message GetAccountInfoRequest { - string account_id = 1; -} - -// Account information response -message GetAccountInfoResponse { - string account_id = 1; - double total_value = 2; - double cash_balance = 3; - double buying_power = 4; - double maintenance_margin = 5; - double day_trading_buying_power = 6; -} - -// Positions request -message GetPositionsRequest { - optional string symbol = 1; // Filter by symbol if provided -} - -// Positions response -message GetPositionsResponse { - repeated Position positions = 1; -} - -// Position information -message Position { - string symbol = 1; - double quantity = 2; - double market_price = 3; - double market_value = 4; - double average_cost = 5; - double unrealized_pnl = 6; - double realized_pnl = 7; -} - -// Market data subscription request -message SubscribeMarketDataRequest { - repeated string symbols = 1; - repeated MarketDataType data_types = 2; -} - -// Market data event -message MarketDataEvent { - oneof event { - TickData tick = 1; - QuoteData quote = 2; - TradeData trade = 3; - BarData bar = 4; - } -} - -// Tick data -message TickData { - string symbol = 1; - int64 timestamp_unix_nanos = 2; - double price = 3; - uint64 size = 4; - string exchange = 5; -} - -// Quote data -message QuoteData { - string symbol = 1; - int64 timestamp_unix_nanos = 2; - double bid_price = 3; - uint64 bid_size = 4; - double ask_price = 5; - uint64 ask_size = 6; - string exchange = 7; -} - -// Trade data -message TradeData { - string symbol = 1; - int64 timestamp_unix_nanos = 2; - double price = 3; - uint64 size = 4; - string trade_id = 5; - string exchange = 6; -} - -// Bar data -message BarData { - string symbol = 1; - int64 timestamp_unix_nanos = 2; - string timeframe = 3; - double open = 4; - double high = 5; - double low = 6; - double close = 7; - uint64 volume = 8; - optional double vwap = 9; -} - -// Order updates subscription request -message SubscribeOrderUpdatesRequest { - optional string account_id = 1; -} - -// Order update event -message OrderUpdateEvent { - string order_id = 1; - string symbol = 2; - OrderStatus status = 3; - double filled_quantity = 4; - double remaining_quantity = 5; - double last_fill_price = 6; - uint64 last_fill_quantity = 7; - int64 timestamp_unix_nanos = 8; - string message = 9; -} - - -// Monitoring messages -message GetMetricsRequest { - repeated string metric_names = 1; - optional int64 start_time_unix_nanos = 2; - optional int64 end_time_unix_nanos = 3; -} - -message GetMetricsResponse { - repeated Metric metrics = 1; - int64 timestamp_unix_nanos = 2; -} - -message Metric { - string name = 1; - double value = 2; - string unit = 3; - map labels = 4; - int64 timestamp_unix_nanos = 5; -} - -message GetLatencyRequest { - optional string service_name = 1; - optional string operation = 2; - optional int64 start_time_unix_nanos = 3; - optional int64 end_time_unix_nanos = 4; -} - -message GetLatencyResponse { - double p50_micros = 1; - double p95_micros = 2; - double p99_micros = 3; - double p999_micros = 4; - double avg_micros = 5; - double max_micros = 6; - double min_micros = 7; - uint64 sample_count = 8; -} - -message GetThroughputRequest { - optional string service_name = 1; - optional string operation = 2; - optional int64 start_time_unix_nanos = 3; - optional int64 end_time_unix_nanos = 4; -} - -message GetThroughputResponse { - double requests_per_second = 1; - double bytes_per_second = 2; - uint64 total_requests = 3; - uint64 total_bytes = 4; - uint64 error_count = 5; - double error_rate = 6; -} - -message SubscribeMetricsRequest { - repeated string metric_names = 1; - uint32 interval_seconds = 2; -} - -message MetricsEvent { - repeated Metric metrics = 1; - int64 timestamp_unix_nanos = 2; -} - -// Configuration messages -message UpdateParametersRequest { - map parameters = 1; - bool persist = 2; -} - -message UpdateParametersResponse { - bool success = 1; - string message = 2; - repeated string updated_keys = 3; -} - -message GetConfigRequest { - repeated string keys = 1; // Empty to get all config -} - -message GetConfigResponse { - map config = 1; - int64 version = 2; - int64 last_updated_unix_nanos = 3; -} - -message SubscribeConfigRequest { - repeated string keys = 1; // Empty to watch all config changes -} - -message ConfigEvent { - string key = 1; - string value = 2; - string old_value = 3; - int64 timestamp_unix_nanos = 4; -} - -// Enums - -// Order direction for trading operations -enum OrderSide { - ORDER_SIDE_UNSPECIFIED = 0; // Default/unknown side - ORDER_SIDE_BUY = 1; // Buy order (long position) - ORDER_SIDE_SELL = 2; // Sell order (short position) -} - -// Order execution type -enum OrderType { - ORDER_TYPE_UNSPECIFIED = 0; // Default/unknown type - ORDER_TYPE_MARKET = 1; // Execute immediately at market price - ORDER_TYPE_LIMIT = 2; // Execute only at specified price or better - ORDER_TYPE_STOP = 3; // Market order triggered at stop price - ORDER_TYPE_STOP_LIMIT = 4; // Limit order triggered at stop price -} - -// Current lifecycle status of orders -enum OrderStatus { - ORDER_STATUS_UNSPECIFIED = 0; // Default/unknown status - ORDER_STATUS_NEW = 1; // Order created and submitted - ORDER_STATUS_PARTIALLY_FILLED = 2; // Order partially executed - ORDER_STATUS_FILLED = 3; // Order completely executed - ORDER_STATUS_CANCELLED = 4; // Order cancelled - ORDER_STATUS_REJECTED = 5; // Order rejected by exchange or system - ORDER_STATUS_PENDING_CANCEL = 6; // Cancellation request pending -} - -enum MarketDataType { - MARKET_DATA_TYPE_UNSPECIFIED = 0; - MARKET_DATA_TYPE_TICKS = 1; - MARKET_DATA_TYPE_QUOTES = 2; - MARKET_DATA_TYPE_TRADES = 3; - MARKET_DATA_TYPE_BARS = 4; -} - - -message GetSystemStatusRequest { - repeated string service_names = 1; // Empty to get all services -} - -message GetSystemStatusResponse { - SystemStatus overall_status = 1; - repeated ServiceStatus services = 2; - int64 timestamp_unix_nanos = 3; -} - -message ServiceStatus { - string name = 1; - SystemStatus status = 2; - string message = 3; - int64 last_check_unix_nanos = 4; - map details = 5; -} - -message SubscribeSystemStatusRequest { - repeated string service_names = 1; -} - -message SystemStatusEvent { - string service_name = 1; - SystemStatus status = 2; - SystemStatus previous_status = 3; - string message = 4; - int64 timestamp_unix_nanos = 5; -} - -enum SystemStatus { - SYSTEM_STATUS_UNKNOWN = 0; - SYSTEM_STATUS_HEALTHY = 1; - SYSTEM_STATUS_DEGRADED = 2; - SYSTEM_STATUS_UNHEALTHY = 3; - SYSTEM_STATUS_CRITICAL = 4; -} - - -// VaR calculation request -message GetVaRRequest { - repeated string symbols = 1; - double confidence_level = 2; // e.g., 0.95, 0.99 - uint32 lookback_days = 3; - VaRMethodology methodology = 4; -} - -// VaR calculation response -message GetVaRResponse { - double portfolio_var = 1; - repeated SymbolVaR symbol_vars = 2; - int64 timestamp_unix_nanos = 3; - string methodology_used = 4; -} - -message SymbolVaR { - string symbol = 1; - double var_amount = 2; - double contribution_percent = 3; -} - -// Position risk analysis -message GetPositionRiskRequest { - optional string symbol = 1; // Empty for all positions -} - -message GetPositionRiskResponse { - repeated PositionRisk positions = 1; - double total_exposure = 2; - double concentration_risk = 3; - int64 timestamp_unix_nanos = 4; -} - -message PositionRisk { - string symbol = 1; - double position_size = 2; - double market_value = 3; - double var_contribution = 4; - double concentration_percent = 5; - RiskLevel risk_level = 6; -} - -// Order validation request -message ValidateOrderRequest { - string symbol = 1; - OrderSide side = 2; - double quantity = 3; - double price = 4; - string account_id = 5; -} - -message ValidateOrderResponse { - bool approved = 1; - string reason = 2; - repeated RiskViolation violations = 3; - double projected_exposure = 4; - double margin_impact = 5; -} - -message RiskViolation { - ViolationType type = 1; - string description = 2; - double limit_value = 3; - double current_value = 4; - RiskSeverity severity = 5; -} - -// Risk metrics request -message GetRiskMetricsRequest { - optional string portfolio_id = 1; - optional int64 start_time_unix_nanos = 2; - optional int64 end_time_unix_nanos = 3; -} - -message GetRiskMetricsResponse { - double sharpe_ratio = 1; - double max_drawdown = 2; - double current_drawdown = 3; - double volatility = 4; - double beta = 5; - double alpha = 6; - double value_at_risk = 7; - double expected_shortfall = 8; - int64 timestamp_unix_nanos = 9; -} - -// Risk alerts subscription -message SubscribeRiskAlertsRequest { - repeated RiskSeverity min_severity = 1; - repeated string symbols = 2; // Empty for all symbols -} - -message RiskAlertEvent { - string alert_id = 1; - RiskSeverity severity = 2; - string symbol = 3; - string message = 4; - double threshold_value = 5; - double current_value = 6; - int64 timestamp_unix_nanos = 7; - bool requires_action = 8; -} - -// Emergency stop -message EmergencyStopRequest { - EmergencyStopType stop_type = 1; - string reason = 2; - repeated string symbols = 3; // Empty for all - bool confirm = 4; -} - -message EmergencyStopResponse { - bool success = 1; - string message = 2; - uint32 orders_cancelled = 3; - uint32 positions_closed = 4; - int64 timestamp_unix_nanos = 5; -} - -// Backtesting Service provides comprehensive strategy backtesting capabilities for the TLI. -// This service allows users to test trading strategies against historical data with detailed -// performance analytics, risk metrics, and trade-by-trade analysis. -service BacktestingService { - // Backtest Execution Management - // Start a new strategy backtest with historical data - rpc StartBacktest(StartBacktestRequest) returns (StartBacktestResponse); - - // Get current status of a running backtest - rpc GetBacktestStatus(GetBacktestStatusRequest) returns (GetBacktestStatusResponse); - - // Get comprehensive backtest results and analytics - rpc GetBacktestResults(GetBacktestResultsRequest) returns (GetBacktestResultsResponse); - - // List historical backtest runs with filtering - rpc ListBacktests(ListBacktestsRequest) returns (ListBacktestsResponse); - - // Subscribe to real-time backtest progress updates - rpc SubscribeBacktestProgress(SubscribeBacktestProgressRequest) returns (stream BacktestProgressEvent); - - // Stop a running backtest and optionally save partial results - rpc StopBacktest(StopBacktestRequest) returns (StopBacktestResponse); -} - -// Start backtest request -message StartBacktestRequest { - string strategy_name = 1; - repeated string symbols = 2; - int64 start_date_unix_nanos = 3; - int64 end_date_unix_nanos = 4; - double initial_capital = 5; - map parameters = 6; - bool save_results = 7; - string description = 8; -} - -message StartBacktestResponse { - bool success = 1; - string backtest_id = 2; - string message = 3; - int64 estimated_duration_seconds = 4; -} - -// Backtest status -message GetBacktestStatusRequest { - string backtest_id = 1; -} - -message GetBacktestStatusResponse { - string backtest_id = 1; - BacktestStatus status = 2; - double progress_percentage = 3; - string current_date = 4; - uint64 trades_executed = 5; - double current_pnl = 6; - int64 started_at_unix_nanos = 7; - optional int64 completed_at_unix_nanos = 8; - optional string error_message = 9; -} - -// Backtest results -message GetBacktestResultsRequest { - string backtest_id = 1; - bool include_trades = 2; - bool include_metrics = 3; -} - -message GetBacktestResultsResponse { - string backtest_id = 1; - BacktestMetrics metrics = 2; - repeated Trade trades = 3; - repeated EquityCurvePoint equity_curve = 4; - repeated DrawdownPeriod drawdown_periods = 5; -} - -message BacktestMetrics { - double total_return = 1; - double annualized_return = 2; - double sharpe_ratio = 3; - double sortino_ratio = 4; - double max_drawdown = 5; - double volatility = 6; - double win_rate = 7; - double profit_factor = 8; - uint64 total_trades = 9; - uint64 winning_trades = 10; - uint64 losing_trades = 11; - double avg_win = 12; - double avg_loss = 13; - double largest_win = 14; - double largest_loss = 15; - double calmar_ratio = 16; - int64 backtest_duration_nanos = 17; -} - -message Trade { - string trade_id = 1; - string symbol = 2; - OrderSide side = 3; - double quantity = 4; - double entry_price = 5; - double exit_price = 6; - int64 entry_time_unix_nanos = 7; - int64 exit_time_unix_nanos = 8; - double pnl = 9; - double return_percent = 10; - string entry_signal = 11; - string exit_signal = 12; -} - -message EquityCurvePoint { - int64 timestamp_unix_nanos = 1; - double equity = 2; - double drawdown = 3; - double benchmark_equity = 4; -} - -message DrawdownPeriod { - int64 start_time_unix_nanos = 1; - int64 end_time_unix_nanos = 2; - double peak_value = 3; - double trough_value = 4; - double drawdown_percent = 5; - uint32 duration_days = 6; -} - -// List backtests -message ListBacktestsRequest { - uint32 limit = 1; - uint32 offset = 2; - optional string strategy_name = 3; - optional BacktestStatus status_filter = 4; -} - -message ListBacktestsResponse { - repeated BacktestSummary backtests = 1; - uint32 total_count = 2; -} - -message BacktestSummary { - string backtest_id = 1; - string strategy_name = 2; - repeated string symbols = 3; - BacktestStatus status = 4; - double total_return = 5; - double sharpe_ratio = 6; - double max_drawdown = 7; - int64 created_at_unix_nanos = 8; - int64 start_date_unix_nanos = 9; - int64 end_date_unix_nanos = 10; - string description = 11; -} - -// Backtest progress subscription -message SubscribeBacktestProgressRequest { - string backtest_id = 1; -} - -message BacktestProgressEvent { - string backtest_id = 1; - double progress_percentage = 2; - string current_date = 3; - uint64 trades_executed = 4; - double current_pnl = 5; - double current_equity = 6; - BacktestStatus status = 7; - int64 timestamp_unix_nanos = 8; -} - -// Stop backtest -message StopBacktestRequest { - string backtest_id = 1; - bool save_partial_results = 2; -} - -message StopBacktestResponse { - bool success = 1; - string message = 2; - bool results_saved = 3; -} - -// Additional enums for risk and backtesting -enum VaRMethodology { - VAR_METHODOLOGY_UNSPECIFIED = 0; - VAR_METHODOLOGY_HISTORICAL = 1; - VAR_METHODOLOGY_MONTE_CARLO = 2; - VAR_METHODOLOGY_PARAMETRIC = 3; - VAR_METHODOLOGY_EXPECTED_SHORTFALL = 4; -} - -enum RiskLevel { - RISK_LEVEL_UNSPECIFIED = 0; - RISK_LEVEL_LOW = 1; - RISK_LEVEL_MEDIUM = 2; - RISK_LEVEL_HIGH = 3; - RISK_LEVEL_CRITICAL = 4; -} - -enum ViolationType { - VIOLATION_TYPE_UNSPECIFIED = 0; - VIOLATION_TYPE_POSITION_LIMIT = 1; - VIOLATION_TYPE_CONCENTRATION = 2; - VIOLATION_TYPE_VAR_LIMIT = 3; - VIOLATION_TYPE_MARGIN = 4; - VIOLATION_TYPE_DRAWDOWN = 5; -} - -enum RiskSeverity { - RISK_SEVERITY_UNSPECIFIED = 0; - RISK_SEVERITY_INFO = 1; - RISK_SEVERITY_WARNING = 2; - RISK_SEVERITY_CRITICAL = 3; - RISK_SEVERITY_EMERGENCY = 4; -} - -enum EmergencyStopType { - EMERGENCY_STOP_TYPE_UNSPECIFIED = 0; - EMERGENCY_STOP_TYPE_CANCEL_ORDERS = 1; - EMERGENCY_STOP_TYPE_CLOSE_POSITIONS = 2; - EMERGENCY_STOP_TYPE_FULL_SHUTDOWN = 3; -} - -enum BacktestStatus { - BACKTEST_STATUS_UNSPECIFIED = 0; - BACKTEST_STATUS_QUEUED = 1; - BACKTEST_STATUS_RUNNING = 2; - BACKTEST_STATUS_COMPLETED = 3; - BACKTEST_STATUS_FAILED = 4; - BACKTEST_STATUS_CANCELLED = 5; - BACKTEST_STATUS_PAUSED = 6; -} - -// ML Trading Messages - -// Submit ML-powered order request -message SubmitMLOrderRequest { - string symbol = 1; // Trading symbol (e.g., "ES.FUT") - string account_id = 2; // Trading account identifier - optional string model_filter = 3; // Optional model filter: "DQN", "MAMBA2", "PPO", "TFT", or null for ensemble -} - -// Submit ML-powered order response -message SubmitMLOrderResponse { - string order_id = 1; // Order ID if executed - string symbol = 2; // Trading symbol - string model_used = 3; // "Ensemble" or specific model name - string predicted_action = 4; // Action taken: BUY, SELL, HOLD - double confidence = 5; // Prediction confidence (0.0-1.0) - int32 quantity = 6; // Order quantity - bool executed = 7; // True if order was submitted - string message = 8; // Status message -} - -// Get ML predictions request -message GetMLPredictionsRequest { - string symbol = 1; // Trading symbol to filter by - optional string model_filter = 2; // Optional model filter - optional int32 limit = 3; // Maximum predictions to return (default: 10) -} - -// Get ML predictions response -message GetMLPredictionsResponse { - repeated MLPrediction predictions = 1; // List of predictions with outcomes -} - -// Single ML prediction with outcome -message MLPrediction { - string timestamp = 1; // Prediction timestamp (ISO 8601) - string model_id = 2; // Model identifier - string symbol = 3; // Trading symbol - string predicted_action = 4; // Predicted action: BUY, SELL, HOLD - double confidence = 5; // Prediction confidence (0.0-1.0) - optional double actual_return = 6; // Actual return if outcome known -} - -// Get ML performance request -message GetMLPerformanceRequest { - optional string model_filter = 1; // Optional model filter -} - -// Get ML performance response -message GetMLPerformanceResponse { - repeated ModelPerformance models = 1; // Performance metrics per model - double ensemble_threshold = 2; // Ensemble confidence threshold - int32 active_models = 3; // Number of active models - int32 total_models = 4; // Total number of models -} - -// Performance metrics for a single model -message ModelPerformance { - string model_id = 1; // Model identifier - double accuracy = 2; // Accuracy rate (0.0-1.0) - int64 total_predictions = 3; // Total predictions made - double sharpe_ratio = 4; // Risk-adjusted return - double avg_return = 5; // Average return per prediction - double max_drawdown = 6; // Maximum drawdown -} - -// Wave D: Regime Detection Messages - -// Request to get current regime state -message GetRegimeStateRequest { - string symbol = 1; // Trading symbol to query -} - -// Response containing current regime state -message GetRegimeStateResponse { - string symbol = 1; // Trading symbol - string current_regime = 2; // Current regime: TRENDING, RANGING, VOLATILE, CRISIS - double confidence = 3; // Regime confidence (0.0-1.0) - double cusum_s_plus = 4; // CUSUM S+ statistic - double cusum_s_minus = 5; // CUSUM S- statistic - double adx = 6; // Average Directional Index - double stability = 7; // Regime stability score (0.0-1.0) - double entropy = 8; // Transition entropy (0.0-1.0) - int64 updated_at_unix_nanos = 9; // Last update timestamp -} - -// Request to get regime transition history -message GetRegimeTransitionsRequest { - string symbol = 1; // Trading symbol to query - int32 limit = 2; // Maximum transitions to return (default: 100) -} - -// Response containing regime transition history -message GetRegimeTransitionsResponse { - repeated RegimeTransition transitions = 1; // List of regime transitions -} - -// Single regime transition record -message RegimeTransition { - string from_regime = 1; // Previous regime - string to_regime = 2; // New regime - int32 duration_bars = 3; // Duration in previous regime (bars) - double transition_probability = 4; // Transition probability from matrix - int64 timestamp_unix_nanos = 5; // Transition timestamp -} diff --git a/bin/fxt/proto/trading_agent.proto b/bin/fxt/proto/trading_agent.proto deleted file mode 100644 index c51737cc2..000000000 --- a/bin/fxt/proto/trading_agent.proto +++ /dev/null @@ -1,615 +0,0 @@ -syntax = "proto3"; - -package trading_agent; - -// Trading Agent Service orchestrates trading decisions across universe selection, -// asset selection, portfolio allocation, and strategy coordination. -service TradingAgentService { - // Universe Management - // Select tradable universe based on liquidity, volatility, and ML signals - rpc SelectUniverse(SelectUniverseRequest) returns (SelectUniverseResponse); - - // Get current trading universe configuration - rpc GetUniverse(GetUniverseRequest) returns (GetUniverseResponse); - - // Update universe selection criteria - rpc UpdateUniverseCriteria(UpdateUniverseCriteriaRequest) returns (UpdateUniverseCriteriaResponse); - - // Asset Selection - // Select specific assets to trade within universe - rpc SelectAssets(SelectAssetsRequest) returns (SelectAssetsResponse); - - // Get current asset selection with scores - rpc GetSelectedAssets(GetSelectedAssetsRequest) returns (GetSelectedAssetsResponse); - - // Portfolio Allocation - // Allocate capital across selected assets - rpc AllocatePortfolio(AllocatePortfolioRequest) returns (AllocatePortfolioResponse); - - // Get current portfolio allocation - rpc GetAllocation(GetAllocationRequest) returns (GetAllocationResponse); - - // Rebalance portfolio based on target allocation - rpc RebalancePortfolio(RebalancePortfolioRequest) returns (RebalancePortfolioResponse); - - // Order Generation - // Generate orders based on allocation and ML signals - rpc GenerateOrders(GenerateOrdersRequest) returns (GenerateOrdersResponse); - - // Submit generated orders to Trading Service - rpc SubmitAgentOrders(SubmitAgentOrdersRequest) returns (SubmitAgentOrdersResponse); - - // Strategy Coordination - // Register a trading strategy with the agent - rpc RegisterStrategy(RegisterStrategyRequest) returns (RegisterStrategyResponse); - - // Get list of active strategies - rpc ListStrategies(ListStrategiesRequest) returns (ListStrategiesResponse); - - // Enable/disable a strategy - rpc UpdateStrategyStatus(UpdateStrategyStatusRequest) returns (UpdateStrategyStatusResponse); - - // Agent Monitoring - // Get comprehensive agent status and performance - rpc GetAgentStatus(GetAgentStatusRequest) returns (GetAgentStatusResponse); - - // Stream real-time agent decisions and actions - rpc StreamAgentActivity(StreamAgentActivityRequest) returns (stream AgentActivityEvent); - - // Get agent performance metrics - rpc GetAgentPerformance(GetAgentPerformanceRequest) returns (GetAgentPerformanceResponse); - - // Service Health - rpc HealthCheck(HealthCheckRequest) returns (HealthCheckResponse); -} - -// Universe Selection Messages - -message SelectUniverseRequest { - UniverseCriteria criteria = 1; // Selection criteria - optional uint32 max_instruments = 2; // Maximum instruments in universe - bool force_refresh = 3; // Force recalculation -} - -message SelectUniverseResponse { - repeated Instrument instruments = 1; // Selected instruments - UniverseMetrics metrics = 2; // Universe quality metrics - int64 timestamp = 3; // Selection timestamp (nanoseconds) - string universe_id = 4; // Unique universe identifier -} - -message GetUniverseRequest { - optional string universe_id = 1; // Get specific universe, or current if not specified -} - -message GetUniverseResponse { - string universe_id = 1; - repeated Instrument instruments = 2; - UniverseCriteria criteria = 3; - UniverseMetrics metrics = 4; - int64 created_at = 5; // Unix timestamp (nanoseconds) - int64 updated_at = 6; -} - -message UpdateUniverseCriteriaRequest { - UniverseCriteria criteria = 1; -} - -message UpdateUniverseCriteriaResponse { - bool success = 1; - string message = 2; - string universe_id = 3; // New universe ID after update -} - -// Asset Selection Messages - -message SelectAssetsRequest { - string universe_id = 1; // Universe to select from - AssetSelectionCriteria criteria = 2; // Selection criteria - uint32 max_assets = 3; // Maximum assets to select -} - -message SelectAssetsResponse { - repeated AssetScore assets = 1; // Selected assets with scores - SelectionMetrics metrics = 2; // Selection quality metrics - int64 timestamp = 3; -} - -message GetSelectedAssetsRequest { - optional string universe_id = 1; -} - -message GetSelectedAssetsResponse { - repeated AssetScore assets = 1; - SelectionMetrics metrics = 2; - int64 timestamp = 3; -} - -// Portfolio Allocation Messages - -message AllocatePortfolioRequest { - repeated AssetScore assets = 1; // Assets to allocate across - AllocationStrategy strategy = 2; // Allocation algorithm - RiskConstraints risk_constraints = 3; // Risk limits - double total_capital = 4; // Total capital to allocate -} - -message AllocatePortfolioResponse { - repeated AssetAllocation allocations = 1; // Allocation per asset - AllocationMetrics metrics = 2; // Allocation quality metrics - int64 timestamp = 3; - string allocation_id = 4; -} - -message GetAllocationRequest { - optional string allocation_id = 1; // Get specific allocation, or current if not specified -} - -message GetAllocationResponse { - string allocation_id = 1; - repeated AssetAllocation allocations = 2; - AllocationMetrics metrics = 3; - int64 created_at = 4; - double total_capital = 5; -} - -message RebalancePortfolioRequest { - string allocation_id = 1; // Target allocation - double rebalance_threshold = 2; // Min deviation to trigger rebalance (%) - bool force_rebalance = 3; // Force rebalance regardless of threshold -} - -message RebalancePortfolioResponse { - repeated RebalanceAction actions = 1; // Required rebalancing actions - RebalanceMetrics metrics = 2; - bool rebalance_required = 3; - int64 timestamp = 4; -} - -// Order Generation Messages - -message GenerateOrdersRequest { - string allocation_id = 1; // Target allocation - repeated MLSignal ml_signals = 2; // ML predictions for timing - OrderGenerationStrategy strategy = 3; // Order generation algorithm -} - -message GenerateOrdersResponse { - repeated GeneratedOrder orders = 1; // Generated order instructions - OrderGenerationMetrics metrics = 2; - int64 timestamp = 3; - string order_batch_id = 4; -} - -message SubmitAgentOrdersRequest { - string order_batch_id = 1; // Batch ID from GenerateOrders - repeated GeneratedOrder orders = 2; // Orders to submit - bool dry_run = 3; // Test without actual submission -} - -message SubmitAgentOrdersResponse { - repeated OrderSubmissionResult results = 1; // Submission results per order - OrderSubmissionMetrics metrics = 2; - int64 timestamp = 3; -} - -// Strategy Coordination Messages - -message RegisterStrategyRequest { - string strategy_name = 1; // Unique strategy name - StrategyType strategy_type = 2; // Strategy category - StrategyConfig config = 3; // Strategy configuration - bool auto_enable = 4; // Enable immediately after registration -} - -message RegisterStrategyResponse { - bool success = 1; - string strategy_id = 2; - string message = 3; -} - -message ListStrategiesRequest { - optional StrategyStatus status_filter = 1; // Filter by status -} - -message ListStrategiesResponse { - repeated Strategy strategies = 1; -} - -message UpdateStrategyStatusRequest { - string strategy_id = 1; - StrategyStatus new_status = 2; - optional string reason = 3; -} - -message UpdateStrategyStatusResponse { - bool success = 1; - string message = 2; - Strategy updated_strategy = 3; -} - -// Agent Monitoring Messages - -message GetAgentStatusRequest { - bool include_performance = 1; // Include performance metrics - bool include_positions = 2; // Include current positions -} - -message GetAgentStatusResponse { - AgentStatus status = 1; - optional AgentPerformanceMetrics performance = 2; - optional PositionSummary positions = 3; - int64 timestamp = 4; -} - -message StreamAgentActivityRequest { - repeated ActivityType activity_types = 1; // Filter by activity type -} - -message AgentActivityEvent { - ActivityType activity_type = 1; - oneof event { - UniverseSelectionEvent universe_event = 2; - AssetSelectionEvent asset_event = 3; - AllocationEvent allocation_event = 4; - OrderGenerationEvent order_event = 5; - StrategyEvent strategy_event = 6; - } - int64 timestamp = 7; -} - -message GetAgentPerformanceRequest { - optional int64 start_time = 1; // Performance window start (nanoseconds) - optional int64 end_time = 2; // Performance window end (nanoseconds) - bool include_strategy_breakdown = 3; // Include per-strategy performance -} - -message GetAgentPerformanceResponse { - AgentPerformanceMetrics metrics = 1; - repeated StrategyPerformance strategy_performance = 2; - int64 timestamp = 3; -} - -message HealthCheckRequest {} - -message HealthCheckResponse { - bool healthy = 1; - string message = 2; - map details = 3; -} - -// Data Structures - -message Instrument { - string symbol = 1; // Trading symbol (ES.FUT, NQ.FUT) - string exchange = 2; // Exchange identifier - InstrumentType instrument_type = 3; // Futures, equity, FX, etc. - double liquidity_score = 4; // Liquidity rating (0.0-1.0) - double volatility = 5; // Annualized volatility - double ml_signal_strength = 6; // ML prediction confidence - map metadata = 7; -} - -message UniverseCriteria { - double min_liquidity_score = 1; // Minimum liquidity threshold - double min_volatility = 2; // Minimum volatility - double max_volatility = 3; // Maximum volatility - repeated InstrumentType allowed_types = 4; - repeated string exchanges = 5; // Allowed exchanges - double min_ml_confidence = 6; // Minimum ML signal confidence -} - -message UniverseMetrics { - uint32 total_instruments = 1; - double avg_liquidity_score = 2; - double avg_volatility = 3; - double portfolio_diversification = 4; // 0.0-1.0 -} - -message AssetSelectionCriteria { - double min_ml_signal_strength = 1; // Minimum ML confidence - double min_sharpe_ratio = 2; // Minimum risk-adjusted return - SelectionMode mode = 3; // Top-N, threshold-based, etc. -} - -message AssetScore { - string symbol = 1; - double ml_score = 2; // ML model prediction score - double momentum_score = 3; // Momentum factor score - double value_score = 4; // Value factor score - double quality_score = 5; // Quality factor score - double composite_score = 6; // Final weighted score - map model_scores = 7; // Per-model scores (DQN, MAMBA2, etc.) -} - -message SelectionMetrics { - uint32 assets_evaluated = 1; - uint32 assets_selected = 2; - double avg_composite_score = 3; - double min_score = 4; - double max_score = 5; -} - -message AllocationStrategy { - AllocationType allocation_type = 1; // Equal-weight, risk-parity, etc. - map parameters = 2; // Strategy-specific parameters -} - -message RiskConstraints { - double max_position_size_pct = 1; // Max % of portfolio per position - double max_sector_exposure_pct = 2; // Max % per sector - double max_volatility = 3; // Portfolio volatility limit - double max_var_95 = 4; // Value at Risk (95%) - double max_leverage = 5; // Maximum leverage ratio -} - -message AssetAllocation { - string symbol = 1; - double target_weight = 2; // Target allocation weight (0.0-1.0) - double target_capital = 3; // Target capital in USD - double target_quantity = 4; // Target position size - double current_weight = 5; // Current allocation weight - double current_quantity = 6; // Current position size - double rebalance_delta = 7; // Required change -} - -message AllocationMetrics { - double total_weight = 1; // Should be ~1.0 - double portfolio_volatility = 2; // Expected portfolio volatility - double portfolio_sharpe = 3; // Expected Sharpe ratio - double var_95 = 4; // Portfolio VaR (95%) - double max_drawdown_estimate = 5; // Expected max drawdown -} - -message RebalanceAction { - string symbol = 1; - double current_quantity = 2; - double target_quantity = 3; - double delta_quantity = 4; // Positive = buy, negative = sell - RebalanceReason reason = 5; -} - -message RebalanceMetrics { - uint32 total_rebalance_actions = 1; - double total_turnover = 2; // Total capital moved (USD) - double estimated_cost = 3; // Estimated transaction costs -} - -message MLSignal { - string symbol = 1; - string model_name = 2; // DQN, MAMBA2, PPO, TFT - double signal_strength = 3; // -1.0 to 1.0 (short to long) - double confidence = 4; // 0.0 to 1.0 - string predicted_action = 5; // BUY, SELL, HOLD - int64 timestamp = 6; -} - -message OrderGenerationStrategy { - OrderGenerationMode mode = 1; - double slippage_tolerance = 2; // Max acceptable slippage (%) - bool use_limit_orders = 3; // Use limit orders vs market - double limit_price_offset = 4; // Offset from mid price (%) -} - -message GeneratedOrder { - string symbol = 1; - OrderSide side = 2; // BUY or SELL - double quantity = 3; - OrderType order_type = 4; // MARKET, LIMIT, etc. - optional double price = 5; // Limit price if applicable - string rationale = 6; // Why this order was generated - map metadata = 7; -} - -message OrderGenerationMetrics { - uint32 orders_generated = 1; - double total_notional = 2; // Total order value (USD) - double avg_order_size = 3; -} - -message OrderSubmissionResult { - string symbol = 1; - bool success = 2; - optional string order_id = 3; // From Trading Service - optional string error_message = 4; -} - -message OrderSubmissionMetrics { - uint32 orders_submitted = 1; - uint32 orders_accepted = 2; - uint32 orders_rejected = 3; - double acceptance_rate = 4; -} - -message Strategy { - string strategy_id = 1; - string strategy_name = 2; - StrategyType strategy_type = 3; - StrategyStatus status = 4; - StrategyConfig config = 5; - StrategyPerformance performance = 6; - int64 created_at = 7; - int64 updated_at = 8; -} - -message StrategyConfig { - map parameters = 1; // Strategy-specific parameters - repeated string target_symbols = 2; // Symbols this strategy trades - double max_capital_pct = 3; // Max % of portfolio for this strategy -} - -message StrategyPerformance { - string strategy_id = 1; - double total_pnl = 2; - double sharpe_ratio = 3; - double win_rate = 4; - uint32 total_trades = 5; - int64 period_start = 6; - int64 period_end = 7; -} - -message AgentStatus { - AgentState state = 1; - string current_universe_id = 2; - uint32 active_strategies = 3; - uint32 selected_assets = 4; - double portfolio_utilization = 5; // % of capital deployed - int64 last_action_timestamp = 6; -} - -message AgentPerformanceMetrics { - double total_pnl = 1; - double sharpe_ratio = 2; - double max_drawdown = 3; - double win_rate = 4; - uint32 total_trades = 5; - double avg_trade_pnl = 6; - double portfolio_turnover = 7; // Annualized - int64 period_start = 8; - int64 period_end = 9; -} - -message PositionSummary { - repeated Position positions = 1; - double total_equity = 2; - double total_exposure = 3; - double leverage_ratio = 4; -} - -message Position { - string symbol = 1; - double quantity = 2; - double average_price = 3; - double market_value = 4; - double unrealized_pnl = 5; - double weight = 6; // % of portfolio -} - -message UniverseSelectionEvent { - string universe_id = 1; - repeated string added_symbols = 2; - repeated string removed_symbols = 3; - UniverseMetrics metrics = 4; -} - -message AssetSelectionEvent { - repeated AssetScore selected_assets = 1; - SelectionMetrics metrics = 2; -} - -message AllocationEvent { - string allocation_id = 1; - repeated AssetAllocation allocations = 2; - AllocationMetrics metrics = 3; -} - -message OrderGenerationEvent { - string order_batch_id = 1; - repeated GeneratedOrder orders = 2; - OrderGenerationMetrics metrics = 3; -} - -message StrategyEvent { - string strategy_id = 1; - StrategyEventType event_type = 2; - string message = 3; -} - -// Enums - -enum InstrumentType { - INSTRUMENT_TYPE_UNSPECIFIED = 0; - INSTRUMENT_TYPE_EQUITY = 1; - INSTRUMENT_TYPE_FUTURES = 2; - INSTRUMENT_TYPE_FX = 3; - INSTRUMENT_TYPE_OPTIONS = 4; - INSTRUMENT_TYPE_CRYPTO = 5; -} - -enum SelectionMode { - SELECTION_MODE_UNSPECIFIED = 0; - SELECTION_MODE_TOP_N = 1; // Select top N by score - SELECTION_MODE_THRESHOLD = 2; // Select all above threshold - SELECTION_MODE_QUANTILE = 3; // Select top quantile (e.g., top 20%) -} - -enum AllocationType { - ALLOCATION_TYPE_UNSPECIFIED = 0; - ALLOCATION_TYPE_EQUAL_WEIGHT = 1; // 1/N allocation - ALLOCATION_TYPE_RISK_PARITY = 2; // Equal risk contribution - ALLOCATION_TYPE_ML_OPTIMIZED = 3; // ML-based optimization - ALLOCATION_TYPE_KELLY = 4; // Kelly criterion - ALLOCATION_TYPE_MEAN_VARIANCE = 5; // Mean-variance optimization -} - -enum RebalanceReason { - REBALANCE_REASON_UNSPECIFIED = 0; - REBALANCE_REASON_DRIFT = 1; // Allocation drifted from target - REBALANCE_REASON_UNIVERSE_CHANGE = 2; // Universe updated - REBALANCE_REASON_RISK_LIMIT = 3; // Risk limit violation - REBALANCE_REASON_MANUAL = 4; // Manual rebalance request -} - -enum OrderGenerationMode { - ORDER_GENERATION_MODE_UNSPECIFIED = 0; - ORDER_GENERATION_MODE_AGGRESSIVE = 1; // Market orders, immediate execution - ORDER_GENERATION_MODE_PASSIVE = 2; // Limit orders, minimize slippage - ORDER_GENERATION_MODE_ADAPTIVE = 3; // Adapt based on market conditions -} - -enum OrderSide { - ORDER_SIDE_UNSPECIFIED = 0; - ORDER_SIDE_BUY = 1; - ORDER_SIDE_SELL = 2; -} - -enum OrderType { - ORDER_TYPE_UNSPECIFIED = 0; - ORDER_TYPE_MARKET = 1; - ORDER_TYPE_LIMIT = 2; - ORDER_TYPE_STOP = 3; - ORDER_TYPE_STOP_LIMIT = 4; -} - -enum StrategyType { - STRATEGY_TYPE_UNSPECIFIED = 0; - STRATEGY_TYPE_ML_ENSEMBLE = 1; // Ensemble ML predictions - STRATEGY_TYPE_MEAN_REVERSION = 2; // Mean reversion - STRATEGY_TYPE_MOMENTUM = 3; // Momentum/trend following - STRATEGY_TYPE_ARBITRAGE = 4; // Statistical arbitrage - STRATEGY_TYPE_MARKET_MAKING = 5; // Market making -} - -enum StrategyStatus { - STRATEGY_STATUS_UNSPECIFIED = 0; - STRATEGY_STATUS_ENABLED = 1; - STRATEGY_STATUS_DISABLED = 2; - STRATEGY_STATUS_PAUSED = 3; - STRATEGY_STATUS_ERROR = 4; -} - -enum AgentState { - AGENT_STATE_UNSPECIFIED = 0; - AGENT_STATE_INITIALIZING = 1; - AGENT_STATE_ACTIVE = 2; - AGENT_STATE_PAUSED = 3; - AGENT_STATE_ERROR = 4; - AGENT_STATE_SHUTDOWN = 5; -} - -enum ActivityType { - ACTIVITY_TYPE_UNSPECIFIED = 0; - ACTIVITY_TYPE_UNIVERSE_SELECTION = 1; - ACTIVITY_TYPE_ASSET_SELECTION = 2; - ACTIVITY_TYPE_ALLOCATION = 3; - ACTIVITY_TYPE_ORDER_GENERATION = 4; - ACTIVITY_TYPE_STRATEGY = 5; -} - -enum StrategyEventType { - STRATEGY_EVENT_TYPE_UNSPECIFIED = 0; - STRATEGY_EVENT_TYPE_REGISTERED = 1; - STRATEGY_EVENT_TYPE_ENABLED = 2; - STRATEGY_EVENT_TYPE_DISABLED = 3; - STRATEGY_EVENT_TYPE_ERROR = 4; -} diff --git a/bin/fxt/src/commands/agent.rs b/bin/fxt/src/commands/agent.rs index 39f8b37a8..6ec60870c 100644 --- a/bin/fxt/src/commands/agent.rs +++ b/bin/fxt/src/commands/agent.rs @@ -18,15 +18,9 @@ use colored::Colorize; // Channel creation via crate::client::connect_channel use tonic::Request; -// Import generated proto types -#[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)] -pub mod trading_agent_proto { - tonic::include_proto!("trading_agent"); -} - use tonic::metadata::MetadataValue; -use trading_agent_proto::{ +use crate::proto::trading_agent::{ trading_agent_service_client::TradingAgentServiceClient, AllocatePortfolioRequest, AllocationStrategy, AllocationType, GetSelectedAssetsRequest, RiskConstraints, }; diff --git a/bin/fxt/src/lib.rs b/bin/fxt/src/lib.rs index 8e9244650..8045264fe 100644 --- a/bin/fxt/src/lib.rs +++ b/bin/fxt/src/lib.rs @@ -187,73 +187,74 @@ impl std::fmt::Display for BuildInfo { /// /// This module contains all the auto-generated protobuf types and service clients /// used for communicating with the Foxhunt HFT system services via gRPC. +/// All protos are compiled from the workspace-root `proto/` directory. 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. + /// Trading service protobuf definitions (package `trading`) #[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)] pub mod trading { - tonic::include_proto!("foxhunt.tli"); + tonic::include_proto!("trading"); } - /// Health check service protobuf definitions - /// - /// Standard gRPC health check service for monitoring service availability - /// and connection status across all backend services. + /// Health check service protobuf definitions (package `grpc.health.v1`) #[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. + /// ML service protobuf definitions (package `ml`) #[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)] pub mod ml { - tonic::include_proto!("foxhunt.ml"); + tonic::include_proto!("ml"); } - /// Configuration service protobuf definitions - /// - /// Contains message types and service interfaces for system configuration - /// management, settings updates, and runtime parameter control. + /// Configuration service protobuf definitions (package `config`) #[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)] pub mod config { - tonic::include_proto!("foxhunt.config"); + tonic::include_proto!("config"); } - /// ML Training service protobuf definitions - /// - /// Contains message types and service interfaces for machine learning - /// training job management, hyperparameter tuning, and training monitoring. + /// ML Training service protobuf definitions (package `ml_training`) #[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. + /// Trading Agent service protobuf definitions (package `trading_agent`) #[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 + /// Broker Gateway service protobuf definitions (package `broker_gateway`) #[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. + /// Monitoring service protobuf definitions (package `monitoring`) #[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)] pub mod monitoring { tonic::include_proto!("monitoring"); } + + /// Risk service protobuf definitions (package `risk`) + #[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)] + pub mod risk { + tonic::include_proto!("risk"); + } + + /// Data acquisition service protobuf definitions (package `data_acquisition`) + #[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)] + pub mod data_acquisition { + tonic::include_proto!("data_acquisition"); + } + + /// Config service protobuf definitions (package `foxhunt.config`) + /// + /// Note: This is from `config_service.proto` (API Gateway config service), + /// distinct from `config.proto` (trading service config, package `config`). + #[allow(clippy::shadow_reuse, clippy::impl_trait_in_params, clippy::empty_structs_with_brackets)] + pub mod config_service { + tonic::include_proto!("foxhunt.config"); + } }