1

在过去的 2 个月里,我一直在从 Interactive 经纪商那里获取期权数据。自从我去拉选项数据的新年以来,我收到此消息“ 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 的经验。在此先感谢各位。我还要提一下,我拉股权数据没有问题

4

0 回答 0