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. |
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.
|
| price | double | Specifies the price for the specified field |
| canAutoExecute | int | Specifies whether the price tick is available for automatic execution. Possible values are:
|
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.
|
| 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!
想問下你背後用咩lib / model 做分析?
ReplyDelete謝謝
Sorry, in english?
ReplyDeletevery nice that you share some practical instructions to program the IB API
ReplyDelete