forked from Syntax-Error/TradeSim
51 lines
No EOL
1.5 KiB
C++
51 lines
No EOL
1.5 KiB
C++
#include <iostream>
|
|
#include <curl/curl.h>
|
|
#include <json/json.h>
|
|
|
|
size_t writefunc(void *ptr, size_t size, size_t nmemb, std::string *s)
|
|
{
|
|
s->append(static_cast<char *>(ptr), size*nmemb);
|
|
return size*nmemb;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
CURL *curl;
|
|
CURLcode res;
|
|
|
|
curl = curl_easy_init();
|
|
if(curl) {
|
|
std::string s;
|
|
curl_easy_setopt(curl, CURLOPT_URL, "https://api3.binance.com/api/v3/trades?symbol=ETHEUR&limit=10");
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
|
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
|
|
/* 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: %s\n",
|
|
curl_easy_strerror(res));
|
|
Json::Value root;
|
|
JSONCPP_STRING err;
|
|
Json::CharReaderBuilder builder;
|
|
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
|
|
if (!reader->parse(s.c_str(), s.c_str() + s.length(), &root,
|
|
&err)) {
|
|
std::cout << "error" << std::endl;
|
|
return EXIT_FAILURE;
|
|
}
|
|
std::cout << root[0]["price"].asString() << std::endl;
|
|
/* always cleanup */
|
|
curl_easy_cleanup(curl);
|
|
}
|
|
return 0;
|
|
} |