## 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>
137 lines
4.1 KiB
Rust
137 lines
4.1 KiB
Rust
#![allow(unused_crate_dependencies)]
|
|
use common::{Price, Quantity, Symbol};
|
|
use data::brokers::interactive_brokers::{IBConfig, InteractiveBrokersAdapter};
|
|
use tokio::time::{sleep, Duration};
|
|
use tracing::error;
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
println!("=== Interactive Brokers Market Data Subscription Example ===");
|
|
|
|
// Configure for paper trading environment
|
|
let config = IBConfig {
|
|
host: "127.0.0.1".to_string(),
|
|
port: 7497, // Paper trading TWS port
|
|
client_id: 1001,
|
|
account_id: "DU123456".to_string(), // Demo account
|
|
connection_timeout: 30,
|
|
max_reconnect_attempts: 3,
|
|
heartbeat_interval: 60,
|
|
request_timeout: 10,
|
|
};
|
|
|
|
let mut adapter = InteractiveBrokersAdapter::new(config);
|
|
|
|
println!("Connecting to TWS...");
|
|
adapter.connect().await?;
|
|
|
|
if !adapter.is_connected() {
|
|
error!("Failed to establish connection");
|
|
return Ok(());
|
|
}
|
|
|
|
println!("✓ Connected successfully");
|
|
|
|
// Subscribe to market data for various symbols
|
|
let symbols = vec![
|
|
Symbol::from("AAPL"), // Apple stock
|
|
Symbol::from("MSFT"), // Microsoft stock
|
|
Symbol::from("SPY"), // S&P 500 ETF
|
|
Symbol::from("EUR.USD"), // EUR/USD forex pair
|
|
];
|
|
|
|
println!(
|
|
"\nSubscribing to market data for {} symbols...",
|
|
symbols.len()
|
|
);
|
|
|
|
let mut request_ids = Vec::new();
|
|
|
|
for symbol in &symbols {
|
|
match adapter.request_market_data(symbol).await {
|
|
Ok(request_id) => {
|
|
println!("✓ Subscribed to {} (request_id: {})", symbol, request_id);
|
|
request_ids.push(request_id);
|
|
},
|
|
Err(e) => error!("✗ Failed to subscribe to {}: {}", symbol, e),
|
|
}
|
|
|
|
// Small delay between subscriptions to avoid rate limiting
|
|
sleep(Duration::from_millis(100)).await;
|
|
}
|
|
|
|
println!("\nListening for market data updates for 30 seconds...");
|
|
println!("Market data will be processed in the background message loop");
|
|
|
|
// Listen for market data for 30 seconds
|
|
let start_time = std::time::Instant::now();
|
|
while start_time.elapsed() < Duration::from_secs(30) {
|
|
if !adapter.is_connected() {
|
|
println!("Connection lost, attempting to reconnect...");
|
|
if let Err(e) = adapter.connect().await {
|
|
error!("Reconnection failed: {}", e);
|
|
break;
|
|
}
|
|
}
|
|
|
|
sleep(Duration::from_millis(1000)).await;
|
|
|
|
// Print periodic status
|
|
if start_time.elapsed().as_secs() % 10 == 0 {
|
|
println!(
|
|
"Still listening... ({:.0}s elapsed)",
|
|
start_time.elapsed().as_secs()
|
|
);
|
|
}
|
|
}
|
|
|
|
println!("\nUnsubscribing from market data...");
|
|
|
|
// Cancel all market data subscriptions
|
|
for (symbol, request_id) in symbols.into_iter().zip(request_ids.into_iter()) {
|
|
match adapter.cancel_market_data(request_id).await {
|
|
Ok(_) => println!(
|
|
"✓ Unsubscribed from {} (request_id: {})",
|
|
symbol, request_id
|
|
),
|
|
Err(e) => error!("✗ Failed to unsubscribe from {}: {}", symbol, e),
|
|
}
|
|
}
|
|
|
|
println!("\nDisconnecting...");
|
|
adapter.disconnect().await?;
|
|
|
|
println!("✓ Market data subscription example completed successfully");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
// Example of market data event handler (would be integrated with the adapter)
|
|
#[allow(dead_code)]
|
|
async fn handle_market_data_event(
|
|
symbol: Symbol,
|
|
bid: Price,
|
|
ask: Price,
|
|
last: Price,
|
|
volume: Quantity,
|
|
) {
|
|
println!(
|
|
"Market Data Update: {} - Bid: {}, Ask: {}, Last: {}, Volume: {}",
|
|
symbol, bid, ask, last, volume
|
|
);
|
|
}
|
|
|
|
// Example of tick-by-tick data handler
|
|
#[allow(dead_code)]
|
|
async fn handle_tick_data(
|
|
symbol: Symbol,
|
|
tick_type: &str,
|
|
price: Price,
|
|
size: Quantity,
|
|
timestamp: u64,
|
|
) {
|
|
println!(
|
|
"Tick Data: {} - Type: {}, Price: {}, Size: {}, Time: {}",
|
|
symbol, tick_type, price, size, timestamp
|
|
);
|
|
}
|