0

IB API C++ topic has several answers, but I haven't been able to identify the needed one. I am struggling to get connected to TWS through C++ API via console. I need no interface, just to get linked on the simplest level.

I am trying the following code:

#include "EWrapper.h"
#include "EClientSocket.h"
#include "textbook_classes_.h" 
//in textbook_classes_.h/.cpp I have EWrapper inheritance with 
//required funcs overriding, 
//those I keep empty (ie:
// void test_EWrapper::tickPrice( TickerId tickerId, TickType field, 
// double price, int canAutoExecute) {}


int main()
{
 IB::test_EWrapper client;
 IB::test_EWrapper* ptr_client = new IB::test_EWrapper(client);

 EClientSocket test_socket(ptr_client);

 test_socket.eConnect( "", 7497, 0, false); //my port is 7497

 delete ptr_client;
 ptr_client = nullptr;

 return 0;
}

The errors I got compiling:

CMakeFiles\tws_san_.dir/objects.a(main.cpp.obj): In function `main':
C:/Users/solovyev.an/Documents/Cpp/tws_san_/main.cpp:15: undefined 
reference to `EClientSocket::EClientSocket(EWrapper*)'
C:/Users/solovyev.an/Documents/Cpp/tws_san_/main.cpp:17: undefined 
reference to `EClientSocket::eConnect(char const*, unsigned int, int, bool)'
C:/Users/solovyev.an/Documents/Cpp/tws_san_/main.cpp:15: undefined 
reference to `EClientSocket::~EClientSocket()'
C:/Users/solovyev.an/Documents/Cpp/tws_san_/main.cpp:15: undefined 
reference to `EClientSocket::~EClientSocket()'
CMakeFiles\tws_san_.dir/objects.a(textbook_classes_.cpp.obj): 
In function `ZN2IB13test_EWrapperC2Ev':
C:/Users/solovyev.an/Documents/Cpp/tws_san_/textbook_classes_.cpp:26:
undefined reference to `EClientSocket::EClientSocket(EWrapper*)'
collect2.exe: error: ld returned 1 exit status

CMakeFiles\tws_san_.dir\build.make:123: recipe for target 'tws_san_.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/tws_san_.dir/all' failed
mingw32-make.exe[3]: *** [tws_san_.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/tws_san_.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/tws_san_.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/tws_san_.dir/rule' failed
Makefile:117: recipe for target 'tws_san_' failed
mingw32-make.exe: *** [tws_san_] Error 2

I appreciate an advise on this very basic thing.

PS

I know there are two quite popular user-developed options for C++ API:

https://github.com/rudimeier/twsapi

https://github.com/JanBoonen/TwsApiCpp

But they don't fly on my Win-machine as well.

  • *"IB API C++ topic"* What is this? What are you talking about? This question needs context. I know what an API is, but it doesn't make sense with the way you're using it. I have no idea what IB is. – Cody Gray - on strike May 07 '17 at 10:20
  • @Cody Gray Besides "IB API" there is also a "TWS", that may be equally unfamiliar to you. IB means Interactive Brokers, TWS means Trader Work Station. – Andrey Soloviev May 07 '17 at 17:11
  • What IDE and OS are you using? – dmaelect May 08 '17 at 00:55
  • @dmaelect CLion + Win7 – Andrey Soloviev May 08 '17 at 05:30
  • @AndreySoloviev, With all of the "undefined" errors, it looks like you do not have header files included or the path to the headers needs to be added to your project. I had to copy the .lib file and the .dll to my projects executable folder and add the .h and .cpp files to my projects include path to get rid of all my undefined errors at compile time. you probably already have this link but here it is anyway. https://www.interactivebrokers.com/en/software/api/api.htm. I am afraid I won't be much help beyond this. Let me know if you get it working. – dmaelect May 08 '17 at 19:02

2 Answers2

2

It seems that there is a complex story:
1 It is better to get the latest version of API (seriously, take it from yesterday).
2 It is better to compile that in VS IDE, despite of potential manual correction of IBString.h to remove MS related declarations.
3 You can't compile it under 2015 VS toolset, use 2012 instead.
4 You can't just make it so simple as writing from scratch a couple of objects instantiates. It is better if you cut off from original IB file what you don't need.
@dmaelect thank you for your contribution.

1

Just to be fair with IB API C++ product.
I have downloaded and tried MacOS version of C++ API. It was CLion IDE. API works like Swiss watch - accurately, quietly, precisely. I've solved my issue of getting connected within 5 mins, next 5 mins I spent on getting contract details and market data.
My conclusion - avoid VS and MS-specific IB API.