import com.google.gson.JsonObject; import com.google.gson.JsonParser; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.Locale; public class EtfOwnership { public static void main(String[] args) throws Exception { // Read NVDA's file (one GET, no key), naming your own project var request = HttpRequest.newBuilder( URI.create("https://tickerinside.com/api/v1/sec/nvda.json")) .header("User-Agent", "MyProject/1.0 (+https://example.com)") .build(); var response = HttpClient.newHttpClient() .send(request, HttpResponse.BodyHandlers.ofString()); if (response.statusCode() != 200) { throw new RuntimeException("HTTP " + response.statusCode()); } // The etf_ownership block holds the figure JsonObject own = JsonParser.parseString(response.body()) .getAsJsonObject().getAsJsonObject("etf_ownership"); // pct_lower_bound is null when no figure is published, and refused // says why if (own.get("pct_lower_bound").isJsonNull()) { System.out.println("NVDA etf_ownership: no figure published, " + "refused " + own.get("refused").getAsString()); return; } System.out.println("NVDA etf_ownership: at least " + own.get("pct_lower_bound") + "% of its shares held by covered" + " US ETFs, basis " + own.get("basis").getAsString()); // The shares counted, and the date of the count of shares outstanding // %,d puts a comma every three digits System.out.println(String.format(Locale.US, "shares_held %,d shares_outstanding %,d as of %s", own.get("shares_held").getAsLong(), own.get("shares_outstanding").getAsLong(), own.get("shares_outstanding_as_of").getAsString())); // The oldest and the newest holdings file behind the figure JsonObject dates = own.getAsJsonObject("holdings_dates"); System.out.println("holdings dated " + dates.get("oldest").getAsString() + " to " + dates.get("newest").getAsString()); // The line to print under the figure System.out.println(own.get("cite_as").getAsString()); } }