2
$\begingroup$

I just started using Interactive Brokers because of their API. I'm using the IBrokers package in R. I've managed to get data for S&P 500 and other indices but now I want data for S&P 500 after hours.
Investing.com shows data for S&P 500 after hours (S&P 500 futures). How can I get this data by using Interactive brokers API?

Update

I just tried this without success. I only get data for regular trading hours.

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

Am I doing something wrong?

$\endgroup$
1
  • $\begingroup$ I would also suggest you to ask this in the [TWS API] discussion group: groups.io/g/twsapi There is a vibrant community there of coders working with several aspects of the Interactive Brokers API. $\endgroup$ Commented Feb 15, 2019 at 14:30

1 Answer 1

4
$\begingroup$

The function reqHistoricalData has an argument useRTH ("use regular trading hours"). Set useRTH = "0" to get data outside those hours.

This can only work for the futures, not for the index, which is only computed during normal trading hours.

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")
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.