Welcome to my ibapilessons blog. I am an independent trader, who uses systematic bots to make money in the market. Before becoming my own boss I worked for some financial institutions in Europe. That is the way I learned, but there are many other ways to do it!
In this blog I will try to give you some tips.
I will not include my code in the blog, instead you can see it in the videos from my Youtube channel: IB Lessons. In these videos you will see how to use the Interactive Brokers Java API, which is the most professional trading platform that I found. What I will include in this blog are links to the Interactive Brokers website, which are extremely useful, and sometimes information about Quant strategies and links to learn about them.
If you need help with the API, you want to learn more, or you need a programmer to develop your coolest strategy, you can send me an e-mail to ibapilessons@gmail.com.
I hope you enjoy the videos!
You can start with this one first:
In this video you could see the method eConnect(), which is used to connect to the TWS. You can have information about this method here.
| Parameter | Type | Description |
|---|---|---|
| host | String | The host name or IP address of the machine where TWS is running. Leave blank to connect to the local host. |
| port | int | Must match the port specified in TWS on the Configure>API>Socket Port field. |
| clientId | int |
A number used to identify this client connection. All orders placed/modified from this client will be associated with this client identifier.
Note: Note: Each client MUST connect with a unique clientId.
|
Source: https://www.interactivebrokers.com/en/software/api/apiguide/java/econnect.htm
This may be an example:
client.eConnect(null, 7496, 1);
This method does not return any value confirming the connection, so you should check the state of you programm with this method client.isConnected().
Another method that appears in the video is the placeOrder() method. Here are the parameters that you need to introduce:
| Parameter | Type | Description |
|---|---|---|
| id | int | The order Id. You must specify a unique value. When the order status returns, it will be identified by this tag. This tag is also used when canceling the order. |
| contract | Contract | This class contains attributes used to describe the contract. |
| order | Order | This structure contains the details of the order. Note: Each client MUST connect with a unique clientId. |
Source: https://www.interactivebrokers.com/en/software/api/apiguide/java/placeorder.htm
But, in order to make that method work, you will need to create a contract object. You can find information about the Contract class here.
| Attribute | Description |
|---|---|
| Vector m_comboLegs | Dynamic memory structure used to store the leg definitions for this contract. |
| String m_comboLegsDescrip | Description for combo legs |
| int m_conId | The unique contract identifier. |
| String m_currency | Specifies the currency. Ambiguities may require that this field be specified, for example, when SMART is the exchange and IBM is being requested (IBM can trade in GBP or USD). Given the existence of this kind of ambiguity, it is a good idea to always specify the currency. |
| String m_exchange | The order destination, such as Smart. |
| String m_expiry | The expiration date. Use the format YYYYMM. |
| boolean m_includeExpired |
If set to true, contract details requests and historical data queries can be performed pertaining to expired contracts.
Note: Historical data queries on expired contracts are limited to the last year of the contracts life, and are initially only supported for expired futures contracts,
|
| String m_localSymbol | This is the local exchange symbol of the underlying asset. |
| String m_multiplier | Allows you to specify a future or option contract multiplier. This is only necessary when multiple possibilities exist. |
| String m_primaryExch | Identifies the listing exchange for the contract (do not list SMART). |
| String m_right | Specifies a Put or Call. Valid values are: P, PUT, C, CALL. |
| String m_secId | Unique identifier for the secIdType. |
| String m_secIdType | Security identifier, when querying contract details or when placing orders. Supported identifiers are:
|
| String m_secType | This is the security type. Valid values are:
|
| double m_strike | The strike price. |
| String m_symbol | This is the symbol of the underlying asset. |
| String m_tradingClass | The trading class name for this contract. |
Source: https://www.interactivebrokers.com/en/software/api/apiguide/java/contract.htm
That is all for today! You can send me a mail if you do not figure out the methods and classes.
PD. I am not a native English speaker, yes I am sorry for that, I may hire somebody to check my mistakes in the future. I hope everything makes sense.
No comments:
Post a Comment