Asset Classes

Free investment financial education

Language

Multilingual content from IBKR

Close Navigation
Learn more about IBKR accounts

Requesting Market Data

Lesson 6 of 11
Duration 17:22
Level Intermediate
Close Navigation

This lesson will explore how to request market and historical data using the TWS Python API. Code examples will be presented which show the minimum Python code necessary to request streaming and historical data and display market data in the console. Finally, we will discuss limitations on requesting data, and the types of data which are included in IBKR’s real time feed as compared to the historical database.

Study Notes:

Welcome to this lesson on requesting market data in the Trader Workstation API. In this video, we will be highlighting the requirements for requesting market data, how to request delayed data, how to request live market data, and how to request historical bars. Please note that these are the most popular methods of requesting market data; however, Interactive Brokers also offers tick data, histogram data, and market depth.

Discussing Market data subscriptions

Let’s begin by discussing market data subscriptions. In order for clients to subscribe to market data, users must have a funded IBKR account for at least $500 USD in most instances. There are some instances where this is not the case; however, for the average individual at Interactive Brokers, $500 is the minimum. This threshold must be maintained in addition to the cost of any subscriptions held by the account.

For those with a long-time IBKR PRO account, you may have observed that some instruments return market data to your Trader Workstation for free by default. That is because some market data can be provided to users for free while “on-platform”. On-platform simply means that users are observing data directly display through one of Interactive Brokers platforms. Exchanges consider API functionality to be considered off-platform, and as a result, typically have a cost affiliated with them. Some of the most popular market data subscriptions for API use are listed in the API Documentation for Market Data on IBKR Campus. Users can subscribe to market data through the Client Portal. 

It is also worth clarifying that Market Data is affiliated on a per-user basis. Many clients will run a single Trader Workstation instance for monitoring trades; however, it is common to have a separate machine running your trading algorithm on IB Gateway hosted on a virtual machine elsewhere. In order for both of these platforms to retrieve market data, each user consuming market data would need to subscribe to data separately.

Requesting streaming data

With the subscription discussion out of the way, we can start to dive into the actual API requests. Please note that we will be using the same framework from our Essential Components video, so if there are any questions on the initial structure in this video, please be sure to review that lesson first.

The most popular way of requesting and viewing data in the API would be with EClient.reqMktData method, which requests the same data available in the TWS Watchlists.

Requesting delayed data

Clients that do not have a market data subscription for instruments can often request 15 minute delayed data. This is only a single extra step compared to standard market data subscriptions, so I will include it before moving forward.

To clarify if your requests will be Live or delayed, users simply need to call the app.reqMarketDataType function. The only argument this takes is the type of data to retrieve, which can be 1,2,3,4 or Live, Frozen, Delayed, or Delayed Frozen respectively. Frozen data will refer to market data from the most recent close, while delayed frozen data will return yesterday’s closing values. And then as we’ve mentioned, standard delayed data will return 15-minute delayed data.

If I am subscribed to market data on a given instrument, but request delayed market data, live data will still be returned. Interactive Brokers will always try to provide the most up-to-date market data where possible.

Requesting live data

Now, let’s start building out our request for streaming data. We will be focused on requesting price and size data; however, the reqMktData request can also return string, news, generic and even Greek values depending on the tick types provided.

From within our TestApp class, let’s start defining one of our tick functions, tickPrice. This will handle all returning values related to price values. tickPrice takes self, reqId, tickType, price, and attrib as arguments. While we’re already familiar with the first two, and the last two are rather self-explanatory, the tickType argument is used to indicate what kind of data is coming in.

Each tickType is an integer value that correlates to a specific value, be it bid price, last size, closing price, or otherwise. For a full list of all of these tick values, we can look at ticktype.py inside the ibapi source files and see exactly what everything is relating to. Users are welcome to reference the returned integer values directly; however, the enumerator contains a toStr method that converts our tick type integers into the values we see before us. In our file, we can add an import for from ibapi.ticktype import TickTypeEnum. This will allow us to reference the TicKTypeEnum.toStr() method and print out our value directly in a moment.

