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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! # Interactive Brokers Client Portal Web API Connector
//!
//! Category: Aggregator (Multi-Asset Broker)
//! Type: Full-Service Broker with Trading and Market Data
//!
//! ## Features
//! - **REST API**: Yes (Client Portal Web API v1.0)
//! - **WebSocket**: Yes (real-time streaming)
//! - **Authentication**: Gateway Session (manual browser login) or OAuth 2.0
//! - **Free tier**: No (requires active IBKR Pro account)
//!
//! ## Asset Classes Supported
//! - Stocks (Equities) - Global stocks on 150+ markets
//! - Forex (FX/CASH) - Spot FX trading
//! - Futures - Commodity, index, currency futures
//! - Options - Equity options, index options, futures options
//! - Bonds - Government and corporate bonds
//! - Mutual Funds & ETFs
//! - Cryptocurrencies (limited)
//! - CFDs (non-US accounts)
//!
//! ## Data Types
//! - Price data: Yes (real-time and delayed)
//! - Historical data: Yes (from 1 second to monthly bars)
//! - Derivatives data: Yes (futures, options)
//! - Fundamentals: Limited
//! - Market depth: Yes (Level 2)
//!
//! ## Trading Capabilities
//! - Order placement: Yes (Market, Limit, Stop, Stop-Limit, Trailing Stop)
//! - Order modification: Yes
//! - Order cancellation: Yes
//! - Account management: Yes (positions, balances, P&L)
//! - Portfolio analytics: Yes
//!
//! ## Authentication
//! - **Individual Accounts**: Client Portal Gateway (Java-based local proxy)
//! - Requires manual browser login (cannot be automated)
//! - Default URL: `https://localhost:5000/v1/api/`
//! - Two-factor authentication required
//! - Session timeout: ~6 minutes (requires periodic tickle)
//!
//! - **Enterprise Accounts**: OAuth 2.0 (Private Key JWT)
//! - Production URL: `https://api.ibkr.com/v1/api/`
//! - Fully automated authentication
//! - RSA key pair required
//!
//! ## Key Differences from Crypto Exchanges
//! - Uses Contract ID (conid) instead of symbols for all operations
//! - Requires contract search before trading
//! - Order confirmation flow (some orders require explicit confirmation)
//! - Session management with periodic tickle (keep-alive) required
//! - WebSocket uses text-based subscription format (not JSON)
//!
//! ## Rate Limits
//! - **Gateway (Individual)**: 10 requests per second
//! - **OAuth (Enterprise)**: 50 requests per second
//! - **Specific Endpoints**:
//! - `/tickle`: 1 req/s
//! - `/iserver/account/{accountId}/orders`: 1 req/5s
//! - `/iserver/marketdata/snapshot`: 10 req/s
//! - `/iserver/marketdata/history`: 5 concurrent max
//!
//! ## Limitations
//! - **Manual Authentication**: Individual accounts require browser login
//! - **Single Session**: Only one session per username
//! - **Market Data**: Requires active subscriptions (typically 100 concurrent)
//! - **Geographic**: Canadian residents cannot trade Canadian exchanges programmatically
//!
//! ## Usage Example
//! ```ignore
//! use connectors_v5::aggregators::ib::IBConnector;
//! use connectors_v5::core::types::{Symbol, AccountType};
//!
//! // Create connector (assumes Gateway is running and authenticated)
//! let connector = IBConnector::from_gateway("https://localhost:5000/v1/api", "DU12345").await?;
//!
//! // Get market data (automatically resolves symbol to conid)
//! let symbol = Symbol::new("AAPL", "USD");
//! let ticker = connector.get_ticker(symbol, AccountType::Spot).await?;
//!
//! // Place order
//! let order_result = connector.place_limit_order(
//! symbol,
//! OrderSide::Buy,
//! 100.0,
//! 185.50,
//! AccountType::Spot,
//! ).await?;
//! ```
//!
//! ## References
//! - [Client Portal Web API Documentation](https://interactivebrokers.github.io/cpwebapi/)
//! - [IBKR Campus API Page](https://www.interactivebrokers.com/campus/ibkr-api-page/cpapi-v1/)
//! - [WebSocket Streaming](https://www.interactivebrokers.com/campus/trading-lessons/websockets/)
pub use IBConnector;
pub use IBWebSocket;