IB API Software Architecture

The Interactive Brokers (IB) data stream and order system can only be communicated with through the TWS (Tradestation) software. The Trade Engine makes a TCP/IP or local host connection to the TWS software. There are two sides to the communication: the request and the response.

To make a request a class is created that implements the EWrapper Java interface. This class implemented the call back methods (defined by the EWrapper interface) that will be used to respond to requests. For example, the tickPrice method is used to return the tick price for a market data stream request. The class that implements EWrapper contains an instance of EClientSocket. This is the socket interface to the TWS. The EClientSocket object is instantiated with a reference to its enclosing class (which implements EWrapper). The EClientSocket class provides the methods for making requests to IB (through TWS). For example, the reqMktData method supports requests for a market data stream.

The diagram below shows the relationship between the various classes.

The EClientSocket object creates a thread that reads from the socket and calls the various call back methods from the EWrapper class that it was initialized with. This means that the process of reading from the socket and writing to the call back methods, is asynchronous and since it takes place in a separate thread.