IB API C++ programming

Discussion in 'App Development' started by marsman, Jul 14, 2016.

  1. marsman

    marsman

    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: Jul 17, 2016
    #31     Jul 17, 2016
  2. marsman

    marsman

    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
    ...
     
    #32     Jul 17, 2016
  3. marsman

    marsman

    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: Jul 17, 2016
    #33     Jul 17, 2016
  4. marsman

    marsman

    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: Jul 17, 2016
    #34     Jul 17, 2016
  5. marsman

    marsman

    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...
     
    #35     Jul 18, 2016
  6. 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: Jul 18, 2016
    #36     Jul 18, 2016
  7. marsman

    marsman

    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...
     
    #37     Jul 18, 2016
  8. marsman

    marsman

    #38     Jul 18, 2016