Requesting After-Hours S&P 500 Futures Data from Interactive Brokers
Summary
The document explains how to request historical data outside regular trading hours through Interactive Brokers’ API using the R IBrokers package. The key setting is the historical-data request’s regular-hours flag: disabling it allows the request to include eligible trading outside those hours.
The crucial instrument distinction is that the S&P 500 index itself is computed only during regular market hours, so an after-hours request should use an S&P 500 futures contract instead. The example uses an E-mini S&P 500 futures contract on Globex and requests 15-minute bars over a one-month duration with regular-hours filtering disabled. The example is specific to the package and contract setup shown; it does not provide guidance on current contract identifiers or data availability for every account.
Key ideas
- The historical-data request includes a flag for restricting results to regular trading hours.
- Disabling that restriction can return data from outside regular hours for eligible instruments.
- The S&P 500 index is only computed during normal hours, so futures are needed for after-hours market data.
- The example requests historical bars for an E-mini S&P 500 futures contract on Globex.
Tags
Full text
# After hours data - Interactive Brokers
# After hours data - Interactive Brokers
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?
## Answer by Enrico Schumann (score 4, accepted)
https://quant.stackexchange.com/a/44016
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")
```Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.