#include #include #include #include // A whole number with a comma every three digits static std::string grouped(long long n) { std::string s = std::to_string(n); for (int i = static_cast(s.size()) - 3; i > 0; i -= 3) { s.insert(static_cast(i), ","); } return s; } // 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 NVDA's file (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/sec/nvda.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; } // The etf_ownership block holds the figure auto own = nlohmann::json::parse(body)["etf_ownership"]; // pct_lower_bound is null when no figure is published, and refused says // why if (own["pct_lower_bound"].is_null()) { std::cout << "NVDA etf_ownership: no figure published, refused " << own["refused"].get() << "\n"; return 0; } std::cout << "NVDA etf_ownership: at least " << own["pct_lower_bound"].get() << "% of its shares held by covered US ETFs, basis " << own["basis"].get() << "\n"; // The shares counted, and the date of the count of shares outstanding std::cout << "shares_held " << grouped(own["shares_held"].get()) << " shares_outstanding " << grouped(own["shares_outstanding"].get()) << " as of " << own["shares_outstanding_as_of"].get() << "\n"; // The oldest and the newest holdings file behind the figure auto& dates = own["holdings_dates"]; std::cout << "holdings dated " << dates["oldest"].get() << " to " << dates["newest"].get() << "\n"; // The line to print under the figure std::cout << own["cite_as"].get() << "\n"; }