Skip to content

Instantly share code, notes, and snippets.

@fguisso
Created October 15, 2019 00:25
Show Gist options
  • Save fguisso/32dbccdffbef221c5f0df0d3d88d377d to your computer and use it in GitHub Desktop.
Save fguisso/32dbccdffbef221c5f0df0d3d88d377d to your computer and use it in GitHub Desktop.
get dcrdata info
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"time"
)
type Dcrdata struct {
BtcIndex string `json: "btc_index"`
BtcFiatPrice float64 `json: "btc_fiat_price"`
Price float64 `json: "price"`
Volume float64 `json: "volume"`
}
const (
url_base = "https://dcrdata.decred.org/api/exchanges"
)
func main() {
client := http.Client{
Timeout: time.Minute,
}
resp, err := client.Get(url_base)
if err != nil {
log.Fatalln(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
var dd = new(Dcrdata)
err = json.Unmarshal(body, &dd)
if err != nil {
log.Fatalln(err)
}
log.Println(dd)
log.Printf("%v, %T", dd.BtcIndex, dd.BtcIndex)
log.Printf("%v, %T", dd.BtcFiatPrice, dd.BtcFiatPrice)
log.Printf("%v, %T", dd.Price, dd.Price)
log.Printf("%v, %T", dd.Volume, dd.Volume)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment