req_matching_symbols: Request Matching Symbols

View source: R/req_matching_symbols.R

req_matching_symbolsR Documentation

Request Matching Symbols

Description

Search Interactive Brokers' database for stocks (and stocks only) by specifying a search string pattern. pattern may be a ticker, e.g. "AAPL", or part of a stock's name, e.g. "App".

Usage

req_matching_symbols(pattern, channel = NULL)

Arguments

pattern

Character vector of length 1. The search string for which matching stocks are sought. May be a ticker, e.g. "IBM", or part of a stock's name, e.g. "International". Not case sensitive.

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

Details

Space out calls to req_matching_symbols() by at least 1 second. IB will only allow at most 1 call to req_matching_symbols per second per user, meaning that even if you run seperate searches for matching symbols on different sockets at the same time, you'll get an error telling you that IB is busy processing the request for a different client.

Value

A tibble object in which each row corresponds to an asset whose name or ticker matched the pattern supplied. The tibble's columns are:

  • con_id <chr>: Interactive Brokers' unique numeric ID

  • symbol <chr>: Exchange symbol (i.e., ticker symbol)

  • sec_type <chr>: Asset class ("STK" for stock)

  • primary_exchange <chr>: Financial exchange on which most of the asset's trade volume takes place (NYSE, ARCA, etc).

  • currency <chr>: Currency in which trades are made.

  • asset_types <list>: A list of other financial products (options, bonds, warrants, etc) that derive from the asset and are available to trade through Interactive Brokers.

See Also

Other asset info: req_contract_details(), req_sec_def_opt_params()

Examples

# Fetch matching symbols for pattern "international"
matching_symbols <- req_matching_symbols("international")
# Print matching symbols
matching_symbols

# If that doesn't satisfy, try a few more search strings. Wait 3 seconds after
# each one so as to be kind to IB's servers.
req_matching_symbols("ibm")
Sys.sleep(3)
req_matching_symbols("business")
Sys.sleep(3)
req_matching_symbols("machines")
Sys.sleep(3)

# Say you only wanted to know what asset types -- futures, options, warrants,
# etc -- that were available for the stock traded on the NYSE under the symbol
# "IBM". You could pipe the output of req_matching_symbols() to a series of
# functions with the end result of returning only the info you want:
req_matching_symbols("ibm") %>%
  dplyr::filter(symbol == "IBM" & primary_exchange == "NYSE") %>%
  dplyr::select(asset_types) %>%
  unlist(use.names = FALSE)

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