【问题标题】:Using IBrokers and R, what is the appropriate way to retrieve last traded price during live trading session?使用 IBrokers 和 R,在实时交易时段检索最后交易价格的适当方法是什么?
【发布时间】:2020-08-31 16:03:57
【问题描述】:

所以目前我是这样做的:

  contract <- lapply(sym, function(x) twsEquity(x, 'SMART','ISLAND'))
  lapply(contract, function(x) reqHistoricalData(tws, Contract=x, barSize = "1 day", duration = "1 D", verbose = FALSE))

sym 只是 30 个左右股票代码的向量。 这非常慢。

因此,这不是正确的方法。 在我的实时交易时段中,我必须监控 100 支股票。 最后交易价格的更新必须在几秒内检索,而不是几分钟。

【问题讨论】:

    标签: r ibrokers


    【解决方案1】:

    您可以使用函数reqMktData 并将快照设置为TRUE

    sym <- c("AAPL", "MSFT")
    contracts <- lapply(sym, function(x) twsEquity(x, 'SMART','ISLAND'))
    
    last_prices <-   lapply(contracts, function(x) reqMktData(tws, 
                                                              Contract = x,
                                                              snapshot = TRUE))
    

    忽略您收到的警告。

    请注意,lastTimeStamp 是您的本地时间,而不是交易所的时间戳。

    last_prices
    [[1]]
            lastTimeStamp symbol bidSize bidPrice askPrice askSize lastPrice  Volume   Open   High Low  Close
    1 2020-08-31 18:38:48   AAPL       4   129.46   129.48       3    129.48 1311118 127.67 130.05 126 124.81
    
    [[2]]
            lastTimeStamp symbol bidSize bidPrice askPrice askSize lastPrice Volume  Open  High    Low  Close
    1 2020-08-31 18:38:47   MSFT       1   225.68    225.7       3    225.69 146282 227.1 228.7 224.31 228.91
    

    【讨论】:

    • 对于包含 32 个股票代码的向量,reqMktData 耗时 7 秒。这看起来仍然不对。应该不会超过 1 秒?
    猜你喜欢
    • 1970-01-01
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多