newo order 'timestamp' was not sent, was empty/null, or malformed.

Sending a new order always return {“code”:-1102,“msg”:“Mandatory parameter ‘timestamp’ was not sent, was empty/null, or malformed.”} from server, but the client post url:https://testnet.binancefuture.com/dapi/v1/order and post data as :symbol=BTCUSD_PERP&side=BUY&type=LIMIT&quantity=1&price=46000.000000&timeInForce=GTC&timestamp=1629961299018&signature=48eb750ddcecb681d0486e6acd197a2c208173e4e8c4ba45f26b7c09c908328b.
I do not know where is wrong, anyone can help?

Could you share a snippet of the code, or the raw curl request you are using please?

the raw curl request:
https://testnet.binancefuture.com/dapi/v1/order?symbol=BTCUSD_PERP&side=BUY&type=LIMIT&quantity=1&price=46000.000000&timeInForce=GTC&timestamp=1629969689941&signature=d0da390578209e56d02f86546d866e3939bb11b22425cae6df80e462b7e5cb31
return:
data:{“code”:-1102,“msg”:“Mandatory parameter ‘timestamp’ was not sent, was empty/null, or malformed.”}

My source code:
std::string RestPost(const char *url, const char *post_data)
{
std::string out_put;
char error[1024]{0};
struct MemoryStruct chunk;
chunk.memory = (char *)malloc(1);
chunk.size = 0;
try
{
curl_easy_reset(curl_);
std::string header_apikey = “X-MBX-APIKEY:” + apikey_;
headers_ = curl_slist_append(headers_, “Content-Type:application/json;charset=UTF-8;”);
headers_ = curl_slist_append(headers_, header_apikey.c_str());
curl_easy_setopt(curl_, CURLOPT_HTTPHEADER, headers_);

	std::string post_url = base_url_ + url; //base_url_ = https://testnet.binancefuture.com, url = /dapi/v1/order
	curl_easy_setopt(curl_, CURLOPT_CAINFO, "./cacert.pem");
	curl_easy_setopt(curl_, CURLOPT_URL, post_url.c_str());
	curl_easy_setopt(curl_, CURLOPT_ERRORBUFFER, (void *)&error);
	curl_easy_setopt(curl_, CURLOPT_POSTFIELDS, post_data); //post_data = ymbol=BTCUSD_PERP&side=BUY&type=LIMIT&quantity=1&price=46000.000000&timeInForce=GTC&timestamp=1629969689941&signature=d0da390578209e56d02f86546d866e3939bb11b22425cae6df80e462b7e5cb31
	curl_easy_setopt(curl_, CURLOPT_POSTFIELDSIZE, strlen(post_data));
	curl_easy_setopt(curl_, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
	curl_easy_setopt(curl_, CURLOPT_WRITEDATA, (void *)&chunk);
	auto res = curl_easy_perform(curl_);
	if (res != CURLE_OK)
	{
		SPDLOG_WARN("post curl_easy_perform failed: {}", curl_easy_strerror(res));
	}
	else
	{
		out_put = std::string(chunk.memory, chunk.size);
		SPDLOG_DEBUG("RestPost {} bytes retrieved, data:{}", (unsigned long)chunk.size,
					 chunk.memory);
	}
}
catch (exception &e)
{
	cout << "RestPost exception :" << e.what() << endl;
	SPDLOG_ERROR("RestPost exception :{}", e.what());
}
free(chunk.memory);
return out_put;

}

Seems like you are setting the incorrect content type.

headers_ = curl_slist_append(headers_, “Content-Type:application/json;charset=UTF-8;”);

to

headers_ = curl_slist_append(headers_, “Content-Type:application/x-www-form-urlencoded;charset=UTF-8;”);

More info here https://binance-docs.github.io/apidocs/spot/en/#general-api-information

1 Like

Thanks, that’s the problem. It’s been solved.