Expand description
Interactive Brokers ExecutionClient implementation.
Uses the ibapi crate for IB TWS/Gateway connectivity. Supports equities,
futures, options, and forex.
§Testing Status
NOT TESTED in CI. IBKR has not confirmed permission to use credentials for CI, and requires IB Gateway/TWS running locally.
Tested locally: All execution tests (connection, orders, account streaming) run on paper trading accounts — no market data subscriptions required.
§Connection
Requires TWS or IB Gateway running locally with API enabled:
| Application | Live Port | Paper Port |
|---|---|---|
| TWS | 7496 | 7497 |
| IB Gateway | 4001 | 4002 |
Enable API in TWS/Gateway: Configure → API → Settings → Enable ActiveX and Socket Clients. For order placement, uncheck “Read-Only API”.
§Architecture
- Connection: TCP socket to TWS/Gateway
- Orders: Subscription-based events (OrderStatus, ExecutionData, CommissionReport)
- Account: Subscription-based position and balance updates
§Limitations
- Order types: Market, Limit, Stop, StopLimit, TrailingStop, TrailingStopLimit, and Bracket (entry + take-profit + stop-loss) supported. No Algo orders.
- TimeInForce: No
post_only(IB has no maker-only orders) - No auto-reconnect: Caller responsibility per library philosophy
§Caller Responsibilities (Reconnection & Recovery)
Unlike WebSocket-based connectors (Binance, Alpaca), this client does not auto-reconnect. The caller must handle:
- Disconnect detection: Monitor
ExecutionClient::account_streamfor EOF or errors - Reconnection: Call
IbkrClient::connect_syncwith a new client ID - Fill recovery: After reconnect, call
ExecutionClient::fetch_tradesto query executions since disconnect, then deduplicate against known fills - Order reconciliation: Call
ExecutionClient::fetch_open_ordersto reconcile open-order state (order lifecycle events during disconnect are lost) - Stale state cleanup: Periodically call
IbkrClient::clear_stale_executions,IbkrClient::clear_stale_order_ids, andIbkrClient::clear_stale_pending_cancels
Rationale: IBKR uses TCP to local TWS/Gateway, not cloud WebSocket. Reconnection requires IB Gateway availability and client ID coordination — decisions that belong in the caller’s wrapper, not the library.
§See Also
- IB API Documentation
rustrade_data::exchange::ibkrfor market data
Re-exports§
pub use order::BracketOrderRequest;pub use order::BracketOrderResult;pub use execution::parse_ib_timestamp;
Modules§
Structs§
- Contract
Config - Pre-configured contract for startup registration.
- Ibkr
Client - Interactive Brokers execution client.
- Ibkr
Config - Configuration for the IBKR execution client.