[英]Alpaca Traders API Unable to Connect with httplib
I am attempting to use the C++ wrapper for the Alpaca Traders API for the found here:我正在尝试为 Alpaca Traders API 使用 C++ 包装器,以便在此处找到:
https://github.com/marpaia/alpaca-trade-api-cpp#client-instantiation https://github.com/marpaia/alpaca-trade-api-cpp#client-instantiation
However, I'm having trouble even connecting to my paper trading account.但是,我什至无法连接到我的模拟交易账户。
Here is the code from the wrapper for getting the Alpaca account:以下是获取 Alpaca 帐户的包装器代码:
httplib::Headers headers(const Environment& environment) {
return {
{"APCA-API-KEY-ID", environment.getAPIKeyID()},
{"APCA-API-SECRET-KEY", environment.getAPISecretKey()},
};
}
std::pair<Status, Account> Client::getAccount() const {
Account account;
httplib::SSLClient client(environment_.getAPIBaseURL());
auto resp = client.Get("/v2/account", headers(environment_));
if (!resp) {
return std::make_pair(Status(1, "Call to /v2/account returned an empty response"), account);
}
}
The problem is that I get an error back that it's unable to connect:问题是我收到一个无法连接的错误:
Error: resp.error(): Connection (2)
I've checked the environment, and it's been parsed correctly, I even tried the following curl command, and it was able to get the http page.我检查了环境,解析正确,我什至尝试了下面的 curl 命令,它能够得到 http 页面。
curl -X GET -H "APCA-API-KEY-ID: {YOUR_API_KEY_ID}"
-H "APCA-API-SECRET-KEY: {YOUR_API_SECRET_KEY}"
https://paper-api.alpaca.markets/v2/account
So my machine can find, and get the page, thus it must be something in the code that is wrong.所以我的机器可以找到并获取页面,因此它一定是代码中的某些错误。 Any help would be appreciated.
任何帮助,将不胜感激。
I found the problem.我发现了问题。 After looking over the documentation on the cpp-httplib github , the SSLClient doesn't have the
https://
at the beginning of the URL, and me having that in there was causing the problem.查看cpp-httplib github上的文档后,SSLClient 在 URL 的开头没有
https://
并导致我出现问题。
So you want:所以你要:
httplib::SSLClient client("paper-api.alpaca.markets");
and not:并不是:
httplib::SSLClient client("https://paper-api.alpaca.markets");
The second one will not connect.第二个连接不上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.