req_sec_def_opt_params: Request Option Parameters (strike, expiry, etc) by Security

View source: R/req_sec_def_opt_params.R

req_sec_def_opt_paramsR Documentation

Request Option Parameters (strike, expiry, etc) by Security

Description

Use this function to request the strike prices and expiry dates for options that are available for a specified underlying contract. While the same information could be obtained via req_contract_details(), req_sec_def_opt_param() is not subject to data pacing (throttling) and is optimized for retreiving strike prices & expiry dates.

Usage

req_sec_def_opt_params(
  underlyingSymbol = "",
  futFopExchange = "",
  underlyingSecType = "",
  underlyingConId = "",
  channel = NULL
)

Arguments

underlyingSymbol

Character, length 1. Symbol of the underlying contract, e.g., "AAPL".

futFopExchange

Character, length 1. Exchange where fetched options trade, e.g., "NASDAQOM"

underlyingSecType

Character, length 1. The type of the underlying security. See SecType in the contract documentation.

underlyingConId

Character or numeric, length 1. The conId of the underlying contract.

channel

One of the following:

  • Not Specified (Default): Opens a new connection to IB, uses it to issue the request and retrieve the response, and closes connection behind itself upon completion.

  • The Name of a Sock: Character vector, length 1. The name of an open, connected socket in the sock_drawer; e.g., "master", "tws", or "sock_123"

  • Numeric Client ID: Numeric, length 1. The client ID for which open orders are to be retrieved; e.g., 0, 874, 123. If a client ID is passed, and no socket in the sock_drawer is connected on that ID, then a new socket will be opened on that ID, and closed upon function exit.

  • A sockconn Connection: An open connection object of class "sockconn", connected to the IB API; e.g., sock_drawer$tws

Value

A 1-row tibble with the following columns:

  • exchange <chr>: See contract

  • underlyingConId <numeric>: Unique numeric conId of underlying contract; See contract

  • tradingClass <chr>: See contract

  • multiplier <numeric>: See contract

  • expirations <list of POSIXt Date Objects>: Expiry dates of put & call options traded on exchange for the contract whose conId is passed as argument underlyingConId

  • expirations <list of Numeric Objects>: Strike prices of put & call options traded on exchange for the contract whose conId is passed as argument underlyingConId

See Also

Other asset info: req_contract_details(), req_matching_symbols()

Examples

# Query Option Parameters for IBM Stock
ibm_opt_params <- req_sec_def_opt_params(
  underlyingSymbol  = "IBM",
  underlyingSecType = "STK",
  underlyingConId   = 8314
)

# Print the params:
ibm_opt_params

# Print just the strike prices:
ibm_opt_params$strikes

# median strike price:
median(ibm_opt_params$strikes[[1]])

# Print just the expirations:
ibm_opt_params$expirations

# Find latest expiration:
max(ibm_opt_params$expirations[[1]])

JakeVestal/InteractiveTradeR documentation built on June 5, 2024, 2:21 p.m.