Friday, October 21, 2016

3rd Interactive Brokers Java API Tutorial (Download Mkt Data)

Hi,

Today I will show you how to download tick market data from Interactive Brokers. I will use this method: reqMktData(). You can check the Interactive Brokers website here. You will see the following parameters:


Parameter Type Description
id TickerId The ticker id. Must be a unique value. When the market data returns, it will be identified by this tag. This is also used when canceling the market data.
contract Contract This structure contains a description of the contract for which market data is being requested.
genericTicks IBString A comma delimited list of generic tick types. Tick types can be found in the Generic Tick Types page.
snapshot bool Check to return a single snapshot of market data and have the market data subscription cancel. Do not enter any genericTicklist values if you use snapshot.
mktDataOptions TagValueListSPtr For internal use only. Use default value XYZ.
Source: https://www.interactivebrokers.com/en/software/api/apiguide/tables/generic_tick_types.htm

To receive the market data from the API you will need to use one of the following methods: tickPrice() and tickSize(). These are the variables that you will need to use for the tickPrice method:

Parameter Type Description
tickerId int The ticker Id that was specified previously in the call to reqMktData()
field int Specifies the type of price. Pass the field value into TickType.getField(int tickType) to retrieve the field description.  For example, a field value of 1 will map to bidPrice, a field value of 2 will map to askPrice, etc.
  • 1 = bid
  • 2 = ask
  • 4 = last
  • 6 = high
  • 7 = low
  • 9 = close
price double Specifies the price for the specified field
canAutoExecute int Specifies whether the price tick is available for automatic execution. Possible values are:
  • 0 = not eligible for automatic execution
  • 1 = eligible for automatic execution

Source: https://www.interactivebrokers.com/en/software/api/apiguide/java/tickprice.htm

These are the variables for the tickSize method:

Parameter Type Description
tickerId int The ticker Id that was specified previously in the call to reqMktData()
field int
Specifies the type of price.
Pass the field value into TickType.getField(int tickType) to retrieve the field description.  For example, a field value of 0 will map to bidSize, a field value of 3 will map to askSize, etc.
  • 0 = bid size
  • 3 = ask size
  • 5 = last size
  • 8 = volume
size int Specifies the size for the specified field

Source: https://www.interactivebrokers.com/en/software/api/apiguide/java/ticksize.htm

I do not want to explain everything, you have the video, and you are smart (you are reading this, so you should be):



Source: https://www.youtube.com/watch?v=59pXOy4AIHE

Enjoy!

3 comments:

  1. 想問下你背後用咩lib / model 做分析?
    謝謝

    ReplyDelete
  2. very nice that you share some practical instructions to program the IB API

    ReplyDelete