ByBit Api.打开有效订单。返回"empty param of timestamp" .Libcurl c++



请帮忙!!!!是否有在c++

中打开订单的工作示例?不断发送打开订单的请求POST https://api.bybit.com/private/linear/order/create

{"api_key":"WTVpIZqOwx2LGYY3TB","order_type":"Market","qty":5,"side":"Buy","symbol":"MATICUSDT","time_in_force":"GoodTillCancel","timestamp":1652444871610,"sign":"433b79f452a6c43f3b507df4b5cee84314c7aae584546a889cde7d750ac2f4a6"}

我得到一个错误

{"ret_code":10001,"ret_msg":"empty param of timestamp","ext_code":"","ext_info":"","result":null,"time_now":"1652444872.324646"

没有人能解释为什么

代码本身

int main(int, char **)
{
CURL *curl;
CURLcode res;
unsigned long long timestamp = chrono::duration_cast<chrono::milliseconds>(chrono::_V2::system_clock::now().time_since_epoch()).count();
string api_key = "WT***************3TB";
string secret_key = "Ik**************4vE";
string reqParam = "api_key=" + api_key + "&order_type=Market&qty=5&side=Buy&symbol=MATICUSDT&time_in_force=GoodTillCancel&timestamp=" + to_string(timestamp);
string sign = hmacEncode(reqParam, secret_key);
string json = "{"api_key":"" + api_key + "","side"="Buy","symbol"="MATICUSDT","order_type":"Market","qty":2,"time_in_force":"GoodTillCancel","timestamp":" + to_string(timestamp) + " ,"sign":"" + sign + ""}";
cout << json << endl;
curl = curl_easy_init();
if (curl)
{
// set params
curl_easy_setopt(curl, CURLOPT_POST, 1);          // post req
curl_easy_setopt(curl, CURLOPT_URL, "https://api.bybit.com/private/linear/order/create"); // url
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json.c_str());
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
// Header "Content-Type: application/json"
struct curl_slist *headers = NULL;
curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %sn",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}

https://github.com/alex290/bybitorder-api/blob/master/src/main.cpp

一切都解决了问题。下面是工作代码

int main(int, char **)
{
CURL *curl;
CURLcode res;
unsigned long long timestamp = chrono::duration_cast<chrono::milliseconds>(chrono::_V2::system_clock::now().time_since_epoch()).count();
string api_key = "WT***************3TB";
string secret_key = "Ik**************4vE";
string reqParam = "api_key=" + api_key + "&close_on_trigger=false&order_type=Market&position_idx=0&qty=5&reduce_only=false&side=Buy&symbol=MATICUSDT&time_in_force=GoodTillCancel&timestamp=" + to_string(timestamp);

string sign = hmacEncode(reqParam, secret_key);
reqParam = reqParam + "&sign=" + sign;

string urlStr = "https://api.bybit.com/private/linear/order/create?" + reqParam;
cout << urlStr << endl;
curl = curl_easy_init();
if (curl)
{
// set params
curl_easy_setopt(curl, CURLOPT_POST, 1);             // post req
curl_easy_setopt(curl, CURLOPT_URL, urlStr.c_str()); // url
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
// Header "Content-Type: application/json"
struct curl_slist *headers = NULL;
curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %sn",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}

我看到了一些奇怪的东西。代码中的错误JSON:

""side"="Buy","symbol"="MATICUSDT"

与转储后的JSON不一致

"side":"Buy","symbol":"MATICUSDT".

你的代码在时间戳后面有空格,转储的JSON没有空格。参数顺序不同

最新更新