- Solve real problems with our hands-on interface
- Progress from basic puts and calls to advanced strategies
Lesson 5 of 8
New to Interactive Brokers?
In the previous lesson, we learned about the IBrokers package and some of the basic API methods like establishing connection with TWS, getting account details, and creating contracts for use in API calls. In this lesson, we will cover the different types of Market Data, learn about Market data lines and show how to fetch streaming and historical market data from the Trader Workstation.
By default, there are certain ‘default tick types’ that are returned. Additional data types are available that can be requested by specifying certain ‘generic tick types’ in the market data request. Callbacks, via CALLBACK and eventWrapper are designed to allow for R level processing of the real-time data stream and provide for more control over the incoming results. We will see how to do this in the next lesson.
The output can be seen in the console. We can see the market depth data up to 5 best bid and ask prices.
Valid Bar Sizes – The valid bar sizes must be specified exactly as shown in the below table. However, there is no guarantee from the API that all will work for all securities or durations.
Valid whatToShow values – The whatToShow values can be any one of the following type: Trades, Midpoint, Bid, Ask, and Bid_Ask
Example: Let us now see how the historical data function works. We first define the contract for which we want to pull the historical data on line 8. On line 11, we use the function with the TWS connection, and the security objects as the arguments. Upon execution the output can be seen in the console.
In the next example, we pull the 1 minute data for the duration of 1 week by specifying the respective arguments. Upon execution the 1 minute data can be seen in the console. 
Information posted on IBKR Campus that is provided by third-parties does NOT constitute a recommendation that you should contract for the services of that third party. Third-party participants who contribute to IBKR Campus are independent of Interactive Brokers and Interactive Brokers does not make any representations or warranties concerning the services offered, their past or future performance, or the accuracy of the information provided by the third party. Past performance is no guarantee of future results.
This material is from QuantInsti and is being posted with its permission. The views expressed in this material are solely those of the author and/or QuantInsti and Interactive Brokers is not endorsing or recommending any investment or trading discussed in the material. This material is not and should not be construed as an offer to buy or sell any security. It should not be construed as research or investment advice or a recommendation to buy, sell or hold any security or commodity. 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.
Join The Conversation
For specific platform feedback and suggestions, please submit it directly to our team using these instructions.
If you have an account-specific question or concern, please reach out to Client Services.
We encourage you to look through our FAQs before posting. Your question may already be covered!