Skip to content

Go bindings for the coinmarketcap API

License

Notifications You must be signed in to change notification settings

abrander/coinmarketcap

Repository files navigation

import "github.com/abrander/coinmarketcap"

This package provides access to the public CoinMarketCap API.

GoDoc Travis Coverage

Overview

This package uses the functional options pattern to ensure that we can upgrade this package without breaking compatibility if the public API ever changes.

Examples

Printing the global market cap in danish kroner

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),
	)
}

Get the top five changes

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,
		)
	}
}