#include #include #include #include // libcurl hands the body over in pieces: append each one to a string static size_t append(char* data, size_t size, size_t n, void* body) { static_cast(body)->append(data, size * n); return size * n; } int main() { // Read the list of covered funds (one GET, no key), naming your own // project std::string body; CURL* curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_URL, "https://tickerinside.com/api/v1/funds.json"); curl_easy_setopt(curl, CURLOPT_USERAGENT, "MyProject/1.0 (+https://example.com)"); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, append); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &body); CURLcode rc = curl_easy_perform(curl); curl_easy_cleanup(curl); if (rc != CURLE_OK) { std::cerr << curl_easy_strerror(rc) << "\n"; return 1; } auto doc = nlohmann::json::parse(body); // funds: read from their issuers' own files, with the date of the data std::cout << doc["count"].get() << " funds from issuer files, as_of " << doc["as_of"].get() << "\n"; // sec_funds: more US stock ETFs, from SEC filings, t and n as in funds std::cout << doc["sec_count"].get() << " more from SEC filings, listed in sec_funds\n"; // One entry per fund: t is the ticker, n the name for (auto& f : doc["funds"]) { std::cout << f["t"].get() << " " << f["n"].get() << "\n"; } }