package main import ( "encoding/json" "fmt" "log" "net/http" "strconv" "time" ) // grouped writes a whole number with a comma every three digits func grouped(n int64) string { s := strconv.FormatInt(n, 10) for i := len(s) - 3; i > 0; i -= 3 { s = s[:i] + "," + s[i:] } return s } func main() { // Read NVDA's file (one GET, no key), naming your own project req, err := http.NewRequest("GET", "https://tickerinside.com/api/v1/sec/nvda.json", nil) if err != nil { log.Fatal(err) } req.Header.Set("User-Agent", "MyProject/1.0 (+https://example.com)") client := &http.Client{Timeout: 30 * time.Second} resp, err := client.Do(req) if err != nil { log.Fatal(err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { log.Fatalf("HTTP %d", resp.StatusCode) } // The etf_ownership block holds the figure; decode the fields used here var stock struct { Own struct { PctLowerBound *float64 `json:"pct_lower_bound"` Refused string `json:"refused"` Basis string `json:"basis"` SharesHeld int64 `json:"shares_held"` SharesOutstanding int64 `json:"shares_outstanding"` SharesOutstandingAsOf string `json:"shares_outstanding_as_of"` HoldingsDates struct { Oldest string `json:"oldest"` Newest string `json:"newest"` } `json:"holdings_dates"` CiteAs string `json:"cite_as"` } `json:"etf_ownership"` } if err := json.NewDecoder(resp.Body).Decode(&stock); err != nil { log.Fatal(err) } own := stock.Own // pct_lower_bound is null when no figure is published, and refused says // why if own.PctLowerBound == nil { fmt.Println("NVDA etf_ownership: no figure published, refused", own.Refused) return } fmt.Printf("NVDA etf_ownership: at least %v%% of its shares held by "+ "covered US ETFs, basis %s\n", *own.PctLowerBound, own.Basis) // The shares counted, and the date of the count of shares outstanding fmt.Println("shares_held", grouped(own.SharesHeld), "shares_outstanding", grouped(own.SharesOutstanding), "as of", own.SharesOutstandingAsOf) // The oldest and the newest holdings file behind the figure fmt.Println("holdings dated", own.HoldingsDates.Oldest, "to", own.HoldingsDates.Newest) // The line to print under the figure fmt.Println(own.CiteAs) }