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.

4

2 回答 2

1

只是为了公平对待 IB API C++ 产品。
我已经下载并试用了 MacOS 版本的 C++ API。这是 CLion IDE。API 像瑞士手表一样工作——准确、安静、精确。我已经在 5 分钟内解决了连接问题,接下来的 5 分钟用于获取合同详细信息和市场数据。
我的结论 - 避免使用 VS 和特定于 MS 的 IB API。

于 2017-05-12T20:57:48.893 回答
1

似乎有一个复杂的故事:
1 最好获得最新版本的API(说真的,从昨天开始)。
2 最好在 VS IDE 中编译它,尽管可能需要手动更正 IBString.h 以删除 MS 相关声明。
3 2015 VS工具集下无法编译,改用2012。
4 你不能让它像从头开始编写几个对象实例那样简单。如果您从原始 IB 文件中删除您不需要的内容会更好。
@dmaelect 感谢您的贡献。

于 2017-05-10T17:18:02.047 回答