IB API C++ programming

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

  1. marsman

    marsman

    I of course couldn't resist and wanted to compile the new version... but it of course does not... :(
    Reason is this: the API guys are developing on an OS that is case-insensitive with file and directory names (Win or Mac).
    But Linux/Unix has always been case-sensitive.

    Solution is to make some symbolic links:

    in directory ~/IBJts/source
    ln -s CppClient cppclient

    in directory ~/IBJts/source/CppClient/client
    ln -s executioncondition.cpp ExecutionCondition.cpp
    ln -s executioncondition.h ExecutionCondition.h

    ... oh boy, there is much more to fix... For example Sleep() is undefined.
    I had in my old version fixed that all, but need to repeat all that again... sh*t!

    Oh IB API guys, come on folks, you can surely do better...
     
    Last edited: Jul 14, 2016
    #21     Jul 14, 2016
  2. marsman

    marsman

    Ok, got it compile now, but haven't test run it yet b/c I have an important meeting in a couple of hours...:

    Changes to do to get IB API Beta 9.72.16 to compile on Linux
    (ie. the TestCppClient application)
    ------------------------------------------------------------

    In directory ~/IBJts/source
    ln -s CppClient cppclient

    In directory ~/IBJts/source/CppClient/client
    mv executioncondition.cpp ExecutionCondition.cpp
    ln -s executioncondition.h ExecutionCondition.h

    And use this ~/IBJts/source/CppClient/client/StdAfx.h instead of the one provided there:

    #ifndef StdAfx_h
    #define StdAfx_h

    /* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
    * and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */

    #ifdef _MSC_VER

    #ifdef TWSAPISSLDLL
    # define TWSAPISSLDLLEXP __declspec(dllexport)
    #endif

    #define assert ASSERT
    #define snprintf _snprintf
    #include <WinSock2.h>
    #include <Windows.h>
    #define IB_WIN32

    #else

    #include <unistd.h> // defines _POSIX_THREADS, @see http://bit.ly/1pWJ8KQ#tag_13_80_03_02
    #include <sys/syscall.h>
    #include <sys/types.h>

    #if defined(_POSIX_THREADS) && (_POSIX_THREADS > 0)
    #include <pthread.h>
    #define IB_POSIX
    #else
    #error "Not supported on this platform"
    #endif

    #define Sleep(n) usleep(n * 1000)

    #endif // #ifdef _MSC_VER

    #include <string>
    #include <deque>
    #include <vector>
    #include <algorithm>
    // #include <openssl/bio.h>
    // #include <openssl/ssl.h>
    // #include <openssl/err.h>

    #ifndef TWSAPISSLDLLEXP
    #define TWSAPISSLDLLEXP
    #endif
    #ifndef TWSAPIDLLEXP
    #define TWSAPIDLLEXP
    #endif

    #include <stdexcept>

    using namespace std;

    #endif



    But there are many compiler warnings:

    Code:
    g++ -pthread -Wall -Wno-switch -std=c++11 -I../../../source/cppclient/client -I../../../source/cppclient ../../../source/cppclient/client/*.cpp ./*.cpp -oTestCppClient
    In file included from ../../../source/cppclient/client/ContractCondition.cpp:3:0:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    In file included from ../../../source/cppclient/client/EClient.cpp:8:0:
    ../../../source/cppclient/client/EClient.h: In constructor ‘EClient::EClient(EWrapper*, ETransport*)’:
    ../../../source/cppclient/client/EClient.h:213:7: warning: ‘EClient::m_useV100Plus’ will be initialized after [-Wreorder]
      bool m_useV100Plus;
           ^
    ../../../source/cppclient/client/EClient.h:190:31: warning:   ‘std::auto_ptr<ETransport> EClient::m_transport’ [-Wreorder]
         std::auto_ptr<ETransport> m_transport;
                                   ^
    ../../../source/cppclient/client/EClient.cpp:229:1: warning:   when initialized here [-Wreorder]
    EClient::EClient( EWrapper *ptr, ETransport *pTransport)
    ^
    In file included from ../../../source/cppclient/client/TagValue.h:8:0,
                     from ../../../source/cppclient/client/EClient.h:14,
                     from ../../../source/cppclient/client/EClient.cpp:8:
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = OrderCondition]’:
    ../../../source/cppclient/client/EClient.cpp:1877:56:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘OrderCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
        ~shared_ptr() { if (use_.only()) delete ptr_; }
                                         ^
    In file included from ../../../source/cppclient/client/EClient.cpp:18:0:
    ../../../source/cppclient/client/EDecoder.h: At global scope:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    ../../../source/cppclient/client/EClientSocket.cpp: In member function ‘virtual void EClientSocket::redirect(const char*, int)’:
    ../../../source/cppclient/client/EClientSocket.cpp:269:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      if( (m_hostNorm != this->host() || port != this->port())) {
                                              ^
    In file included from ../../../source/cppclient/client/EClientSocket.cpp:12:0:
    ../../../source/cppclient/client/EDecoder.h: At global scope:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    In file included from ../../../source/cppclient/client/TagValue.h:8:0,
                     from ../../../source/cppclient/client/Order.h:8,
                     from ../../../source/cppclient/client/EDecoder.cpp:8:
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = OrderCondition]’:
    ../../../source/cppclient/client/EDecoder.cpp:623:153:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘OrderCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
        ~shared_ptr() { if (use_.only()) delete ptr_; }
                                         ^
    ../../../source/cppclient/client/EReader.cpp: In member function ‘void EReader::readToQueue()’:
    ../../../source/cppclient/client/EReader.cpp:72:12: warning: unused variable ‘msg’ [-Wunused-variable]
      EMessage *msg = 0;
                ^
    ../../../source/cppclient/client/EReader.cpp: In member function ‘bool EReader::bufferedRead(char*, int)’:
    ../../../source/cppclient/client/EReader.cpp:181:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      while (m_buf.size() < size)
                          ^
    ../../../source/cppclient/client/EReader.cpp: In member function ‘EMessage* EReader::readSingleMsg()’:
    ../../../source/cppclient/client/EReader.cpp:218:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
        if (m_buf.size() >= m_nMaxBufSize * 3/4)
                         ^
    In file included from ../../../source/cppclient/client/EReader.cpp:7:0:
    ../../../source/cppclient/client/EDecoder.h: At global scope:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    In file included from ../../../source/cppclient/client/ExecutionCondition.cpp:3:0:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    In file included from ../../../source/cppclient/client/OperatorCondition.cpp:3:0:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    In file included from ../../../source/cppclient/client/OrderCondition.h:3:0,
                     from ../../../source/cppclient/client/OrderCondition.cpp:2:
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = OrderCondition]’:
    /usr/include/c++/4.9/bits/stl_construct.h:93:7:   required from ‘void std::_Destroy(_Tp*) [with _Tp = ibapi::shared_ptr<OrderCondition>]’
    /usr/include/c++/4.9/bits/stl_construct.h:103:46:   required from ‘static void std::_Destroy_aux<<anonymous> >::__destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*; bool <anonymous> = false]’
    /usr/include/c++/4.9/bits/stl_construct.h:127:27:   required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*]’
    /usr/include/c++/4.9/bits/stl_construct.h:151:31:   required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>&) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*; _Tp = ibapi::shared_ptr<OrderCondition>]’
    /usr/include/c++/4.9/bits/stl_vector.h:425:30:   required from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = ibapi::shared_ptr<OrderCondition>; _Alloc = std::allocator<ibapi::shared_ptr<OrderCondition> >]’
    ../../../source/cppclient/client/Order.h:46:2:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘OrderCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
        ~shared_ptr() { if (use_.only()) delete ptr_; }
                                         ^
    In file included from ../../../source/cppclient/client/OrderCondition.cpp:9:0:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    In file included from ../../../source/cppclient/client/OrderCondition.h:3:0,
                     from ../../../source/cppclient/client/OperatorCondition.h:2,
                     from ../../../source/cppclient/client/ContractCondition.h:2,
                     from ../../../source/cppclient/client/PercentChangeCondition.h:2,
                     from ../../../source/cppclient/client/PercentChangeCondition.cpp:2:
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = OrderCondition]’:
    /usr/include/c++/4.9/bits/stl_construct.h:93:7:   required from ‘void std::_Destroy(_Tp*) [with _Tp = ibapi::shared_ptr<OrderCondition>]’
    /usr/include/c++/4.9/bits/stl_construct.h:103:46:   required from ‘static void std::_Destroy_aux<<anonymous> >::__destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*; bool <anonymous> = false]’
    /usr/include/c++/4.9/bits/stl_construct.h:127:27:   required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*]’
    /usr/include/c++/4.9/bits/stl_construct.h:151:31:   required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>&) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*; _Tp = ibapi::shared_ptr<OrderCondition>]’
    /usr/include/c++/4.9/bits/stl_vector.h:425:30:   required from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = ibapi::shared_ptr<OrderCondition>; _Alloc = std::allocator<ibapi::shared_ptr<OrderCondition> >]’
    ../../../source/cppclient/client/Order.h:46:2:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘OrderCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
        ~shared_ptr() { if (use_.only()) delete ptr_; }
                                         ^
    In file included from ../../../source/cppclient/client/PriceCondition.cpp:4:0:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    In file included from ../../../source/cppclient/client/TagValue.h:8:0,
                     from ../../../source/cppclient/client/Order.h:8,
                     from ./AvailableAlgoParams.cpp:6:
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = OrderCondition]’:
    /usr/include/c++/4.9/bits/stl_construct.h:93:7:   required from ‘void std::_Destroy(_Tp*) [with _Tp = ibapi::shared_ptr<OrderCondition>]’
    /usr/include/c++/4.9/bits/stl_construct.h:103:46:   required from ‘static void std::_Destroy_aux<<anonymous> >::__destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*; bool <anonymous> = false]’
    /usr/include/c++/4.9/bits/stl_construct.h:127:27:   required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*]’
    /usr/include/c++/4.9/bits/stl_construct.h:151:31:   required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>&) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*; _Tp = ibapi::shared_ptr<OrderCondition>]’
    /usr/include/c++/4.9/bits/stl_vector.h:425:30:   required from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = ibapi::shared_ptr<OrderCondition>; _Alloc = std::allocator<ibapi::shared_ptr<OrderCondition> >]’
    ../../../source/cppclient/client/Order.h:46:2:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘OrderCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
        ~shared_ptr() { if (use_.only()) delete ptr_; }
                                         ^
    In file included from ../../../source/cppclient/client/EReader.h:7:0,
                     from ./TestCppClient.h:10,
                     from ./Main.cpp:16:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    ./OrderSamples.cpp: In static member function ‘static Order OrderSamples::ComboLimitOrder(std::string, double, double, bool)’:
    ./OrderSamples.cpp:623:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      if(nonGuaranteed = true){
                             ^
    ./OrderSamples.cpp: In static member function ‘static Order OrderSamples::ComboMarketOrder(std::string, double, bool)’:
    ./OrderSamples.cpp:645:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      if(nonGuaranteed = true){
                             ^
    ./OrderSamples.cpp: In static member function ‘static Order OrderSamples::LimitOrderForComboWithLegPrices(std::string, double, std::vector<double>, bool)’:
    ./OrderSamples.cpp:668:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for(int i = 0; i < legprices.size(); i++){
                       ^
    ./OrderSamples.cpp:673:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      if(nonGuaranteed = true){
                             ^
    ./OrderSamples.cpp: In static member function ‘static Order OrderSamples::RelativeLimitOrder(std::string, double, double, bool)’:
    ./OrderSamples.cpp:696:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      if(nonGuaranteed = true){
                             ^
    ./OrderSamples.cpp: In static member function ‘static Order OrderSamples::RelativeMarketCombo(std::string, double, bool)’:
    ./OrderSamples.cpp:718:25: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
      if(nonGuaranteed = true){
                             ^
    In file included from ./OrderSamples.h:6:0,
                     from ./OrderSamples.cpp:5:
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = OrderCondition]’:
    /usr/include/c++/4.9/bits/stl_construct.h:93:7:   required from ‘void std::_Destroy(_Tp*) [with _Tp = ibapi::shared_ptr<OrderCondition>]’
    /usr/include/c++/4.9/bits/stl_construct.h:103:46:   required from ‘static void std::_Destroy_aux<<anonymous> >::__destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*; bool <anonymous> = false]’
    /usr/include/c++/4.9/bits/stl_construct.h:127:27:   required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*]’
    /usr/include/c++/4.9/bits/stl_construct.h:151:31:   required from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>&) [with _ForwardIterator = ibapi::shared_ptr<OrderCondition>*; _Tp = ibapi::shared_ptr<OrderCondition>]’
    /usr/include/c++/4.9/bits/stl_vector.h:425:30:   required from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = ibapi::shared_ptr<OrderCondition>; _Alloc = std::allocator<ibapi::shared_ptr<OrderCondition> >]’
    ../../../source/cppclient/client/Order.h:46:2:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘OrderCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
        ~shared_ptr() { if (use_.only()) delete ptr_; }
                                         ^
    In file included from ./TestCppClient.cpp:6:0:
    ./TestCppClient.h: In constructor ‘TestCppClient::TestCppClient()’:
    ./TestCppClient.h:185:18: warning: ‘TestCppClient::m_osSignal’ will be initialized after [-Wreorder]
      EReaderOSSignal m_osSignal;
                      ^
    ./TestCppClient.h:184:24: warning:   ‘EClientSocket* const TestCppClient::m_pClient’ [-Wreorder]
      EClientSocket * const m_pClient;
                            ^
    ./TestCppClient.cpp:42:1: warning:   when initialized here [-Wreorder]
    TestCppClient::TestCppClient() :
    ^
    ./TestCppClient.cpp: In destructor ‘virtual TestCppClient::~TestCppClient()’:
    ./TestCppClient.cpp:58:12: warning: deleting object of polymorphic class type ‘EClientSocket’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
         delete m_pClient;
                ^
    ./TestCppClient.cpp: In member function ‘void TestCppClient::processMessages()’:
    ./TestCppClient.cpp:99:9: warning: unused variable ‘readSet’ [-Wunused-variable]
      fd_set readSet, writeSet, errorSet;
             ^
    ./TestCppClient.cpp:99:18: warning: unused variable ‘writeSet’ [-Wunused-variable]
      fd_set readSet, writeSet, errorSet;
                      ^
    ./TestCppClient.cpp:99:28: warning: unused variable ‘errorSet’ [-Wunused-variable]
      fd_set readSet, writeSet, errorSet;
                                ^
    ./TestCppClient.cpp:101:17: warning: variable ‘tval’ set but not used [-Wunused-but-set-variable]
      struct timeval tval;
                     ^
    ./TestCppClient.cpp: In member function ‘void TestCppClient::ocaSamples()’:
    ./TestCppClient.cpp:580:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for(int i = 0; i < ocaOrders.size(); i++){
                       ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::nextValidId(OrderId)’:
    ./TestCppClient.cpp:810:39: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘OrderId {aka long int}’ [-Wformat=]
      printf("Next Valid Id: %d\n", orderId);
                                           ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::tickPrice(TickerId, TickType, double, int)’:
    ./TestCppClient.cpp:861:110: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "Tick Price. Ticker Id: %d, Field: %d, Price: %g, CanAutoExecute: %d\n", tickerId, (int)field, price);
                                                                                                                  ^
    ./TestCppClient.cpp:861:110: warning: format ‘%d’ expects a matching ‘int’ argument [-Wformat=]
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::tickSize(TickerId, TickType, int)’:
    ./TestCppClient.cpp:867:87: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "Tick Size. Ticker Id: %d, Field: %d, Size: %d\n", tickerId, (int)field, size);
                                                                                           ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::tickOptionComputation(TickerId, TickType, double, double, double, double, double, double, double, double)’:
    ./TestCppClient.cpp:875:277: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "TickOptionComputation. Ticker Id: %d, Type: %d, ImpliedVolatility: %g, Delta: %g, OptionPrice: %d, pvDividend: %g, Gamma: %g, Vega: %g, Theta: %g, Underlying Price: %g\n", tickerId, (int)tickType, impliedVol, delta, optPrice, pvDividend, gamma, vega, theta, undPrice);
                                                                                                                                                                                                                                                                                         ^
    ./TestCppClient.cpp:875:277: warning: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::tickGeneric(TickerId, TickType, double)’:
    ./TestCppClient.cpp:881:94: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "Tick Generic. Ticker Id: %d, Type: %d, Value: %s\n", tickerId, (int)tickType, value);
                                                                                                  ^
    ./TestCppClient.cpp:881:94: warning: format ‘%s’ expects argument of type ‘char*’, but argument 4 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::tickString(TickerId, TickType, const string&)’:
    ./TestCppClient.cpp:887:101: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "Tick String. Ticker Id: %d, Type: %d, Value: %s\n", tickerId, (int)tickType, value.c_str());
                                                                                                         ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::tickEFP(TickerId, TickType, double, const string&, double, int, const string&, double, double)’:
    ./TestCppClient.cpp:893:361: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "TickEFP. %d, Type: %d, BasisPoints: %d, FormattedBasisPoints: %s, Total Dividends: %d, HoldDays: %d, Future Last Trade Date: %s, Dividend Impact: %d, Dividends To Last Trade Date: %d\n", tickerId, (int)tickType, basisPoints, formattedBasisPoints.c_str(), totalDividends, holdDays, futureLastTradeDate.c_str(), dividendImpact, dividendsToLastTradeDate);
                                                                                                                                                                                                                                                                                                                                                                             ^
    ./TestCppClient.cpp:893:361: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp:893:361: warning: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp:893:361: warning: format ‘%d’ expects argument of type ‘int’, but argument 9 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp:893:361: warning: format ‘%d’ expects argument of type ‘int’, but argument 10 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::orderStatus(OrderId, const string&, double, double, double, int, int, double, int, const string&)’:
    ./TestCppClient.cpp:900:255: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘OrderId {aka long int}’ [-Wformat=]
      printf("OrderStatus. Id: %d, Status: %s, Filled: %g, Remaining: %g, AvgFillPrice: %g, PermId: %d, LastFillPrice: %g, ClientId: %d, WhyHeld: %s\n", orderId, status.c_str(), filled, remaining, avgFillPrice, permId, lastFillPrice, clientId, whyHeld.c_str());
                                                                                                                                                                                                                                                                   ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::openOrder(OrderId, const Contract&, const Order&, const OrderState&)’:
    ./TestCppClient.cpp:906:238: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘OrderId {aka long int}’ [-Wformat=]
      printf( "OpenOrder. ID: %d, %s, %s @ %s: %s, %s, %g, %s\n", orderId, contract.symbol.c_str(), contract.secType.c_str(), contract.exchange.c_str(), order.action.c_str(), order.orderType.c_str(), order.totalQuantity, ostate.status.c_str());
                                                                                                                                                                                                                                                  ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::contractDetails(int, const ContractDetails&)’:
    ./TestCppClient.cpp:950:343: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘long int’ [-Wformat=]
      printf( "ContractDetails. ReqId: %d - %s, %s, ConId: %d @ %s, Trading Hours: %s, Liquidation Hours: %s\n", reqId, contractDetails.summary.symbol.c_str(), contractDetails.summary.secType.c_str(), contractDetails.summary.conId, contractDetails.summary.exchange.c_str(), contractDetails.tradingHours.c_str(), contractDetails.liquidHours.c_str());
                                                                                                                                                                                                                                                                                                                                                           ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::execDetails(int, const Contract&, const Execution&)’:
    ./TestCppClient.cpp:966:210: warning: format ‘%d’ expects argument of type ‘int’, but argument 7 has type ‘long int’ [-Wformat=]
      printf( "ExecDetails. ReqId: %d - %s, %s, %s - %s, %d, %d\n", reqId, contract.symbol.c_str(), contract.secType.c_str(), contract.currency.c_str(), execution.execId.c_str(), execution.orderId, execution.shares);
                                                                                                                                                                                                                      ^
    ./TestCppClient.cpp:966:210: warning: format ‘%d’ expects argument of type ‘int’, but argument 8 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::updateMktDepth(TickerId, int, int, int, double, int)’:
    ./TestCppClient.cpp:979:140: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "UpdateMarketDepth. %d - Position: %d, Operation: %d, Side: %d, Price: %g, Size: %d\n", id, position, operation, side, price, size);
                                                                                                                                                ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::updateMktDepthL2(TickerId, int, std::string, int, int, double, int)’:
    ./TestCppClient.cpp:985:142: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "UpdateMarketDepthL2. %d - Position: %d, Operation: %d, Side: %d, Price: %g, Size: %d\n", id, position, operation, side, price, size);
                                                                                                                                                  ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::historicalData(TickerId, const string&, double, double, double, double, int, int, double, int)’:
    ./TestCppClient.cpp:1009:212: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "HistoricalData. ReqId: %d - Date: %s, Open: %g, High: %g, Low: %g, Close: %g, Volume: %d, Count: %d, WAP: %g, HasGaps: %d\n", reqId, date.c_str(), open, high, low, close, volume, barCount, WAP, hasGaps);
                                                                                                                                                                                                                        ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::realtimeBar(TickerId, long int, double, double, double, double, long int, double, int)’:
    ./TestCppClient.cpp:1036:170: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "RealTimeBars. %d - Time: %l, Open: %g, High: %g, Low: %g, Close: %g, Volume: %l, Count: %d, WAP: %g\n", reqId, time, open, high, low, close, volume, count, wap);
                                                                                                                                                                              ^
    ./TestCppClient.cpp:1036:170: warning: unknown conversion type character ‘,’ in format [-Wformat=]
    ./TestCppClient.cpp:1036:170: warning: format ‘%g’ expects argument of type ‘double’, but argument 3 has type ‘long int’ [-Wformat=]
    ./TestCppClient.cpp:1036:170: warning: unknown conversion type character ‘,’ in format [-Wformat=]
    ./TestCppClient.cpp:1036:170: warning: format ‘%d’ expects argument of type ‘int’, but argument 7 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp:1036:170: warning: format ‘%g’ expects argument of type ‘double’, but argument 8 has type ‘long int’ [-Wformat=]
    ./TestCppClient.cpp:1036:170: warning: too many arguments for format [-Wformat-extra-args]
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::fundamentalData(TickerId, const string&)’:
    ./TestCppClient.cpp:1042:65: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "FundamentalData. ReqId: %d, %s\n", reqId, data.c_str());
                                                                     ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::deltaNeutralValidation(int, const UnderComp&)’:
    ./TestCppClient.cpp:1047:131: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long int’ [-Wformat=]
      printf( "DeltaNeutralValidation. %d, ConId: %d, Delta: %d, Price: %d\n", reqId, underComp.conId, underComp.delta, underComp.price);
                                                                                                                                       ^
    ./TestCppClient.cpp:1047:131: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp:1047:131: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘double’ [-Wformat=]
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::marketDataType(TickerId, int)’:
    ./TestCppClient.cpp:1058:72: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘TickerId {aka long int}’ [-Wformat=]
      printf( "MarketDataType. ReqId: %d, Type: %d\n", reqId, marketDataType);
                                                                            ^
    ./TestCppClient.cpp: In member function ‘virtual void TestCppClient::commissionReport(const CommissionReport&)’:
    ./TestCppClient.cpp:1064:177: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘double’ [-Wformat=]
      printf( "CommissionReport. %s - %d %s RPNL %d\n", commissionReport.execId.c_str(), commissionReport.commission, commissionReport.currency.c_str(), commissionReport.realizedPNL);
                                                                                                                                                                                     ^
    ./TestCppClient.cpp:1064:177: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘double’ [-Wformat=]
    In file included from ../../../source/cppclient/client/TagValue.h:8:0,
                     from ../../../source/cppclient/client/Contract.h:8,
                     from ../../../source/cppclient/client/EDecoder.h:6,
                     from ../../../source/cppclient/client/EReader.h:7,
                     from ./TestCppClient.h:10,
                     from ./TestCppClient.cpp:6:
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = PriceCondition]’:
    ./TestCppClient.cpp:601:75:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘PriceCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
        ~shared_ptr() { if (use_.only()) delete ptr_; }
                                         ^
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = OrderCondition]’:
    ./TestCppClient.cpp:601:76:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘OrderCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = ExecutionCondition]’:
    ./TestCppClient.cpp:602:78:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘ExecutionCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = MarginCondition]’:
    ./TestCppClient.cpp:603:77:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘MarginCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = PercentChangeCondition]’:
    ./TestCppClient.cpp:604:87:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘PercentChangeCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = TimeCondition]’:
    ./TestCppClient.cpp:605:73:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘TimeCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    ../../../source/cppclient/client/shared_ptr.h: In instantiation of ‘ibapi::shared_ptr<X>::~shared_ptr() [with X = VolumeCondition]’:
    ./TestCppClient.cpp:606:77:   required from here
    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘VolumeCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    In file included from ../../../source/cppclient/client/EReader.h:7:0,
                     from ./TestCppClient.h:10,
                     from ./TestCppClient.cpp:6:
    ../../../source/cppclient/client/EDecoder.h: At global scope:
    ../../../source/cppclient/client/EDecoder.h:152:20: warning: ‘std::string errMsg(std::exception)’ defined but not used [-Wunused-function]
    static std::string errMsg(std::exception e) {
                        ^
    
     
    #22     Jul 15, 2016
  3. marsman

    marsman

    Oh boy, who's doing such silly things (from the compiler warnings list above):

    if(nonGuaranteed = true){

    :)

    The IB API developers seem to have never heard of such tools like "lint" or "cppcheck"...
    CodeQualityControl = nada = zilch = zero
     
    Last edited: Jul 15, 2016
    #23     Jul 15, 2016
  4. #24     Jul 15, 2016
  5. marsman

    marsman

    Thx.
    I'm interessted in the newest IB API, ie. 9.72+.
    I think the wrapper library above does not cover the latest IB API yet, ie .the current Beta 9.72.x, but that should not surprise as the status of the IB API is still Beta.
     
    #25     Jul 15, 2016
  6. Not to be a pain but why do you feel you need 9.72 as opposed to 9.71? What new features does it bring you that you need?
     
    #26     Jul 16, 2016
  7. 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.
     
    #27     Jul 17, 2016
  8. marsman

    marsman

    Anybody have fixed this warning?

    ../../../source/cppclient/client/shared_ptr.h:66:37: warning: deleting object of polymorphic class type ‘OrderCondition’ which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
    ~shared_ptr() { if (use_.only()) delete ptr_; }
    ^

    Update:
    Ok, adding the following to OrderCondition.h fixes it:
    Code:
            virtual ~OrderCondition() {}
    
     
    Last edited: Jul 17, 2016
    #28     Jul 17, 2016
  9. marsman

    marsman

    I've written my own Makefile's: one for the library, and the other for the sample app.
    (One of course should move the original makefile's to somewhere else...)
    I'm using API 9.72.16 (ie. Beta), cf. prev postings for fixing the other issues...

    Here's my Makefile for creating a static library called 'libtwsapi.a':
    ~/IBJts/source/cppclient/client$ cat Makefile
    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 -Wno-switch -std=c++11
    
    SOURCES=$(wildcard *.cpp)
    
    TARGET=libtwsapi.a
    
    $(TARGET): $(SOURCES:.cpp=.o) Makefile
            ar cr $(TARGET) $(SOURCES:.cpp=.o)
    
    .cpp.o:
            ${CXX} ${CXXFLAGS} -c $<
    
    clean:
            rm -f $(TARGET) *.o
    
    

    And this is my Makefile for the sample application (TestCppClient):
    ~/IBJts/samples/Cpp/TestCppClient$ cat Makefile
    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 -Wno-switch -std=c++11
    
    ROOT_DIR=../../../source/cppclient
    BASE_SRC_DIR=${ROOT_DIR}/client
    INCLUDES=-I${BASE_SRC_DIR} -I${ROOT_DIR}
    
    TARGET=TestCppClient
    
    SOURCES=$(wildcard *.cpp)
    
    $(TARGET): $(SOURCES:.cpp=.o) Makefile
            $(CXX) -o $(TARGET) $(SOURCES:.cpp=.o) $(BASE_SRC_DIR)/libtwsapi.a -lpthread
    
    .cpp.o:
            ${CXX} ${CXXFLAGS} $(INCLUDES) -c $<
    
    clean:
            rm -f $(TARGET) *.o
    
    

    With these Makefile's the compilation goes much faster as only the changed file needs to be rebuilt.
     
    Last edited: Jul 17, 2016
    #29     Jul 17, 2016
  10. marsman

    marsman

    No special reason, just starting a new project... :)
     
    #30     Jul 17, 2016