Skip to main content

Module ibkr

Module ibkr 

Source
Expand description

Ibkr market data stream (behind ibkr feature). Interactive Brokers market data connector.

Provides streaming market data from IB TWS/Gateway via the ibapi crate.

§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 (free subscriptions via IBKR Pro):

  • Tier 0: Connection, contract resolution
  • Tier 1: Historical bars/ticks, L1 quotes, Greeks calculator, option chains

NOT tested locally (paid subscriptions):

  • Tier 2: L2 Market Depth — exchange-specific fees
  • Tier 3: OPRA US Options — paid subscription

Tests are organized by subscription tier (see ibkr_integration.rs).

§Connection

Requires TWS or IB Gateway running locally with API enabled:

ApplicationLive PortPaper Port
TWS74967497
IB Gateway40014002

Enable API in TWS/Gateway: Configure → API → Settings → Enable ActiveX and Socket Clients.

§Architecture

Unlike WebSocket-based exchanges, IB uses TCP sockets with a blocking API. This module implements Stream directly rather than using the Connector trait designed for WebSocket exchanges.

§Supported Data Types

  • Quotes (OrderBookL1): Best bid/ask via market_data() subscription
  • Depth (OrderBookEvent): L2 order book via market_depth() subscription
  • Trades (PublicTrade): Tick-by-tick trades via tick_by_tick_all_last() subscription
  • Historical (Candle): OHLCV bars via historical::IbkrHistoricalData

§Limitations

  • Market depth limit: IB allows max 3 concurrent depth subscriptions (error 309)
  • Trade side: IB doesn’t provide trade side; defaults to Side::Buy
  • Blocking API: Uses std::thread::spawn for long-lived subscriptions
  • No auto-reconnect: Caller responsibility per library philosophy

§See Also

Modules§

depth
Depth aggregation for IB market depth updates.
greeks
Greeks aggregation for IB option tick data.
historical
Historical data fetcher for Interactive Brokers.
options
Option Greeks and chain data types for Interactive Brokers.
quotes
Quote aggregation for IB market data ticks.
subscription
IBKR subscription types.
trades
Trade tick transformation for IB tick-by-tick data.

Structs§

FlexPollPolicy
Poll timing for the GetStatement stage of IbkrFlexClient::fetch_statement_xml.
IbkrFlexClient
Client for fetching corporate-action records from the IBKR Flex Web Service.
IbkrFlexConfig
Credentials for the IBKR Flex Web Service: an Activity-statement Flex token and the id of a saved Flex query that includes the Corporate Actions section.
IbkrFlexCorporateAction
A single corporate-action row from an IBKR Flex statement, surfaced verbatim.
IbkrMarketStream
Market data stream from Interactive Brokers.
IbkrStreamConfig
Configuration for the IBKR market data stream.

Enums§

IbkrFlexError
Errors from IBKR Flex Web Service operations.
IbkrReorgType
IBKR Flex reorganisation type (the <CorporateAction> type attribute).

Functions§

parse_corporate_actions
Parse the <CorporateAction> rows out of an IBKR Flex statement XML document.