View source: R/req_contract_details.R
req_contract_details | R Documentation |
Fetch a wealth of information about contracts at Interactive Brokers that are
found to match parameters supplied in the contract
argument.
req_contract_details(contract = NULL, channel = NULL)
contract |
Named character vector of contract parameter(s). The name of each element identifies the parameter – for example, |
channel |
One of the following:
|
IB's documentation describes each column variable that can appear in
the output of InteractiveTradeR's implementation of
req_contract_details
() in the
ContractDetails
Members section. A list of the contract parameters that may be passed in via
the contract
object can be found in IB's
Contract
Class Reference.
Pacing and Large Queries: req_contract_details
() is able to
send queries that involve the transfer of high amounts of data in cases where
many contracts are found to match the selection criteria. As a consequence,
Interactive Brokers may pace requests made by this function by
placing similar or identical requests on hold for one minute, with the amount
of time increasing each time subsequent similar/identical requests are made.
The exact criteria regarding what constitutes a "similar" request, and the
rules governing pacing behavior, are not published. However, by following
three general rules of thumb, pacing should not be a problem when using
req_contract_details
() in InteractiveTradeR:
In SYNC mode ( channel = NULL
) , bump up the
timeout parameter for large queries with sync_timeout(). If a large
number of contracts are found to match the parameters in contract
,
then the function might return an error if called with the default timeout
because it needs bit more time than the default 5 seconds in order to
complete. Try using sync_timeout(10)
or sync_timeout(15)
.
Using conId
Only: If the object passed in as
contract
has length = 1, then req_contract_details
() will
assume that contract
contains a conId
, which is sufficient to
specify a unique contract. This shortcut can help speed up usage.
Other asset info:
req_matching_symbols()
,
req_sec_def_opt_params()
#### Example: supplying more parameters gives more specific results.
#### Goal: We would like to retrieve the contract details of IBM common stock,
#### which, at IB, happens to have conId = 8314.
# The fastest and simplest way to get IBM's contract details is by conId only:
contract_details <- req_contract_details(8314)
contract_details
# You can select, manipulate, and view the fetched details:
contract_details$exchange_info # View the exchange info
contract_details$orderTypes # See what order types are available
contract_details$conId # Check the conId
# ... and so on.
# You can also use glimpse() to print the information in what may be an
# easier-to-read format:
dplyr::glimpse(contract_details)
# But what if you didn't already know IBM's conId?
# 2) You could try to get IBM's contract details by symbol only, but because
# there are many securities across many exchanges that have the symbol "IBM"
# this query won't work -- IB responds by asking for more info.
contract_details_1 <- req_contract_details(contract = c(symbol = "IBM"))
# 3) So, try providing a valid security type:
contract_details_2 <- req_contract_details(
contract = c(symbol = "IBM", secType = "STK")
)
contract_details_2
# This call will work, but returns ALL of the contracts whose symbol is "IBM".
# Only one of these is the contract of interest, so this doesn't help much.
# 4) Narrow things down by specifying a currency:
contract_details_3 <- req_contract_details(
contract = c(
symbol = "IBM",
secType = "STK",
currency = "USD"
)
)
contract_details_3
# This helped somewhat, but still have a large number of matching contracts.
# 5) Specify an exchange:
contract_details_4 <- req_contract_details(
contract = c(
symbol = "IBM",
secType = "STK",
currency = "USD",
exchange = "SMART"
)
)
contract_details_4
# Success! For IBM, these four exchanges are enough to specify the contract.
# Bond details return slightly different parameters. See the "ContractDetails"
# documentation on IB's website at the link provided in the "Value" section.
broadcom_bond <- req_contract_details(359401413)
broadcom_bond
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.