IbkrApi.ClientPortal.MarketData (ibkr_api v1.0.0)
View SourceMarket Data functionality for the IBKR Client Portal API.
This module provides functions to retrieve live market data snapshots and other market data related information.
Summary
Functions
Retrieves historical market data for a contract.
Retrieves live market data snapshots for one or more contracts.
Functions
@spec get_historical_data(String.t(), String.t(), String.t(), keyword()) :: {:ok, [IbkrApi.ClientPortal.MarketData.HistoricalBar.t()]} | {:error, ErrorMessage.t()}
Retrieves historical market data for a contract.
Parameters
conid
: Contract identifierperiod
: Duration of data to fetch (e.g., "1w", "1mo", "1d", "2h")bar
: Bar size (e.g., "1hour", "5min", "1day")opts
: Optional parameters:outside_rth
- Include extended hours? (default: false):exchange
- Optional exchange (default: "SMART")
Examples
iex> get_historical_data("265598", "2w", "1hour")
{:ok, [%HistoricalBar{timestamp: ~U[2024-02-05 14:00:00Z], open: 189.9, ...}, ...]}
iex> get_historical_data("265598", "1d", "5min", outside_rth: true)
{:ok, [%HistoricalBar{...}, ...]}
@spec live_market_data_snapshots( String.t(), keyword() ) :: {:ok, [IbkrApi.ClientPortal.MarketData.MarketDataSnapshot.t()]} | {:error, ErrorMessage.t()}
Retrieves live market data snapshots for one or more contracts.
For derivative contracts, /iserver/secdef/search must be called first.
Parameters
conids
: Contract identifier(s) - can be a single string or comma-separated stringopts
: Optional parameters:fields
- List of specific field codes to request (defaults to all fields)
Examples
iex> live_market_data_snapshots("265598")
{:ok, [%MarketDataSnapshot{symbol: "AAPL", last_price: 150.25, ...}]}
iex> live_market_data_snapshots("265598,8314", fields: ["31", "55"])
{:ok, [%MarketDataSnapshot{last_price: 150.25, symbol: "AAPL"}, ...]}