1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//! FLEX Web Service API client
//!
//! This module provides a client for the Interactive Brokers FLEX Web Service API,
//! allowing programmatic retrieval of FLEX statements without manual downloads.
//!
//! The FLEX Web Service API uses a two-step process:
//! 1. **SendRequest**: Submit a query ID with your token → receive a reference code
//! 2. **GetStatement**: Poll with the reference code → receive XML when ready
//!
//! ## Feature Flag
//!
//! This module requires the `api-client` feature:
//!
//! ```toml
//! [dependencies]
//! ib-flex = { version = "0.1", features = ["api-client"] }
//! ```
//!
//! ## Example
//!
//! ```rust,no_run
//! # #[cfg(feature = "api-client")]
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use ib_flex::api::FlexApiClient;
//! use std::time::Duration;
//!
//! // Create client with your token
//! let client = FlexApiClient::new("YOUR_TOKEN_HERE");
//!
//! // Step 1: Send request with your query ID
//! let reference_code = client.send_request("123456").await?;
//! println!("Reference code: {}", reference_code);
//!
//! // Step 2: Wait a moment for IB to generate the report
//! tokio::time::sleep(Duration::from_secs(5)).await;
//!
//! // Step 3: Get the statement XML
//! let xml = client.get_statement(&reference_code).await?;
//!
//! // Step 4: Parse the XML
//! let statement = ib_flex::parse_activity_flex(&xml)?;
//! println!("Trades: {}", statement.trades.items.len());
//! # Ok(())
//! # }
//! # #[cfg(not(feature = "api-client"))]
//! # fn main() {}
//! ```
//!
//! ## API Endpoints
//!
//! - **Base URL**: `https://gdcdyn.interactivebrokers.com/Universal/servlet`
//! - **SendRequest**: `FlexStatementService.SendRequest?t=TOKEN&q=QUERY_ID&v=3`
//! - **GetStatement**: `FlexStatementService.GetStatement?t=TOKEN&q=REFERENCE_CODE&v=3`
//!
//! ## References
//!
//! - [FLEX Web Service Documentation](https://www.interactivebrokers.com/campus/ibkr-api-page/flex-web-service/)
pub use ;