#[cfg(feature = "api-client")]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
use ib_flex::api::FlexApiClient;
use std::time::Duration;
let token = std::env::var("IB_FLEX_TOKEN")?;
let query_id = std::env::var("IB_FLEX_QUERY_ID")?;
let client = FlexApiClient::new(token);
println!("Sending request...");
let reference_code = client.send_request(&query_id).await?;
println!("Reference code: {}", reference_code);
println!("Fetching statement (with automatic retry)...");
let xml = client
.get_statement_with_retry(&reference_code, 10, Duration::from_secs(2))
.await?;
println!("Received statement ({} bytes)", xml.len());
let statement = ib_flex::parse_activity_flex(&xml)?;
println!("\nStatement Details:");
println!(" Account: {}", statement.account_id);
println!(" Period: {} to {}", statement.from_date, statement.to_date);
println!(" Trades: {}", statement.trades.items.len());
println!(" Positions: {}", statement.positions.items.len());
println!(
" Cash Transactions: {}",
statement.cash_transactions.items.len()
);
Ok(())
}
#[cfg(not(feature = "api-client"))]
fn main() {
eprintln!("This example requires the 'api-client' feature.");
eprintln!("Run with: cargo run --example api_with_retry --features api-client");
std::process::exit(1);
}