This package provides access to the public CoinMarketCap API.
This package uses the functional options pattern to ensure that we can upgrade this package without breaking compatibility if the public API ever changes.
import (
"fmt"
"time"
"github.com/abrander/coinmarketcap"
)
func main() {
client, _ := coinmarketcap.NewClient()
globaldata, _ := client.GlobalData(
coinmarketcap.Convert("DKK"),
)
cap, _ := globaldata.MarketCap("DKK")
fmt.Printf("Global market cap in DKK: %.0f (Updated %s ago)\n",
cap,
time.Since(globaldata.LastUpdated),
)
}
import (
"fmt"
"github.com/abrander/coinmarketcap"
)
func main() {
client, _ := coinmarketcap.NewClient()
coins, _ := client.Ticker(
coinmarketcap.Limit(5),
)
for _, coin := range coins {
fmt.Printf("%04s %s 1H: %f 24H:%f 7D:%f (%s)\n",
coin.Symbol,
coin.ID,
coin.PercentChange1H,
coin.PercentChange24H,
coin.PercentChange7D,
coin.LastUpdated,
)
}
}