IbkrApi.ClientPortal.Contract (ibkr_api v1.0.0)

View Source

Contract-related functionality for the IBKR Client Portal API.

This module provides functions to retrieve contract information, trading schedules, security definitions, and currency exchange rates.

Summary

Functions

contract_details(conid)

@spec contract_details(String.t()) :: IbkrApi.ErrorMessage.t_res()

get_available_currency_pairs(currency \\ "USD")

@spec get_available_currency_pairs(String.t()) :: IbkrApi.ErrorMessage.t_res()

get_contract_ids(exchange)

@spec get_contract_ids(String.t()) :: IbkrApi.ErrorMessage.t_res()

get_contract_info(conid, opts \\ [])

Get detailed contract information using the secdef/info endpoint.

Returns a list of contract information objects matching the criteria.

Parameters

  • conid - Contract identifier (required)
  • opts - Optional parameters:
    • :sec_type - Security type
    • :month - Expiration month for derivatives
    • :exchange - Specific exchange
    • :strike - Strike price for options
    • :right - "C" for Call, "P" for Put options
    • :issuer_id - Issuer ID for bonds
    • :filters - Comma-separated list of additional filters for bonds

Examples

iex> IbkrApi.ClientPortal.Contract.get_contract_info("8314")
{:ok, [%SecdefInfo{conid: 8314, symbol: "IBM", sec_type: "STK", ...}]}

iex> IbkrApi.ClientPortal.Contract.get_contract_info("265598", sec_type: "OPT", strike: 250)
{:ok, [%SecdefInfo{conid: 795753109, symbol: "NVDA", right: "C", ...}, ...]}

get_currency_exchange_rate(target, source)

@spec get_currency_exchange_rate(String.t(), String.t()) ::
  IbkrApi.ErrorMessage.t_res()

get_nyse_trading_schedule(symbol \\ "NVDA", asset_class \\ "STK")

get_stock_security_definition(symbol)

@spec get_stock_security_definition(String.t()) :: IbkrApi.ErrorMessage.t_res()

get_strikes(symbol, opts \\ [])

@spec get_strikes(String.t(), Keyword.t()) :: IbkrApi.ErrorMessage.t_res()

Convenience function to get strikes for a symbol by first searching for the contract.

This function searches for the symbol, finds the first matching contract with options, then retrieves the strikes for the current month.

Parameters

  • symbol: The ticker symbol to search for
  • opts: Optional parameters:
    • :month: Date struct for expiration month (defaults to current month)
    • :sec_type: Security type for search (defaults to "STK")

Examples

iex> get_strikes("AAPL")
{:ok, %StrikesResponse{call: [150, 155, 160], put: [150, 155, 160]}}

get_strikes(contract_id, sec_type, month, opts \\ [])

@spec get_strikes(String.t(), String.t(), Date.t(), Keyword.t()) ::
  IbkrApi.ErrorMessage.t_res()

Get option strikes for a given contract.

Parameters

  • contract_id: Contract identifier of the underlying or derivative
  • sec_type: Security type (e.g., "OPT" for options)
  • month: Elixir Date struct representing the expiration month
  • opts: Optional parameters including exchange (defaults to "SMART")

Examples

iex> date = ~D[2024-01-15]
iex> get_strikes("265598", "OPT", date)
{:ok, %StrikesResponse{call: [70, 75, 80], put: [70, 75, 80]}}

get_trading_schedule(asset_class, symbol, opts \\ [])

@spec get_trading_schedule(String.t(), String.t(), Keyword.t()) ::
  IbkrApi.ErrorMessage.t_res()

search_contracts(symbol, opts \\ [])

@spec search_contracts(String.t(), Keyword.t()) :: IbkrApi.ErrorMessage.t_res()

Search for contracts based on symbol and other criteria.

Parameters

  • symbol: The ticker symbol, bond issuer type, or company name
  • opts: Optional parameters:
    • :sec_type: Security type ("STK", "IND", "BOND") - defaults to "STK"
    • :name: Boolean indicating if symbol is part of company name
    • :more: Boolean for additional results
    • :fund: Boolean for fund search
    • :fund_family_conid_ex: String for fund family
    • :pattern: Boolean for pattern search
    • :referrer: String referrer

Examples

iex> search_contracts("AAPL")
{:ok, [%SearchContract{symbol: "AAPL", conid: "265598", ...}]}

secdef_by_conid(conids)

@spec secdef_by_conid([integer()]) :: IbkrApi.ErrorMessage.t_res()

security_futures_by_symbol(symbols)

@spec security_futures_by_symbol(String.t()) :: IbkrApi.ErrorMessage.t_res()

security_stocks_by_symbol(symbols)

@spec security_stocks_by_symbol(String.t()) :: IbkrApi.ErrorMessage.t_res()