reqHistoricalData {IBrokers} | R Documentation |
Makes a request to the Interactive Brokers Trader Workstation (TWS), and returns an xts object containing the results of the request if successful.
reqHistoricalData(conn, Contract, endDateTime, barSize = "1 day", duration = "1 M", useRTH = "1", whatToShow = "TRADES", time.format = "1")
conn |
a tws connection object |
Contract |
a twsContract |
endDateTime |
end date/time for request. See details. |
barSize |
bar size to retrieve |
duration |
time span the request will cover |
useRTH |
limited to regular trading hours |
whatToShow |
type of data to be extracted |
time.format |
POSIX style or seconds from 1970-01-01 |
All arguments should be character strings. Attempts will be made to coerce, but should not be relied upon.
The endDateTime
argument must be of the form
'CCYYMMDD HH:MM:SS TZ'. If not specified the current
time as returned from the TWS server will be used. This
is the preferred method.
Legal barSize
settings are technically
‘1 secs’,‘5 secs’,‘15 secs’,
‘30 mins’,‘1 min’,‘2 mins’,
‘3 mins’,‘5 mins’,‘15 mins’,
‘30 mins’,‘1 hour’,‘1 day’,
‘1 week’,‘1 month’,‘3 months’,
and ‘1 year’. They must be specified exactly
and there is no guarantee from the API that all
will work for all securities or durations.
The duration string must be of the form ‘n S’ where the last character may be any one of ‘S’ (seconds), ‘D’ (days), ‘W’ (weeks), ‘M’ (months), and ‘Y’ (year). At present the limit for years is 1.
useRTH
takes either ‘1’ or ‘0’,
indicating the request to return only regular trade
hour data, or all data, respectively.
whatToShow
can be any one of the following,
though depending on the overall request it may not succeed.
‘TRADES’, ‘MIDPOINT’, ‘BID’,
‘ASK’, ‘BID/ASK’.
time.format
should simply be left alone. :D
Returns an xts
object containing the requested data, along
with additional information stored in the objects xtsAttributes
.
There is a strictly enforced 6 seconds between request pacing rule implemented by the TWS. Keep this in mind.
The TWS workstation must be running on the same machine as R.
The TWS must also be set up to allow for the API to be connected to. See the associated help on the main Interactive Brokers website.
The underlying API is subject to changes on an ongoing basis by Interactive Brokers. All attempts have been made to keep this current. If something should fail, please contact the maintainer of this package.
Jeffrey A. Ryan
Interactive Brokers www.interactivebrokers.com
## Not run: tws <- twsConnect() contract <- twsEquity('QQQQ','SMART','ISLAND') reqHistoricalData(tws,Contract=contract) ## End(Not run)