Sunday, December 18, 2011

IB SDK/API review

This article reflects my experience developing an automated equity trading platforms using the IB SDK/API. I have written this article as an individual, not representing IB (Interactive brokers) in ANY way.

The IB Application Program Interface (API) connects through the Trader Workstation (often known as TWS) or the IB Gateway. TWS is programmed in Java, which is platform-independent and can be very useful( but, it is not as fast as it would be if it was programmed in C or C++ ). In order to connect to IB, the TWS (Trading Work Station ) application must be running in the background. The connection takes place via a network connection. If the TWS and the API application run on the same system this network connection will be through localhost ( which is a bit awkward, since trading program execution requires TWS to be run first to establish a session).

The good news is that, TWS provides a great API ( application programming interface ) in several programming languages, which including Java,C++, ActiveX and DDE for Excel ( there is also a possibility to get an interface in C# ), and this can be used to access almost all of the TWS' features via other programs. The API code makes a TCP/IP or local host connection to the TWS software( usually to port 7496 on the local host). There are two sides to the communication: the request and the response. This means that the process of reading from the socket and writing to the call back methods, is asynchronous and it takes place in separate threads. IB transaction either go through the TWS (trading software),or through CTCI FIX. When using The IB API, A single account (user name and password) is limited to 50 messages a second. Using the CTCI FIX interface the limit is150 messages a second. If you have the possibility, I would suggest to avoid using the CTCI FIX since its complex and sample applications are not provided.

Beside that, this are some of the issues that I had to deal with :
1) Opening an account with IB takes a long time. Application forms are the largest I have seen.
2) The API Chat is usually empty ( Which mean that I am the only person in the room ). Only Registered clients ( customers who paid money ), will get a full customer support by mail.
3) There were several technical issues, which forced me to find a creative solution inorder to make my trading platform work as I needed. For Eg: I placed a limit BUY at $60 for a stock at $30, IB rejected the order as too far outside the NBBO. Well, IB allows you to override TWS order price percentage constraints ( which are applied to orders that TWS sees as deviating too much from the NBBO` of the contract ). Unfortunately, setting this param ( from TWS or the API ) had no effect, and my only alternative was to place a market order. I guess, That this param exist there as a restriction created by the exchange in order to "protect" me. But, If I'm responsible enough for my own trades and want to make some more money, why this feature is not working ? Maybe if enough people will complain to IB , they will fix it.
4) Limits to data requests : 60 requests in 10 mins (almost) without pacing violations, But also this issue can be handled by implementing a smart mechanism ( Or you can just get real time data from Yahoo! Finance )

Despite of the problems I've described above, My main impression is good. The very best advantage that IB offers for developers is that there is a discussion forum, which serves as a serviceable message board where traders read and share information or even post programming code, also a very good API reference guide is presented, and you get code samples which,ship with the IB's API package.(Code samples :Cpp, Java, VB6, VB.NET, C#.NET).

IB support ( Only Registered clients ), a paper trading account which allows traders to test the full range of IB trading facilities in a simulated environment using real market conditions. Its especially beneficial to traders that want a special strategy implemented for them by a developer, without using there real account (paper trading account works just like the production account, but has different username/password). as well, Users can test new strategies and ideas risk-free or learn about order execution of global products they've never traded in the past. Last but not least, IB allows very sophisticated, advanced order specification and routing. They allow you to trade just about every kind of tradable security.

Moris oz
Algorithmic trading Consulting and development
www.caapitech.com