![](/img/trans.png)
[英]Using IBrokers and R, what is the appropriate way to retrieve live trading data for multiple stocks?
[英]Using IBrokers and R, what is the appropriate way to retrieve last traded price during live trading session?
所以目前我這樣做:
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 只股票。 必須在幾秒鍾內而不是幾分鍾內檢索到他們最后交易價格的更新。
您可以使用函數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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.