I will print out all of these values in an ­f-string, including our reference of TickTypeEnum.toStr(). As we discussed before, this would be perfectly fine to print out our price values; however, I also want to see the quantities of our trades effected by this. To do this, we will also add the EWrapper.tickSize function to our TestApp class as well. This function only takes the arguments: self, reqId, tickType, and size.  The sizes returned here will relate to the prices returned in our tickPrice function and allow us to create a clearer picture of the trades taking place.

Now that we have everything in place to receive the data, let’s build out a contract object and a request for market data. Leaping off of our prior video, I’ll make a request for AAPL market data using the symbol, security type, currency, and exchange values.

With a contract now set, I can call app.reqMktData to start requesting my streaming data. For arguments, we’ll need to pass the reqId, which we’ll use our app.nextId() function for. I can pass mycontract for the contract object. For our next argument, the generic tick list, I will pass “232” as a string so I can retrieve the mark price from my request. For users looking to request multiple generic ticks, you would simply comma-separate the values within the string. So maybe you would pass “232, 233, 234” as an example.

The next argument defines if we are requesting a Snapshot value.

This is a single return instance aggregating the last 11 seconds of trading. If no trading has taken place, this will not return any values. And if we do see trades in the last 11 seconds, we will see those values returned in aggregate. Similarly, the next argument determines if we are requesting a regulatory snapshot. This is a snapshot used to determine the price of an instrument before executing a trade.

Regulatory snapshots will cost approximately $0.01 per request, until we reach the cost of the affiliated subscription. If I request market data for AAPL repeatedly, Interactive Brokers will eventually add the subscription to your account, as the cost of the regulatory snapshots equate to the value of the subscription anyway. The final argument takes market data options, which is an argument used only for internal purposes.

If we run this script, we’ll find an initial flood of data depicting the most recent values for several tick types, then over time we will receive all the live data prices and sizes as they come through.

Requesting Historical Data

Requesting Historical Data follows a similar pattern to the live market data requests. The one caveat to this is that market data cannot be retrieved if you do not have a valid market data subscription. Before we begin to dig into historical data, I’d like to first find how far back we can request market data. I’ll start finding this value using a new python file.

Requesting the headTimeStamp Value

In our new file, I will create a new function in the TestApp class to define the headTimeStamp function. This takes three arguments, self, a request ID, and the headTimeStamp string. Within my new function, I will print out my headTimeStamp value. I will also make a request for self.cancelHeadTimeStamp to terminate the request now that I’m done with it, and we can just pass the requestId we received as an argument. With the EWrapper piece out of the way, I will move out of the TestApp class to create my headTimeStamp request. I will copy over my same AAPL contract I used from the Live Data script, because I want to validate how far back I can find AAPL market data.

Next, I will make a call to the app.reqHeadTimeStamp function. This takes an argument for a request ID, which can use our nextId function; and a contract reference, which will take my mycontract object.  After these two, I’m now encountering something known as the “whatToShow” value. This same value is used to denote what data is displayed in your TWS bar charts. In my case, I will use the value for Trades, though the full list of whatToShow values are available in our documentation.

The next argument relates to using regular trading hours. A 1 will indicate that we want the earliest date within trading hours, while a 0 will request the earliest date outside of trading hours. Finally, we have the formatDate parameter. This will indicate whether we want 1, a UTC timestamp in a string format, or 2, an Epoch timestamp. The latter is an integer representation of the same timestamp. You can consider the former better for human consumption, while the latter is best utilized in a programmatic request structure. I will show these off in just a moment by making two requests.

