null account balances


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;

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(“”));

const auto timestamp = std::chrono::duration_caststd::chrono::milliseconds(

http_request request(methods::GET);
request.headers().add(“X-MBX-APIKEY”, api_key);

web::http::uri_builder blder(request.request_uri());
blder.append_query(U(“timestamp”), utility::conversions::to_utf8string(std::to_string(timestamp)));


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;
return 0;


BTW I can use ANY library here. Ive no particular attachment to cpprest. Also, I have ssl version 3.0 installed. Also, the hmac_sha256 returns a signature ok

Ignore this question… I switched over to libCURL C++ and it worked first time. Wont be going near cpprest at all!