该问题是由于API请求中timestamp参数为空导致的。可以通过使用Libcurl c++的代码示例来解决如下:
#include
#include
#include
#include
std::string bybitApiSignature(const std::string& secret, const std::string& verb, const std::string& url, const int64_t& expires, const std::string& body) {
std::stringstream prehash;
prehash << verb << url << expires << body;
const std::string message = prehash.str();
std::vector result(HMAC_SHA256_DIGEST_LENGTH);
HMAC_SHA256(result.data(), secret.c_str(), secret.size(), message.c_str(), message.size());
return base64_encode(result.data(), result.size());
}
int main() {
CURL* curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
std::string verb = "GET";
std::string endpoint = "/open-api/order/list";
std::string params = "limit=10&order_status=New";
const int64_t expires = get_current_timestamp() + 10;
const std::string body = "";
std::stringstream ss;
ss << "https://api.bybit.com" << endpoint << "?api_key=" << apikey << "&" << params
<< "×tamp=" << expires << "&sign=" << bybitApiSignature(secret, verb, endpoint, expires, body);
std::string url = ss.str();
if (curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return 0;
}
其中,需要注意对timestamp参数进行正确的传递。