IB API C++主題有幾個答案,但我一直無法確定需要的答案。 我很努力通過控制檯通過C++ API連接到TWS。我不需要界面,只是爲了在最簡單的層面上進行關聯。Interactive Brokers API C++控制檯非常基本的東西
我想下面的代碼:
#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
但他們並沒有支付給我的機器上飛作爲好。
*「IB API C++主題」*這是什麼?你在說什麼?這個問題需要上下文。我知道一個API是什麼,但它對你使用它的方式沒有意義。我不知道什麼是IB。 –
@Cody Gray除了「IB API」之外,還有一個「TWS」,對您而言可能同樣陌生。 IB代表盈透證券,TWS表示交易者工作站。 –
您使用的是什麼IDE和操作系統? – dmaelect