Skip to content

Commit

Permalink
chore: add header to coin gecko market cap call #43
Browse files Browse the repository at this point in the history
  • Loading branch information
robcxyz committed Nov 10, 2023
1 parent a25f653 commit daca180
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/api/rest/stats_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,21 @@ func UpdateCirculatingSupply() {
var MarketCap float64

func GetMarketCap() (float64, error) {
resp, err := http.Get("https://api.coingecko.com/api/v3/coins/icon")
req, err := http.NewRequest("GET", "https://api.coingecko.com/api/v3/coins/icon", nil)
if err != nil {
return 0.0, err
}
//coingecko is blocking requests without a user agent so spoofing here
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3")

// Send the request using http.Client
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return 0.0, err
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return 0.0, err
Expand Down

0 comments on commit daca180

Please sign in to comment.