小编nik*_*kke的帖子

IBrokers reqMktData,如何为回调函数添加超时?

我一直在使用来自伟大的IBrokers软件包的改进的snapShot功能来获得IB的"最后"价格,并且它一直非常适合流动性股票.我做的电话是例如.

reqMktData(tws, twsSTK("AAPL"), eventWrapper=eWrapper.data.Last(1),CALLBACK=snapShot)
Run Code Online (Sandbox Code Playgroud)

在尝试检索非常缺乏流动性的股票或期权时会出现问题.因此,我需要为snapShot函数添加超时.如何以及在何处添加超时?

具有snapShot功能的代码:

library(IBrokers)
tws <- twsConnect()

eWrapper.data.Last <- function(n) {
  eW <- eWrapper(NULL)  # use basic template
  eW$assign.Data("data", rep(list(structure(.xts(matrix(rep(NA_real_,2),nc=2),0),
                                      .Dimnames=list(NULL,c("LastSize","Last")))),n))

  eW$tickPrice <- function(curMsg, msg, timestamp, file, ...) 
  {
    tickType = msg[3]
    msg <- as.numeric(msg)
    id <- msg[2] #as.numeric(msg[2])
    data <- eW$get.Data("data") #[[1]]  # list position of symbol (by id == msg[2])
    attr(data[[id]],"index") <- as.numeric(Sys.time())
    nr.data <- NROW(data[[id]])
    if(tickType == .twsTickType$LAST) {
      data[[id]][nr.data,2] <- msg[4]
    }
    eW$assign.Data("data", data)
    c(curMsg, msg)
  }
  eW$tickSize  <- function(curMsg, msg, timestamp, file, …
Run Code Online (Sandbox Code Playgroud)

r ibrokers

5
推荐指数
1
解决办法
1949
查看次数

标签 统计

ibrokers ×1

r ×1