Interactive Brokers¶
- class ContainerStatus¶
Bases:
objectContainer status enumeration.
- CONTAINER_CREATED = ContainerStatus.CONTAINER_CREATED¶
- CONTAINER_STARTING = ContainerStatus.CONTAINER_STARTING¶
- CONTAINER_STOPPED = ContainerStatus.CONTAINER_STOPPED¶
- NOT_LOGGED_IN = ContainerStatus.NOT_LOGGED_IN¶
- NO_CONTAINER = ContainerStatus.NO_CONTAINER¶
- READY = ContainerStatus.READY¶
- UNKNOWN = ContainerStatus.UNKNOWN¶
- class DockerizedIBGateway¶
Bases:
objectDockerized IB Gateway manager.
This struct manages the lifecycle of Interactive Brokers Gateway Docker containers, including creation, starting, stopping, and status checking.
- container_name¶
Get the container name.
- container_status()¶
Get container status.
- host¶
Get the host address.
- port¶
Get the port.
- safe_start(wait)¶
Safely start the gateway.
# Arguments
wait - Optional wait time in seconds
- safe_start_blocking(wait)¶
- start(wait)¶
Start the gateway.
# Arguments
wait - Optional wait time in seconds
- start_blocking(wait)¶
- stop()¶
Stop the gateway.
- stop_blocking()¶
- class DockerizedIBGatewayConfig¶
Bases:
objectConfiguration for Dockerized IB Gateway.
This configuration is for managing containerized IB Gateway instances. It supports environment variable loading and sensitive data masking.
- container_image¶
Returns the container image.
- has_password¶
- read_only_api¶
Returns whether read-only API is enabled.
- timeout¶
Returns the timeout in seconds.
- trading_mode¶
Returns the trading mode.
- username¶
Returns the username.
- vnc_port¶
Returns the VNC port.
- class HistoricalInteractiveBrokersClient¶
Bases:
objectHistorical data client for Interactive Brokers.
This client provides methods for requesting historical bars and ticks for backtesting and research purposes.
- request_bars(bar_specifications, end_date_time, start_date_time=None, duration=None, contracts=None, instrument_ids=None, use_rth=True, timeout=60)¶
Request historical bars.
# Continuous futures
Continuous futures (CONTFUT) reject an explicit end date/time with IB error 10339. For these contracts the end date is dropped and only the first duration segment is requested, anchored to the current time, so the returned bars may fall outside [start_date_time, end_date_time]. A warning is logged when the requested end date/time is in the past or the range spans more than one duration segment.
# Arguments
bar_specifications - List of bar specifications (e.g., [“1-HOUR-LAST”])
end_date_time - End date for bars
start_date_time - Optional start date
duration - Optional duration string (e.g., “1 D”)
contracts - Optional list of IB contracts (dicts with symbol, sec_type, exchange, currency, etc.)
instrument_ids - Optional list of instrument IDs
use_rth - Use regular trading hours only
timeout - Request timeout in seconds
- request_instruments(instrument_ids=None, contracts=None)¶
Request instruments.
# Arguments
instrument_ids - Optional list of instrument IDs to load
contracts - Optional list of IB contracts (dicts with symbol, sec_type, exchange, currency, etc.)
- request_ticks(tick_type, start_date_time, end_date_time, contracts=None, instrument_ids=None, use_rth=True, timeout=60, limit=0)¶
Request historical ticks (quotes or trades).
# Arguments
tick_type - Historical tick type.
start_date_time - Start date for ticks
end_date_time - End date for ticks
contracts - Optional list of IB contracts (dicts with symbol, sec_type, exchange, currency, etc.)
instrument_ids - Optional list of instrument IDs
use_rth - Use regular trading hours only
timeout - Request timeout in seconds
limit - Maximum number of ticks to return, or 0 for no explicit limit
- class InteractiveBrokersDataClientConfig¶
Bases:
objectConfiguration for Interactive Brokers data client.
- batch_quotes¶
Returns whether to use batch quotes.
- client_id¶
Returns the client ID.
- connection_timeout¶
Returns the connection timeout in seconds.
- handle_revised_bars¶
Returns whether to handle revised bars.
- host¶
Returns the host.
- ignore_quote_tick_size_updates¶
Returns whether to ignore quote tick size updates.
- instrument_provider¶
Returns the instrument provider configuration.
- market_data_type¶
Returns the market data type.
- port¶
Returns the port.
- request_timeout¶
Returns the request timeout in seconds.
- use_regular_trading_hours¶
Returns whether to use regular trading hours only.
- class InteractiveBrokersDataClientFactory¶
Bases:
objectFactory for creating Interactive Brokers data clients.
- name()¶
- class InteractiveBrokersExecClientConfig¶
Bases:
objectConfiguration for Interactive Brokers execution client.
- account_id¶
Returns the account ID.
- client_id¶
Returns the client ID.
- connection_timeout¶
Returns the connection timeout in seconds.
- fetch_all_open_orders¶
Returns whether to fetch all open orders.
- host¶
Returns the host.
- instrument_provider¶
Returns the instrument provider configuration.
- port¶
Returns the port.
- request_timeout¶
Returns the request timeout in seconds.
- track_option_exercise_from_position_update¶
Returns whether to track option exercise from position updates.
- class InteractiveBrokersExecutionClientFactory¶
Bases:
objectFactory for creating Interactive Brokers execution clients.
- name()¶
- class InteractiveBrokersInstrumentProvider¶
Bases:
objectInteractive Brokers instrument provider.
This provider fetches contract details from Interactive Brokers using the rust-ibapi library and converts them to NautilusTrader instruments.
- count()¶
Get the number of cached instruments.
- determine_venue(contract)¶
Determine venue from contract using provider configuration.
- fetch_contract_details()¶
Maintain compatibility with the legacy Python provider API.
Contract details are fetched as part of the data/execution client load flow, so the standalone provider has nothing to do here.
- find(instrument_id)¶
Find an instrument by its ID.
- find_by_contract_id(contract_id)¶
Find an instrument by IB contract ID.
- get_all()¶
Get all cached instruments.
- get_price_magnifier(instrument_id)¶
Get price magnifier for an instrument ID.
- instrument_id_to_ib_contract_details(instrument_id)¶
Convert an instrument ID to cached IB contract details.
- load_cache(cache_path)¶
Load instrument cache from disk if valid.
# Arguments
cache_path - Path to the cache file
# Returns
Returns true if cache was loaded successfully and is valid, false otherwise.
# Errors
Returns an error if deserialization or file I/O fails (but treats missing file as non-error).
- save_cache(cache_path)¶
Save the current instrument cache to disk.
# Arguments
cache_path - Path to the cache file
# Errors
Returns an error if serialization or file I/O fails.
- class InteractiveBrokersInstrumentProviderConfig¶
Bases:
objectConfiguration for Interactive Brokers instrument provider.
- build_futures_chain¶
Returns whether to build full futures chain.
- build_options_chain¶
Returns whether to build full options chain.
- cache_path¶
Returns the cache path for persistent instrument caching.
- cache_validity_days¶
Returns the cache validity in days.
- convert_exchange_to_mic_venue¶
Returns whether to convert IB exchanges to MIC venues.
- filter_callable¶
Returns the custom instrument filter callable path.
- filter_sec_types¶
Returns the filter security types.
- load_contracts¶
Returns the IB contracts to load on startup.
- load_ids¶
Returns the instrument IDs to load on startup.
- max_expiry_days¶
Returns the maximum expiry days.
- min_expiry_days¶
Returns the minimum expiry days.
- symbol_to_mic_venue¶
Returns the symbol to MIC venue mapping.
- symbology_method¶
Returns the symbology method.