Беда с вытягиванием опции Data IBrokers - PullRequest
0 голосов
/ 04 января 2019

За последние 2 месяца я получал данные опционов от Интерактивных брокеров. Начиная с нового года, когда я собираюсь получить данные опций, я получаю это сообщение «Ошибка в tmp [[id]]: индекс за пределами»

Вот код.

 tws = twsConnect(port = 7498)
 isConnected(tws)

 snapShot <- function (twsCon, eWrapper, timestamp, file, playback = 1, ...)
 {
if (missing(eWrapper))
eWrapper <- eWrapper()
names(eWrapper$.Data$data) <- eWrapper$.Data$symbols
con <- twsCon[[1]]
if (inherits(twsCon, "twsPlayback")) {
sys.time <- NULL
while (TRUE) {
  if (!is.null(timestamp)) {
    last.time <- sys.time
    sys.time <- as.POSIXct(strptime(paste(readBin(con,
                                                  character(), 2), 
                                          collapse = " "), timestamp))
    if (!is.null(last.time)) {
      Sys.sleep((sys.time - last.time) * playback)
    }
    curMsg <- .Internal(readBin(con, "character",
                                1L, NA_integer_, TRUE, FALSE))
    if (length(curMsg) < 1)
      next
    processMsg(curMsg, con, eWrapper, format(sys.time,
                                             timestamp), file, ...)
  }
  else {
    curMsg <- readBin(con, character(), 1)
    if (length(curMsg) < 1)
      next
    processMsg(curMsg, con, eWrapper, timestamp,
               file, ...)
    if (curMsg == .twsIncomingMSG$REAL_TIME_BARS)
      Sys.sleep(5 * playback)
  }
}
}
else {
while (TRUE) {
  socketSelect(list(con), FALSE, NULL)
  curMsg <- .Internal(readBin(con, "character", 1L,
                              NA_integer_, TRUE, FALSE))
  if (!is.null(timestamp)) {
    processMsg(curMsg, con, eWrapper, format(Sys.time(),
                                             timestamp), file, ...)
  }
  else {
    processMsg(curMsg, con, eWrapper, timestamp,
               file, ...)
  }
  if (!any(sapply(eWrapper$.Data$data, is.na)))
    return(do.call(rbind, lapply(eWrapper$.Data$data,
                                 as.data.frame)))
}
}
}

opt_put = twsOption("", expiry ="20190125",  symbol = "AAPL", right = 'P', 
strike = "148")

reqMktData(tws, Contract = opt_put, eventWrapper = eWrapper.data(1), 
CALLBACK = snapShot)
# Error in `*tmp*`[[id]] : subscript out of bounds 

Команда API у интерактивных брокеров не могла помочь и не имела опыта работы с R. Заранее спасибо, ребята. Я также хотел бы отметить, что у меня нет проблем с получением данных по капиталу

...