Files
foxhunt/config
jgrusewski c2687bf084 chore(clippy): add deny(unwrap_used) to config and trading_agent_service, fix 27 violations
- Add #![deny(clippy::unwrap_used, clippy::expect_used)] to config/src/lib.rs
- Add #![deny(clippy::unwrap_used, clippy::expect_used)] to trading_agent_service/src/lib.rs
- Add #![deny(clippy::unwrap_used, clippy::expect_used)] to trading_agent_service/src/main.rs (binary crate)

config crate fixes:
- asset_classification.rs: Replace .parse().unwrap() with Decimal::new() for tick/position sizes
- asset_classification.rs: Replace NaiveTime::from_hms_opt().unwrap() with .unwrap_or_default()
- asset_classification.rs: Add #[allow] on test module
- symbol_config.rs: Add #[allow] on test module (function-level allows already present)

trading_agent_service fixes:
- monitoring.rs: Add #[allow(clippy::expect_used)] on each Lazy static metric registration
- monitoring.rs: Fix start_metrics_server() runtime unwrap/expect calls with safe alternatives
- monitoring.rs: Add #[allow] on test module
- main.rs: Fix health_handler() .unwrap() with .unwrap_or_else() fallback
- main.rs: Fix metrics_handler() .unwrap()/.expect() with let _ / .unwrap_or_default()
- autonomous_scaling.rs: Fix capital parse .expect() with .unwrap_or(0.0)
- autonomous_scaling.rs: Replace .find().cloned().unwrap() with filter_map()
- autonomous_scaling.rs: Replace .find().unwrap() on tier lookup with let-else
- autonomous_scaling.rs: Add #[allow] on test module
- allocation.rs: Fix .unwrap() on Decimal::from_f64_retain(0.20) with .unwrap_or(Decimal::ZERO)
- allocation.rs: Add #[allow] on test module
- orders.rs: Replace BigDecimal::from_str("0").unwrap() with BigDecimal::from(0_i64)
- orders.rs: Add #[allow] on test module
- universe.rs, dynamic_stop_loss.rs, strategies.rs: Add #[allow] on test modules

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 00:01:40 +01:00
..

Config Crate

Overview

The config crate provides a centralized, dynamic, and secure configuration management solution for Foxhunt HFT services. It enables hot-reloading of configurations and integrates with robust secret management systems, ensuring operational flexibility and security.

Features

  • Centralized PostgreSQL Storage: Stores all application configurations in a PostgreSQL database, providing a single source of truth.
  • Dynamic Hot-Reloading: Leverages PostgreSQL's NOTIFY/LISTEN mechanism to push live configuration updates to running services without restarts.
  • Secure Secret Management: Integrates with HashiCorp Vault for secure storage and retrieval of sensitive credentials and secrets.
  • Schema-Validated Configurations: Enforces structured configuration schemas to prevent malformed or invalid configurations.
  • Model Configuration Management: Manages configurations for various trading models, including their parameters and associated S3 asset paths.
  • Service-Specific Schemas: Allows defining and validating distinct configuration schemas for each microservice or component.

Architecture

The config crate's architecture comprises:

  • Config Store: A PostgreSQL database instance dedicated to storing configuration data.
  • Config Loader: Component responsible for fetching configurations from PostgreSQL.
  • Vault Client: Interface for securely interacting with HashiCorp Vault to retrieve secrets.
  • Notifier/Listener: Utilizes PostgreSQL NOTIFY/LISTEN channels to signal and receive configuration changes for hot-reloading.
  • Schema Validator: Ensures that loaded configurations adhere to predefined JSON or YAML schemas.
  • Configuration Models: Rust structs that represent the structured configuration data, often deserialized from JSON/YAML stored in the database.

Usage

To load a configuration and listen for live updates:

use config::{
    ConfigManager,
    schema::ServiceConfig,
};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
struct MyServiceSpecificConfig {
    api_key_name: String,
    trade_threshold: f64,
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize ConfigManager with database connection and Vault client
    let config_manager = ConfigManager::new(
        "postgres://user:pass@localhost/foxhunt_config",
        "http://localhost:8200", // Vault address
    ).await?;

    // Load initial configuration for a specific service
    let initial_config: MyServiceSpecificConfig = config_manager
        .get_service_config("my_trading_service")
        .await?;
    println!("Initial config: {:?}", initial_config);

    // Subscribe to updates for this service's configuration
    let mut config_stream = config_manager
        .subscribe_to_service_config::<MyServiceSpecificConfig>("my_trading_service")
        .await?;

    println!("Listening for config updates...");

    tokio::spawn(async move {
        while let Some(updated_config) = config_stream.recv().await {
            println!("Configuration updated: {:?}", updated_config);
            // Apply the new configuration to the running service
        }
    });

    tokio::signal::ctrl_c().await?;
    println!("Shutting down config listener.");

    Ok(())
}

Testing

To run the tests for the config crate:

cargo test --package config

Documentation

Comprehensive API documentation is available at docs.rs/config.