|
|
This documentation is now deprecated. Please switch to the IBKR Campus for up-to-date information regarding IBKR's API solutions. |
Historical data is obtained from the the TWS via the IBApi.EClient.reqHistoricalData function. Every request needs:
For example, making a request with an end date and time of "20160127-23:59:59", a duration string of "3 D" and a bar size of "1 hour" will return three days worth of 1 hour bars data in which the most recent bar will be the closest possible to 20160127-23:59:59.
The daily bar size has several unique characteristics. This is true both in TWS and the API:
The historical data will be delivered via the IBApi::EWrapper::historicalData method in the form of candlesticks. The time zone of returned bars is the time zone chosen in TWS on the login screen. If reqHistoricalData was invoked with keepUpToDate = false, once all candlesticks have been received the IBApi.EWrapper.historicalDataEnd marker will be sent. Otherwise updates of the most recent partial five-second bar will continue to be returned in real time to IBApi::EWrapper::historicalDataUpdate. The keepUpToDate functionality can only be used with bar sizes 5 seconds or greater and requires the endDate is set as the empty string. Also, with keepUpToDate = true, if bust event happens, then bust event error (code=10225) is reported to all API client versions connected to TWS version 981+.
A new whatToShow = SCHEDULE parameter has been introduced in the TWS API 10.12.
The data is requested via IBApi.EClient.reqHistoricalData method with whatToShow "SCHEDULE" and delivered via IBApi.EWrapper.historicalSchedule method.
Unit | Description |
---|---|
S | Seconds |
D | Day |
W | Week |
M | Month |
Y | Year |
Size | |||||||
---|---|---|---|---|---|---|---|
1 secs | 5 secs | 10 secs | 15 secs | 30 secs | |||
1 min | 2 mins | 3 mins | 5 mins | 10 mins | 15 mins | 20 mins | 30 mins |
1 hour | 2 hours | 3 hours | 4 hours | 8 hours | |||
1 day | |||||||
1 week | |||||||
1 month |
(whatToShow)
All different kinds of historical data are returned in the form of candlesticks and as such the values return represent the state of the market during the period covered by the candlestick.
Type | Open | High | Low | Close | Volume |
---|---|---|---|---|---|
TRADES | First traded price | Highest traded price | Lowest traded price | Last traded price | Total traded volume |
MIDPOINT | Starting midpoint price | Highest midpoint price | Lowest midpoint price | Last midpoint price | N/A |
BID | Starting bid price | Highest bid price | Lowest bid price | Last bid price | N/A |
ASK | Starting ask price | Highest ask price | Lowest ask price | Last ask price | N/A |
BID_ASK | Time average bid | Max Ask | Min Bid | Time average ask | N/A |
ADJUSTED_LAST | Dividend-adjusted first traded price | Dividend-adjusted high trade | Dividend-adjusted low trade | Dividend-adjusted last trade | Total traded volume |
HISTORICAL_VOLATILITY | Starting volatility | Highest volatility | Lowest volatility | Last volatility | N/A |
OPTION_IMPLIED_VOLATILITY | Starting implied volatility | Highest implied volatility | Lowest implied volatility | Last implied volatility | N/A |
FEE_RATE | Starting fee rate | Highest fee rate | Lowest fee rate | Last fee rate | N/A |
YIELD_BID | Starting bid yield | Highest bid yield | Lowest bid yield | Last bid yield | N/A |
YIELD_ASK | Starting ask yield | Highest ask yield | Lowest ask yield | Last ask yield | N/A |
YIELD_BID_ASK | Time average bid yield | Highest ask yield | Lowest bid yield | Time average ask yield | N/A |
YIELD_LAST | Starting last yield | Highest last yield | Lowest last yield | Last last yield | N/A |
SCHEDULE | N/A | N/A | N/A | N/A | N/A |
AGGTRADES | First traded price | Highest traded price | Lowest traded price | Last traded price | Total traded volume |