If we run this script using ‘1’ as the date format, we’ll see 19801212-14:30:00. Meaning AAPL’s “Trades” market data can go as far back as December 12, 1980 at 9:30 AM Eastern. Before we move on, I’ll quickly add another print statement to my headTimeStamp method for the datetime.datetime.fromtimestamp function, taking in the integer version of our headTimeStamp. If I change my original request to use 2 as my date format, I’ll print out the original epoch value as well as the python translated datetime, which is automatically converted to my pc’s local time in US/Central time.

Requesting historical bars

Now that we know our historical data range, we can start making a request for historical data. You are welcome to use the same file, but for my demonstration, I’ll be starting from a fresh example of our standard layout but add in our AAPL contract again. As always, we’ll define the EWrapper function inside TestApp using def historicalData. This function takes an argument for self, reqId, and bar. We will finish the function by printing the reqId and bar values.

I will note that we are printing out the full bar object; however, the bar object can be split out, so you may print bar.open for the opening price, bar.close for the closing price, and so on. But just for our presentation here, I’ll print the whole thing.

Each bar size is returned separately, so for us to know we’re done we should reference the EWrapper function for historicalDataEnd. This function takes an argument for self and reqID and is just meant to indicate that all available data has been returned to the user.

With the wrapper functions set, we’ll start our EClient request. To make the request, we’ll call the app.reqHistoricalData function. This takes 10 total arguments, starting with reqid, contract.

The next argument is endDateTime, which takes the value we’d like to end our historical data at. If we leave this as an empty string, the system will assume the current time. Otherwise, we would make a format for year, month, day followed by the 24 hour timestamp, and a timezone. You must pass the timezone for the exchange, available through a Contract Details request, the exact timezone used for your TWS, which is set prior to the homescreen, or using UTC. I will send my request for “20240523 16:00:00 US/Eastern”.

Then, we’ll pass in a duration value, which corresponds to the full interval over which data will be returned. So, if I specify “1 D”, I will receive however many bars in a single day. On the topic of bars, the next argument will take the bar size. In my case, I can pass “1 hour” to receive an hour.

This means I will receive 7 bars for my day, a bit more on that later.

Moving forward in our arguments, we’ll find more familiar values, like the whatToShow value we used before, which I’ll use “TRADES” for once again, then useRth and formatDate, again using 1 in both cases. Now we have the option for “keepUpToDate”, which allows us to build bars as data is available and return these new bars to the historicalDataUpdate function. I’m not interested in this data at the moment, so I’ll go ahead and leave this as False for now. Finally, we end with market data options, which I’ll again leave as an empty list.

Now if we run this script, I will see my request ID, and all of my bar’s values. While most of this is self-explanatory, there are a few points I’d like to mention from the programmatic standpoint. You might notice that we sent the request using US/Eastern, but my data shows America/Chicago. That’s because I’m choosing to print out my “Operator Timezone” even though I made the request with the “Instrument Timezone”. You can modify the time zone returned in TWS by opening the Global Configuration page and opening the API Settings. You’ll notice a section for “Send instrument-specific attributes for dual-mode API Client in”. Specifying Operator Timezone returns your TWS time zone, Instrument time zone returns the time zone for the contract, and UTC is obviously the UTC time zone.

The other piece I’d like to mention is the 7 bars I had referenced earlier. The Date value in the bar references the starting time for the bar. In my case, we can see my bar started at 08:30:00 America/Chicago, which is when NASDAQ opens for trading AAPL. But then we’ll see 09:00 as our next bar, meaning our first bar is only 30 minutes long, before turning into a series of 1-hour bars. This is the same behavior as Trader Workstation, though it may not be as commonly understood when pulling data programmatically. Therefore, it’s best practice to use the next bar as an indicator of approximate bar size.

This concludes our lesson on market data in the TWS API. Thank you for watching. If you have any questions, please be sure to review our documentation or leave a comment below this video. We look forward to having you in the next lesson of our TWS API series.

Code Snippet – headTimeStamp

from ibapi.client import *
from ibapi.wrapper import *
import datetime
import time
import threading

port = 7497


