Files
foxhunt/data/examples/account_portfolio_demo.rs
jgrusewski cb515363a9 fix(warnings): Eliminate 136 warnings across workspace via 11 parallel agents
## 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>
2025-11-03 10:15:09 +01:00

201 lines
6.3 KiB
Rust

#![allow(unused_crate_dependencies)]
use common::{OrderId, OrderSide, Price, Quantity, Symbol};
use data::brokers::interactive_brokers::{IBConfig, InteractiveBrokersAdapter};
use data::brokers::BrokerClient;
use tokio::time::{sleep, Duration};
use tracing::error;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
println!("=== Interactive Brokers Account & Portfolio Demo ===");
// Configure for paper trading environment
let config = IBConfig {
host: "127.0.0.1".to_string(),
port: 7497, // Paper trading TWS port
client_id: 1002,
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");
// Request account information
println!("\n=== Account Information ===");
match adapter.get_account_info().await {
Ok(account_info) => {
println!(
"Account ID: {}",
account_info
.get("account_id")
.unwrap_or(&"Unknown".to_string())
);
println!(
"Net Liquidation Value: ${:.2}",
account_info
.get("net_liquidation")
.and_then(|s| s.parse::<f64>().ok())
.unwrap_or(0.0)
);
println!(
"Available Funds: ${:.2}",
account_info
.get("available_funds")
.and_then(|s| s.parse::<f64>().ok())
.unwrap_or(0.0)
);
println!(
"Buying Power: ${:.2}",
account_info
.get("buying_power")
.and_then(|s| s.parse::<f64>().ok())
.unwrap_or(0.0)
);
println!(
"Day Trading Buying Power: ${:.2}",
account_info
.get("day_trading_buying_power")
.and_then(|s| s.parse::<f64>().ok())
.unwrap_or(0.0)
);
println!(
"Currency: {}",
account_info.get("currency").unwrap_or(&"USD".to_string())
);
},
Err(e) => error!("Failed to get account info: {}", e),
}
// Small delay for data processing
sleep(Duration::from_millis(1000)).await;
// Request portfolio positions
println!("\n=== Portfolio Positions ===");
match adapter.get_positions(None).await {
Ok(positions) => {
if positions.is_empty() {
println!("No positions found in portfolio");
} else {
println!("Found {} position(s):", positions.len());
for (i, position) in positions.into_iter().enumerate() {
println!(" {}. Symbol: {}", i + 1, position.symbol);
println!(" Quantity: {}", position.quantity);
println!(" Average Cost: ${:.4}", position.avg_cost);
println!(" Market Value: ${:.2}", position.market_value);
println!(" Unrealized PnL: ${:.2}", position.unrealized_pnl);
println!(" Realized PnL: ${:.2}", position.realized_pnl);
println!();
}
}
},
Err(e) => error!("Failed to get positions: {}", e),
}
// Request executions (recent trades)
println!("\n=== Recent Executions ===");
// NOTE: get_executions not implemented in broker adapter
println!("Execution history: Not available in demo - would query broker API for recent fills");
// Demonstrate real-time account updates
println!("=== Real-time Account Updates ===");
println!("Listening for account and portfolio updates for 15 seconds...");
let start_time = std::time::Instant::now();
while start_time.elapsed() < Duration::from_secs(15) {
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
let elapsed = start_time.elapsed().as_secs();
if elapsed % 5 == 0 && elapsed > 0 {
println!("Still monitoring... ({:.0}s elapsed)", elapsed);
}
}
// Final account summary
println!("\n=== Final Account Summary ===");
match adapter.get_account_info().await {
Ok(account_info) => {
println!(
"Final Net Liquidation Value: ${:.2}",
account_info
.get("net_liquidation")
.and_then(|s| s.parse::<f64>().ok())
.unwrap_or(0.0)
);
println!(
"Final Available Funds: ${:.2}",
account_info
.get("available_funds")
.and_then(|s| s.parse::<f64>().ok())
.unwrap_or(0.0)
);
},
Err(e) => error!("Failed to get final account info: {}", e),
}
println!("\nDisconnecting...");
adapter.disconnect().await?;
println!("✓ Account & Portfolio demo completed successfully");
Ok(())
}
// Example account information structure (would be defined in types crate)
#[allow(dead_code)]
struct AccountInfo {
account_id: String,
net_liquidation: f64,
available_funds: f64,
buying_power: f64,
day_trading_buying_power: f64,
currency: String,
}
// Example position structure
#[allow(dead_code)]
struct Position {
symbol: Symbol,
quantity: Quantity,
average_cost: Price,
market_value: f64,
unrealized_pnl: f64,
realized_pnl: f64,
}
// Example execution structure
#[allow(dead_code)]
struct Execution {
order_id: OrderId,
symbol: Symbol,
side: OrderSide,
quantity: Quantity,
price: Price,
commission: f64,
execution_time: String,
}