Hi,
Thanks for all the help I’m getting here. This is driving me nuts;
I have written a main.cxx to get my account balances at runtime using API. I’m using cpprest but will use any library at all. The problem is that I’m always seeing “Response null” returned (4th last line). Everything runs ok. The keys/secret I pass at command line are correct. The hmac_sha256 function returns a signature ok.
Can anybody see why this is broken/returning null? Sorry for the bother.
std::string hmac_sha256(const std::string& key, const std::string& data);
int main(int argc, char** argv)
{
if (argc != 3)
{
std::cerr << “Please provide API_Key and Secret as command line arguments” << std::endl;
exit(1);
}
const std::string api_key (argv[1]);
const std::string api_secret (argv[2]);
std::cout << "API_KEY: " << api_key << std::endl;
std::cout << "SECRET: " << api_secret << std::endl;
const uri_builder builder(U(“https://api.binance.com/api/v3/account”));
const auto timestamp = std::chrono::duration_caststd::chrono::milliseconds(
std::chrono::system_clock::now().time_since_epoch()).count();
http_request request(methods::GET);
request.headers().set_content_type(“application/x-www-form-urlencoded”);
request.headers().add(“X-MBX-APIKEY”, api_key);
request.set_request_uri(builder.to_uri());
web::http::uri_builder blder(request.request_uri());
blder.append_query(U(“timestamp”), utility::conversions::to_utf8string(std::to_string(timestamp)));
request.set_request_uri(blder.to_uri());
std::string signature_data = request.to_string();
signature_data.erase(signature_data.find("timestamp="), 10);
std::string signature = hmac_sha256(signature_data, api_secret);
request.headers().add(U(“signature”), signature);
http_client client(builder.to_uri());
client.request(request).then((http_response response) {
if (response.status_code() == status_codes::OK) {
return response.extract_json();
}
return pplx::task_from_result(json::value());
}).then((json::value jsonResponse) {
std::cout << "Response: " <<
utility::conversions::to_string_t(jsonResponse.serialize()) << std::endl;
}).wait();
return 0;
}
Graham