Requesting Historical Bars

View as MarkdownOpen in Claude

EClient.reqHistoricalData(

reqId: int, A unique identifier which will serve to identify the incoming data.

contract: Contract, The IBApi.Contract object you are working with.

endDateTime: String, The request’s end date and time. This should be formatted as “YYYYMMDD HH:mm:ss TMZ” or an empty string indicates current present moment).
Please be aware that endDateTime must be left as an empty string when requesting continuous futures contracts.

[durationStr:](/tws-api/doc/market-data-historical/historical-bars/duration) String, The amount of time (or Valid Duration String units) to go back from the request’s given end date and time.

[barSizeSetting:](/tws-api/doc/market-data-historical/historical-bars/historical-bar-sizes) String, The data’s granularity or Valid Bar Sizes

[whatToShow:](/tws-api/doc/market-data-historical/historical-bar-what-to-show/introduction) String, The type of data to retrieve. See Historical Data Types

useRTH: bool, Whether (1) or not (0) to retrieve data generated only within Regular Trading Hours (RTH)

[formatDate:](/tws-api/doc/market-data-historical/historical-bars/format-date-received) bool, The format in which the incoming bars’ date should be presented. Note that for day bars, only yyyyMMdd format is available.

[keepUpToDate:](/tws-api/doc/market-data-historical/historical-bars/keep-up-to-date) bool, Whether a subscription is made to return updates of unfinished real time bars as they are available (True), or all data is returned on a one-time basis (False). If True, and endDateTime cannot be specified.
Supported whatToShow values: Trades, Midpoint, Bid, Ask.

chartOptions: TagValueList, This is a field used exclusively for internal use.

)

self.reqHistoricalData(4102, contract, queryTime, "1 M", "1 day", "MIDPOINT", 1, 1, False, [])