Interactive Brokers API C ++控制台非常基本的东西

时间:2017-05-07 10:05:59

标签: c++ api interactive-brokers

IB API C ++主题有几个答案,但我无法识别所需的答案。 我正在努力通过控制台通过C ++ API连接到TWS。我不需要任何界面,只需要在最简单的级别上进行链接。

我正在尝试以下代码:

#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;
}

我编译的错误:

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

我很欣赏这个非常基本的建议。

PS

我知道C ++ API有两个非常流行的用户开发选项:

https://github.com/rudimeier/twsapi

https://github.com/JanBoonen/TwsApiCpp

但他们也不会在我的Win机器上飞行。

2 个答案:

答案 0 :(得分:1)

似乎有一个复杂的故事:
1最好是获得最新版本的API(严肃地说,从昨天开始) 2尽管可能会对IBString.h进行手动更正以删除与MS相关的声明,但最好在VS IDE中对其进行编译 3您无法在2015 VS工具集下编译它,请改用2012 4你不能只是简单地把它写成几个对象实例化。如果你从原始的IB文件中删除了你不需要的东西,那就更好了 @dmaelect感谢您的贡献。

答案 1 :(得分:1)

公平对待IB API C ++产品 我已经下载并尝试了MacOS版本的C ++ API。这是CLION IDE。 API就像瑞士手表一样 - 准确,安静,精确。我已经解决了我在5分钟内建立联系的问题,接下来的5分钟我用于获取合同细节和市场数据。
我的结论 - 避免VS和MS特定的IB API。