IB API C++ programming

Using a similar set-up but with the Java API. Would recommend the Yahoo TWS API group for help. Also, console only via IB Gateway is a bad idea IMHO. Servers are so cheap nowadays it's easy to add some extra RAM and have a VNC solution so you can see the TWS GUI in case there's a problem. Finally, for some strange reason the API logs are deeper if you are running TWS than the Gateway.
Yes, I for some time now am subscribing the yahoo TWS group, ie. getting the postings via email.
I'm maybe old-school, as said I don't want have any server with a GUI; console login via ssh is sufficient for me.
 
Last edited:
The following additions/modifications in the posted 2 Makefile's then take care also of the header files:

...
SOURCES=$(wildcard *.cpp)
HEADERS=$(wildcard *.h)

TARGET=...

$(TARGET): $(SOURCES:.cpp=.o) $(HEADERS) Makefile
...
 
The latest versions of my Makefile's:

Code:
# Makefile (for GNU Make on Linux)
#
# Creates static library 'source/cppclient/client/libtwsapi.a'
#
# Author: marsman @ ET  :-)
# Date  : 2016-07-17-Su
#

CXX=g++
CXXFLAGS=-pthread -Wall -O2 -std=c++11 -Wno-switch

TARGET=libtwsapi.a

SOURCES=$(wildcard *.cpp)
HEADERS=$(wildcard *.h)

$(TARGET): $(SOURCES:.cpp=.o)
        ar cr $@ $^

.cpp.o: $(SOURCES) $(HEADERS) Makefile
        ${CXX} ${CXXFLAGS} -c $<

clean:
        rm -f $(TARGET) *.o


Code:
# Makefile (for GNU Make on Linux)
#
# Creates the app 'TestCppClient'
# (user must first have built the 'libtwsapi.a' in the source/cppclient/client directory --> see the Makefile there)
#
# Author: marsman @ ET  :-)
# Date  : 2016-07-17-Su
#

CXX=g++
CXXFLAGS=-pthread -Wall -O2   -std=c++11 -Wno-switch
#CXXFLAGS=-pthread -Wall -ggdb -std=c++11 -Wno-switch         # for dbg

ROOT_DIR=../../../source/cppclient
BASE_SRC_DIR=${ROOT_DIR}/client
INCLUDES=-I${BASE_SRC_DIR} -I${ROOT_DIR}

TARGET=TestCppClient

SOURCES=$(wildcard *.cpp)
HEADERS=$(wildcard *.h)

$(TARGET): $(SOURCES:.cpp=.o) $(BASE_SRC_DIR)/libtwsapi.a
        $(CXX) ${CXXFLAGS} -o $@ $^

.cpp.o: $(SOURCES) $(HEADERS) Makefile
        ${CXX} ${CXXFLAGS} $(INCLUDES) -c $<

clean:
        rm -f $(TARGET) *.o
 
Last edited:
All I need is to get every x minutes, say every 5 minutes, the Level-1 data to all strikes of one expiration date.
How do I do that?
Get once the ContractDetails of that expiration date, ie. get all strikes.
Then every 5 minutes loop over all the strikes to get their snapshot quotes?
This is IMO overkill. Isn't there any easier method?
 
Last edited:
All I need is to get every x minutes, say every 5 minutes, the Level-1 data to all strikes of one expiration date.
How do I do that?
Get once the ContractDetails of that expiration date, ie. get all strikes.
Then every 5 minutes loop over all the strikes to get their snapshot quotes?
This is IMO overkill. Isn't there any easier method?
Since the above method is very impractical to accomplish with the IB API, I've to change my concept by limiting myself to a few hand-selected strikes only...
For this selection (analysis) I've to use web-data... :) Oh boy...
 
All I need is to get every x minutes, say every 5 minutes, the Level-1 data to all strikes of one expiration date.
How do I do that?
Get once the ContractDetails of that expiration date, ie. get all strikes.
Then every 5 minutes loop over all the strikes to get their snapshot quotes?
This is IMO overkill. Isn't there any easier method?

Yes there is. Create an std:map keyed by strike (i.e. the "first" of the pair). Create a struct that contains the bid/ask/last for call and put (the "second" of the pair). Subscribe to the tick data for all the calls and puts for all the strikes for the desired expiry.

I can assure you that every 3rd party app for IB does something like this. There is not magic secret way that's easier.

Every 5 minutes iterate through the map and get the latest values in the struct.
 
Last edited:
Yes there is. Create an std:map keyed by strike (i.e. the "first" of the pair). Create a struct that contains the bid/ask/last for call and put (the "second" of the pair). Subscribe to the tick data for all the calls and puts for all the strikes for the desired expiry.

I can assure you that every 3rd party app for IB does something like this. There is not magic secret way that's easier.

Every 5 minutes iterate through the map and get the latest values in the struct.
Yes, that seems to be the only way with this API. But IMO it's not efficient for such use-cases like mine.

IMO a much better approch would be if the API would have some new methods for delivering "snapshot tables",
for example similar to what GoogleFinance and YahooFinance make available via web, and also as json, unfortunately what they have is too much delayed.

It would be even much better if the user could specify which fields the table should contain (like is the case with Yahoo's web API).

My current solution uses such tables from the web. I just wanted to improve it by using IB's feed, but it's more work than I had imagined...
 
And: I had also sent the compiler warnings to IB's API team, but have not heard anything since then yet...

They replied. Here's an excerpt of the reply:
IB_API_Team.png


Ie. one shall report API issues at the above github-adress http://interactivebrokers.github.io
--> http://interactivebrokers.github.io/api_software_contribute.html
 
Back
Top