class TestApp(EClient, EWrapper):
    def __init__(self):
        EClient.__init__(self, self)

    def nextValidId(self, orderId: OrderId):
        self.orderId = orderId
    
    def nextId(self):
        self.orderId += 1
        return self.orderId
    
    def error(self, reqId, errorCode, errorString, advancedOrderReject):
        print(f"reqId: {reqId}, errorCode: {errorCode}, errorString: {errorString}, orderReject: {advancedOrderReject}")
    
    def headTimestamp(self, reqId, headTimeStamp):
        print(headTimeStamp)
        print(datetime.datetime.fromtimestamp(int(headTimeStamp)))
        self.cancelHeadTimeStamp(reqId)


app = TestApp()
app.connect("127.0.0.1", port, 0)
threading.Thread(target=app.run).start()
time.sleep(1)

mycontract = Contract()
mycontract.symbol = "AAPL"
mycontract.secType = "STK"
mycontract.exchange = "SMART"
mycontract.currency = "USD"

app.reqHeadTimeStamp(app.nextId(), mycontract, "TRADES", 1, 2)

Code Snippet – historical_market_data.py

from ibapi.client import *
from ibapi.wrapper import *
import datetime
import time
import threading

port = 7497


class TestApp(EClient, EWrapper):
    def __init__(self):
        EClient.__init__(self, self)

    def nextValidId(self, orderId: OrderId):
        self.orderId = orderId
    
    def nextId(self):
        self.orderId += 1
        return self.orderId
    
    def error(self, reqId, errorCode, errorString, advancedOrderReject):
        print(f"reqId: {reqId}, errorCode: {errorCode}, errorString: {errorString}, orderReject: {advancedOrderReject}")
    
    def historicalData(self, reqId, bar):
        print(reqId, bar)
    
    def historicalDataEnd(self, reqId, start, end):
        print(f"Historical Data Ended for {reqId}. Started at {start}, ending at {end}")
        self.cancelHistoricalData(reqId)

app = TestApp()
app.connect("127.0.0.1", port, 0)
threading.Thread(target=app.run).start()
time.sleep(1)

mycontract = Contract()
mycontract.symbol = "AAPL"
mycontract.secType = "STK"
mycontract.exchange = "SMART"
mycontract.currency = "USD"

app.reqHistoricalData(app.nextId(), mycontract, "20240523 16:00:00 US/Eastern", "1 D", "1 hour", "TRADES", 1, 1, False, [])
from ibapi.client import *
from ibapi.wrapper import *
import datetime
import time
import threading
from ibapi.ticktype import TickTypeEnum

port = 7497


class TestApp(EClient, EWrapper):
    def __init__(self):
        EClient.__init__(self, self)

    def nextValidId(self, orderId: OrderId):
        self.orderId = orderId
    
    def nextId(self):
        self.orderId += 1
        return self.orderId
    
    def error(self, reqId, errorCode, errorString, advancedOrderReject):
        print(f"reqId: {reqId}, errorCode: {errorCode}, errorString: {errorString}, orderReject: {advancedOrderReject}")
      
    def tickPrice(self, reqId, tickType, price, attrib):
        print(f"reqId: {reqId}, tickType: {TickTypeEnum.toStr(tickType)}, price: {price}, attrib: {attrib}")
      
    def tickSize(self, reqId, tickType, size):
        print(f"reqId: {reqId}, tickType: {TickTypeEnum.toStr(tickType)}, size: {size}")


app = TestApp()
app.connect("127.0.0.1", port, 0)
threading.Thread(target=app.run).start()
time.sleep(1)

mycontract = Contract()
mycontract.symbol = "AAPL"
mycontract.secType = "STK"
mycontract.exchange = "SMART"
mycontract.currency = "USD"

app.reqMarketDataType(3)
app.reqMktData(app.nextId(), mycontract, "232", False, False, [])

Join The Conversation

If you have a general question, it may already be covered in our FAQs. If you have an account-specific question or concern, please reach out to Client Services.

