【发布时间】:2021-01-14 19:12:26
【问题描述】:
在我的一生中,我无法让它发挥作用。我无法找到 Bittrex API v3 的示例代码,所以我将我在其他编程语言中找到的 v1.1 和 v3 的代码拼凑在一起。
我正在使用 curl 和 openssl 库。
我收到“URL 使用错误/非法格式或缺少 URL”错误。
#include "../curl/curl.h"
#include <sha512.hh>
#include "hmac.h"
#include "sha.h"
string bittKey, bittSecret;
string timeStamp, hTTPMethod, uRI, requestBody, contentHash;
CURL *curl;
CURLcode res;
curl = curl_easy_init();
bittKey = "...";
bittSecret = "...";
timeStamp = std::to_string(time(nullptr));
uRI = "https://api.bittrex.com/v3/balances";
hTTPMethod = "GET";
requestBody = "";
contentHash = sw::sha512::calculate(requestBody);
string preSign = timeStamp + uRI + hTTPMethod + contentHash;
string apiSign = hmac_sha512(preSign, bittSecret);
struct curl_slist* headerList = NULL;
headerList = curl_slist_append(headerList, "Accept: application/json");
headerList = curl_slist_append(headerList, "Content-Type: application/json");
headerList = curl_slist_append(headerList, ("Api-Key: " + bittKey).c_str());
headerList = curl_slist_append(headerList, ("Api - Signature: " + apiSign).c_str());
headerList = curl_slist_append(headerList, ("Api-Timestamp: " + timeStamp).c_str());
headerList = curl_slist_append(headerList, ("Api-Content-Hash: " + contentHash).c_str());
curl_easy_setopt(curl, CURLOPT_URL, uRI);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerList);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
curl_slist_free_all(headerList);
curl_easy_cleanup(curl);
【问题讨论】: