## Summary
Pre-commit warning regression fix wave - deployed 11 parallel Task agents to systematically eliminate all compilation errors (2) and warnings (136) across the entire workspace.
## Changes by Category
### P0 Compilation Fixes (2 errors → 0)
- ml/src/hyperopt/adapters/mamba2.rs: Added missing `trial_counter: 0` to test initializers (lines 1135, 1165)
### ML Crate Warnings (35 → 0)
- ml/src/hyperopt/tests.rs: Added `#[allow(deprecated)]` for test-specific deprecated function usage
- ml/src/ensemble/ab_testing.rs: Renamed unused variables (_control_count, _rng)
- ml/src/security/*.rs: Fixed unused loop variables (i → _)
- ml/src/tft/quantized_attention.rs: Renamed unused test variable (_v)
- ml/src/features/regime_adaptive.rs: Renamed unused variables (_adaptive)
- ml/src/regime/{orchestrator,ranging}.rs: Renamed unused variables
### Data Crate Fixes (28 warnings + 4 errors → 0)
- data/Cargo.toml: Moved clap from [dev-dependencies] to [dependencies] (examples require it)
- data/examples/validate_cl_fut.rs: Updated to databento 0.42.0 API (decode_record_ref loop pattern)
- data/examples/download_mbp10_data.rs: Fixed reqwest 0.12 API (bytes_stream → chunk)
- data/examples/*.rs: Removed unused imports (4 files via cargo fix)
- data/tests/real_data_helpers.rs: Added `#[allow(dead_code)]` to cross-binary test helpers
### API Gateway Test Warnings (19 → 0)
- services/api_gateway/tests/common/mod.rs: Added `#[allow(dead_code)]` to shared test utilities (6 items)
- services/api_gateway/tests/rate_limiting_tests.rs: Added `#[allow(dead_code)]` to REDIS_URL constant
## Verification
```bash
cargo check --workspace
# Result: Finished in 49.41s
# Warnings: 0 (was 136)
# Errors: 0 (was 2)
```
## Files Modified: 26 total
- ML: 14 files (9 manual + 5 auto-fixed)
- Data: 10 files (2 Cargo.toml + 6 examples + 1 test + 1 dependency update)
- API Gateway: 2 test files
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
140 lines
4.8 KiB
Rust
140 lines
4.8 KiB
Rust
//! Real Market Data Helpers for Feature Engineering Tests
|
|
//!
|
|
//! Utilities to load real BTC/ETH Parquet data and convert it to formats
|
|
//! used by feature engineering tests (OHLCV bars, PricePoints).
|
|
|
|
use anyhow::{Context, Result};
|
|
use chrono::{DateTime, Utc};
|
|
use data::features::PricePoint;
|
|
use data::parquet_persistence::{MarketDataEvent, ParquetMarketDataReader};
|
|
use std::path::PathBuf;
|
|
|
|
/// Path to real test data directory (relative to workspace root)
|
|
const REAL_DATA_PATH: &str = "test_data/real/parquet";
|
|
const BTC_FILE: &str = "BTC-USD_30day_2024-09.parquet";
|
|
const ETH_FILE: &str = "ETH-USD_30day_2024-09.parquet";
|
|
|
|
/// Real market data loader for feature engineering tests
|
|
pub(crate) struct RealDataLoader {
|
|
base_path: String,
|
|
}
|
|
|
|
impl RealDataLoader {
|
|
/// Create new loader with workspace-relative path
|
|
pub(crate) fn new() -> Self {
|
|
let manifest_dir = env!("CARGO_MANIFEST_DIR");
|
|
let base_path = PathBuf::from(manifest_dir)
|
|
.parent()
|
|
.expect("Failed to get workspace root")
|
|
.join(REAL_DATA_PATH);
|
|
|
|
Self {
|
|
base_path: base_path.to_string_lossy().to_string(),
|
|
}
|
|
}
|
|
|
|
/// Check if real data files exist
|
|
pub(crate) fn files_exist(&self) -> bool {
|
|
let btc_path = PathBuf::from(&self.base_path).join(BTC_FILE);
|
|
let eth_path = PathBuf::from(&self.base_path).join(ETH_FILE);
|
|
btc_path.exists() && eth_path.exists()
|
|
}
|
|
|
|
/// Load BTC price data as PricePoints
|
|
#[allow(dead_code)]
|
|
pub(crate) async fn load_btc_prices(&self, count: usize) -> Result<Vec<PricePoint>> {
|
|
self.load_prices(BTC_FILE, count).await
|
|
}
|
|
|
|
/// Load ETH price data as PricePoints
|
|
#[allow(dead_code)]
|
|
pub(crate) async fn load_eth_prices(&self, count: usize) -> Result<Vec<PricePoint>> {
|
|
self.load_prices(ETH_FILE, count).await
|
|
}
|
|
|
|
/// Load BTC close prices as f64 vector (for simple technical indicator tests)
|
|
#[allow(dead_code)]
|
|
pub(crate) async fn load_btc_close_prices(&self, count: usize) -> Result<Vec<f64>> {
|
|
self.load_close_prices(BTC_FILE, count).await
|
|
}
|
|
|
|
/// Load ETH close prices as f64 vector (for simple technical indicator tests)
|
|
#[allow(dead_code)]
|
|
pub(crate) async fn load_eth_close_prices(&self, count: usize) -> Result<Vec<f64>> {
|
|
self.load_close_prices(ETH_FILE, count).await
|
|
}
|
|
|
|
/// Load price data from a specific file as PricePoints
|
|
#[allow(dead_code)]
|
|
async fn load_prices(&self, filename: &str, count: usize) -> Result<Vec<PricePoint>> {
|
|
let reader = ParquetMarketDataReader::new(self.base_path.clone());
|
|
let events = reader
|
|
.read_file(filename)
|
|
.await
|
|
.with_context(|| format!("Failed to load {}", filename))?;
|
|
|
|
// Take only the requested number of events
|
|
let events_subset = events.into_iter().take(count).collect::<Vec<_>>();
|
|
|
|
// Convert MarketDataEvent to PricePoint
|
|
let price_points = events_subset
|
|
.into_iter()
|
|
.map(|event| self.event_to_price_point(&event))
|
|
.collect::<Result<Vec<_>>>()?;
|
|
|
|
Ok(price_points)
|
|
}
|
|
|
|
/// Load close prices as f64 vector for simple indicator calculations
|
|
#[allow(dead_code)]
|
|
async fn load_close_prices(&self, filename: &str, count: usize) -> Result<Vec<f64>> {
|
|
let reader = ParquetMarketDataReader::new(self.base_path.clone());
|
|
let events = reader
|
|
.read_file(filename)
|
|
.await
|
|
.with_context(|| format!("Failed to load {}", filename))?;
|
|
|
|
// Take only the requested number of events and extract close prices
|
|
let close_prices = events
|
|
.into_iter()
|
|
.take(count)
|
|
.filter_map(|event| event.price) // Use price as close price
|
|
.collect::<Vec<_>>();
|
|
|
|
Ok(close_prices)
|
|
}
|
|
|
|
/// Convert MarketDataEvent to PricePoint
|
|
#[allow(dead_code)]
|
|
fn event_to_price_point(&self, event: &MarketDataEvent) -> Result<PricePoint> {
|
|
let timestamp = self.ns_to_datetime(event.timestamp_ns)?;
|
|
let close = event.price.context("Price is None")?;
|
|
|
|
// If OHLC data is available, use it; otherwise derive from close price
|
|
let open = event.open.unwrap_or(close);
|
|
let high = event.high.unwrap_or(close.max(open));
|
|
let low = event.low.unwrap_or(close.min(open));
|
|
|
|
Ok(PricePoint {
|
|
timestamp,
|
|
open,
|
|
high,
|
|
low,
|
|
close,
|
|
})
|
|
}
|
|
|
|
/// Convert nanosecond timestamp to DateTime<Utc>
|
|
#[allow(dead_code)]
|
|
fn ns_to_datetime(&self, timestamp_ns: u64) -> Result<DateTime<Utc>> {
|
|
let timestamp_ms = (timestamp_ns / 1_000_000) as i64;
|
|
DateTime::from_timestamp_millis(timestamp_ms).context("Invalid timestamp")
|
|
}
|
|
}
|
|
|
|
impl Default for RealDataLoader {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|