I am having some difficulty get the following reqHistoricalData request in IBrokers to work. I am try to feed a data frame of date time and stock tickers pair to retrieve the intraday tickers at 5 minute intervals for historical research. I am looking to retrieve specific pair of stock ticker and a date. I can get this to work on a manual input but I have a data frame of 950 of these to do and want to make this work in a loop. This done in r using the IBrokers package
Manual example that works
conn <- twsConnect()
stock_dat = reqHistoricalData(conn, twsSTK("XEC"), endDateTime = "20191223 16:00:00", duration = "1 D", barSize = '5 mins')
the "XEC" and "20191223 16:00:00" are as.character and returns an object xts object for that day.
My sample data for this example would be a data frame called PoDHist and has 2 columns with 4 observations
Stock END_Date_Time
SYY 20191206 16:00:00
JNJ 20191209 16:00:00
OMC 20191210 16:00:00
MOS 20191213 16:00:00
both columns are as.characters
I am trying to use a pmap function from purrr
bar_downloader <- function(Stock,endDateTime)
{
n=PoDHist2 %>%
five_min_bar_data = reqHistoricalData(conn, twsEquity=PoDHist2$Stock, endDateTime = PoDHist2$END_Date_Time, duration = "1 D", barSize = '5 mins') %>%
print(Stock)
}
pmap(list(PoDHist2$Stock),list(PoDHist2$END_Date_Time),bar_downloader)
I am getting an error
Error in 1:nrow(PoDHist2$Stock) : argument of length 0
I am also seeing some inconsistence in the input format for endDateTime. The IBrokers r package specifies as format as ’CCYYMMDD HH:MM:SS TZ’. However I was manually able to get this to work in YYMMDD HH:MM:SS format as a character and not a time object.
Any suggestions would be helpful