程式

下班後數據 - 盈透證券

  • February 15, 2019

我剛開始使用 Interactive Brokers 是因為他們的 API。我正在使用 R 中的 IBrokers 包。我已經設法獲取標準普爾 500 指數和其他指數的數據,但現在我想要下班後標準普爾 500 指數的數據。

Investing.com顯示盤後標準普爾 500 指數(標準普爾 500 指數期貨)的數據。如何使用 Interactive brokers API 獲取這些數據?

更新

我剛試過這個沒有成功。我只獲取正常交易時間的數據。

spx = reqHistoricalData(tws2, twsIndex(symbol = "SPX", exch = "CBOE"), barSize = "15 mins", duration = "1 M", useRTH = "0")

難道我做錯了什麼?

該函式reqHistoricalData有一個參數useRTH(“使用正常交易時間”)。設置useRTH = "0"為在這些時間之外獲取數據。

這僅適用於期貨,不適用於僅在正常交易時間內計算的指數。

library("IBrokers")
tws <- twsConnect()

contract <- twsContract(local = "ESH9",
                       sectype = "FUT",
                       exch = "GLOBEX",
                       currency = "USD",
                       include_expired = "1",
                       conId = "", symbol = "", primary = "", 
                       expiry = "", strike = "", right = "",
                       multiplier = "", combo_legs_desc = "",
                       comboleg = "", secIdType = "", secId = "")

reqHistoricalData(tws,
                 contract,
                 barSize = "15 mins",
                 duration = "1 M",
                 useRTH = "0")

引用自:https://quant.stackexchange.com/questions/44011