28 thoughts on “Requesting Market Data”

  • Ali

    A big thanks!
    Love!

    Do you have any sample code for streaming the deep data(Level II)?

  • Ankit

    First code is working fine. Code Snippet – Request Market Data But while running
    Code Snippet – Request Historical Market Data

    I am getting below errror
    (ib_venv) akotak@Ankitkumars-MacBook-Pro IBJts % /Users/akotak/Downloads/AlgoTrading/IBJts/source/pythonclient/ib_venv/b
    in/python /Users/akotak/Downloads/AlgoTrading/IBJts/source/pythonclient/my_work/rqst_hist_data.py
    ERROR -1 2104 Market data farm connection is OK:usfarm.nj
    ERROR -1 2104 Market data farm connection is OK:usfuture
    ERROR -1 2104 Market data farm connection is OK:cashfarm
    ERROR -1 2104 Market data farm connection is OK:usfarm
    ERROR -1 2106 HMDS data farm connection is OK:ushmds.nj
    ERROR -1 2106 HMDS data farm connection is OK:ushmds
    ERROR -1 2158 Sec-def data farm connection is OK:secdefil
    ERROR 1 162 Historical Market Data Service error message:No market data permissions for ISLAND STK. Requested market data requires additional subscription for API. See link in ‘Market Data Connections’ dialog for more details.

    • Interactive Brokers

      Hello Ankit, thank you for reaching out. All supported API programming languages offer call back functions to receive error messages sent from the TWS for troubleshooting purposes. Socket-based APIs (e.g., C#, Java, VB.Net, C++, Python and ActiveX) handle error messages within the error() call back function in the EWrapper interface. For additional information, including a list of message codes, please review our API documentation. We hope this helps!
      If your query is still not answered after reviewing the documentation, please create a web ticket in Client Portal with the category “API.” Our experts will be glad to help you out!

  • Arun Punj

    Greetings,
    I am trying to download the continous futures historical data for ES. I have set the contract as follows:
    contract = Contract()
    contract.symbol = “ES”
    contract.secType = “CONTFUT”
    contract.exchange = “GLOBEX”
    contract.currency = “USD”
    client.reqHistoricalData(
    Fails with 200 contract specification not found. Can you tell me what is wrong here. Here is there any code sample available for getting continous futures.

  • kamal

    Hello, when I use “self.reqHistoricalData(orderId, mycontract, “20230908 09:20:00 Asia/Kolkata”, “2 D”, “5 mins”, “TRADES”, 0, 1, 0, [])” why the last of the bar is missing ? The output will be like “Historical Data: Date: 20230907 15:25:00, Open: 250.750000, High: 251.000000, Low: 250.400000, Close: 251.000000, Volume: 3814, Average: 250.765000, BarCount: 56
    Historical Data: Date: 20230908 09:15:00, Open: 252.650000, High: 254.000000, Low: 252.500000, Close: 253.250000, Volume: 7373, Average: 252.950000, BarCount: 45

    As you can see its ended on 15:25 not 15:30 I’m unable to end of the day data for 1min (which ends at 15:29) or 2min which ends at 15:28 – I can’t find the days last bar in any timeframe. What am i missing here? thanks!

    • Interactive Brokers

      Hello Kamal. For this inquiry, please open a web ticket in Client Portal (click the “Help?” in the upper right menu, then “Secure Message Center”). The best category to choose is “API.” Our API experts will be able to help you out from there!

  • cnMuggle

    Hi, the thing I don’t understand is when you define class TestApp, and start app.run(), why all the def functions inside the class TestApp are automatically executed? The basic python example tell people that we should explicitly call the function, for example, app.historicalData().

  • Paulo Mendes

    First snippet worked fine, but the second one didn’t. I got the following error message:

    ERROR -1 2104 Market data farm connection is OK:usopt
    ERROR -1 2104 Market data farm connection is OK:usfarm
    ERROR -1 2106 HMDS data farm connection is OK:euhmds
    ERROR -1 2106 HMDS data farm connection is OK:cashhmds
    ERROR -1 2106 HMDS data farm connection is OK:fundfarm
    ERROR -1 2106 HMDS data farm connection is OK:ushmds
    ERROR -1 2158 Sec-def data farm connection is OK:secdefil
    ERROR 1 10314 End Date/Time: The date, time, or time-zone entered is invalid. The correct format is yyyymmdd hh:mm:ss xx/xxxx where yyyymmdd and xx/xxxx are optional. E.g.: 20031126 15:59:00 US/Eastern Note that there is a space between the date and time, and between the time and time-zone. If no date is specified, current date is assumed. If no time-zone is specified, local time-zone is assumed(deprecated). You can also provide yyyymmddd-hh:mm:ss time is in UTC. Note that there is a dash between the date and time in UTC notation.

    When I tried to fix the time (from ’15:00′ to ’15:00:00′) as per the instructions in the error message, the code either hang or said that I didn’t have market data permissions for ISLAND STK. If the previous snippet worked fine for an identical contract, doesn’t this mean that I do have the required permissions? Moreover real-time quotes for AAPL seem to be available normally at TWS.

  • SD

    is there a way to get complete options chain for a security for any expiry ?

    • Interactive Brokers

      Hello, thank you for reaching out. You can use TWS Options Trader to modify the expiration date on a selected underlying asset. You can open it from the New Window button in Mosaic or the Trading Tools menu in Classic TWS. Once open, you can enter or change the underlying symbol in the top left. Next, hit enter to load the option chains. You can modify the expiration dates using the settings along the top. We hope this helps!

  • DR

    Hello,
    Curious to know if there is a link that offers a sample for delayed data without a subscription or a subscription that offers this at a basic entry ? Thanks for any feedback or support. Python

  • Hao

    Hi,

    I tried the snippet of reqMktData in a paper account and get the error message:
    “ERROR 1 10197 No market data during competing live session”

    This only happens when calling reqMktData. The other two (reqTickByTickData/reqHistoricalData) works fine.

    • Interactive Brokers

      Hi Hao, thank you for reaching out. This error message indicates that the user is logged into the paper account and live account simultaneously trying to request live market data using both accounts. In such a scenario preference would be given to the live account. For more details please refer: https://ibkr.info/node/1719 We hope this helps!

  • SD

    I am looking to get complete optios chain for SPX for a given expiry using API

  • Thomas

    I can’t get market data (5s bars, IBUS500 CFD, SMART) older than one month. According to the “Historical Data Limitations” page it should be 6 month, not one. What could I possibly have done wrong? Or have the limitations changed without notice?

    • Interactive Brokers

      Hello, thank you for reaching out. 5 second bars are not supported for period sizes larger than 1 hour (or 3600 S). Please see our documentation for additional insight on valid period units and their affiliated bar sizes: https://ibkrcampus.com/ibkr-api-page/cpapi/#hmds-period-bar-size. We hope this helps!

  • Jetson Davis

    I am trying to use IB Gateway with a Mac. All of the docs say there should be a checkbox “Enable ActiveX and Socket EClient” which does not exist in my config tab!?? Also, in the example above, there is this line of code:

    app.connect(“127.0.0.1”, 7497, 1000)

    What should this be using IB Gateway?

    Finally, I have pip installed ibapi version 10.19.2. My IDE says there is no module ibapi.client or ibapi.wrapper?

    Thx

    • Interactive Brokers

      Hello, thank you for reaching out. For IB Gateway, the “Enable ActiveX and Socket Clients” is always enabled as the platform was built specifically for API use. As discussed in the Essential Components of TWS API, the host, port, and client ID can vary based on system. At a minimum, the Socket Port (7497) would likely need to be changed to accommodate the default of IB Gateway Paper accounts (4002).

      With respect to the inquiry of a pip install, please be aware that Interactive Brokers does not support network pip installation. See “Download the TWS API” for more information, here: https://ibkrcampus.com/ibkr-api-page/trader-workstation-api/#find-the-api. After downloading the appropriate file, please see the Python-specific installation instructions here: https://ibkrcampus.com/ibkr-api-page/trader-workstation-api/#setup-python.

      Please reach back out with any more questions. We are here to help!

  • Alexander

    Hello, I’m just starting to explore the API and when trying the last example (app.reqMktData), I am getting “Requested market data is not subscribed.” What needs to be done to access real-time pricing via the API? This is a personal account. Thanks

    • Interactive Brokers

      Hello Alexander, thank you for asking. Please view this FAQ for instructions to subscribe to Market data in your live account: https://www.ibkr.com/faq?id=28239718

      Some exchanges allow delayed data to be displayed without any market data subscription, free of charge. Customers receive free delayed market data (usually 10-20 minutes behind real-time quotes) for contracts to which they do not currently hold market data subscriptions when made available by the exchanges. To view other market data, please subscribe to the necessary market data subscriptions: https://spr.ly/IBKRMarketDataCampus

      You can also use the Market Data Assistant to help find the best subscriptions for your needs:
      https://ndcdyn.interactivebrokers.com/sso/Login?action=CS_MARKET_DATA_ASSISTANT

      We hope this information is helpful!

  • Anonymous

    Hello, How do I disconnect from the stream politely?

    • Interactive Brokers

      Hello, thank you for reaching out. Please view this FAQ to review or cancel your market data subscriptions:

      https://www.ibkr.com/faq?id=28215152

      We hope this helps!

  • Duane

    Hi IBKRCampus: reqHistoricalData returns data from 1970 with bar size = ‘1 D’ and ‘1 W’. Here’s my method (requesting recent data): app.reqHistoricalData( myOrder, contract, ”, duration, barsize, what_to_show, 1, 2, False, [] ) With ( barsize = ‘1 W’ or barsize = ‘1 D’ ) and duration = ‘6 M’, it returns: date open high low close volume 0 1970-08-22 23:15:26 60.304 62.849 59.938 61.031 1021489740 1 1970-08-22 23:16:42 61.245 66.600 60.700 66.160 1419188440 It works with barsize = ‘1 hour’ and duration = ‘1 M’: date open high low close volume 0 2024-06-27 06:30:00 124.09 126.41 123.75 124.42 36803879 1 2024-06-27 07:00:00 124.44 125.47 123.46 124.23 36089145 Thanks, Duane

  • Duane

    Sorry, it removed all of my CRLF’s when I posted: Hi IBKRCampus: reqHistoricalData returns data from 1970 with bar size = ‘1 D’ and ‘1 W’. Here’s my method (requesting recent data): app.reqHistoricalData( myOrder, contract, ”, duration, barsize, what_to_show, 1, 2, False, [] ) With ( barsize = ‘1 W’ or barsize = ‘1 D’ ) and duration = ‘6 M’, it returns: date open high low close volume 0 1970-08-22 23:15:26 60.304 62.849 59.938 61.031 1021489740 1 1970-08-22 23:16:42 61.245 66.600 60.700 66.160 1419188440 It works with barsize = ‘1 hour’ and duration = ‘1 M’: date open high low close volume 0 2024-06-27 06:30:00 124.09 126.41 123.75 124.42 36803879 1 2024-06-27 07:00:00 124.44 125.47 123.46 124.23 36089145 Thanks, Duane

Leave a Reply

Disclosure: Interactive Brokers

The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

The views and opinions expressed herein are those of the author and do not necessarily reflect the views of Interactive Brokers, its affiliates, or its employees.

Disclosure: API Examples Discussed

Throughout the lesson, please keep in mind that the examples discussed are purely for technical demonstration purposes, and do not constitute trading advice. Also, it is important to remember that placing trades in a paper account is recommended before any live trading.

IBKR Campus Newsletters

This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.