Skip to content

Latest commit

 

History

History
79 lines (57 loc) · 1.69 KB

README.md

File metadata and controls

79 lines (57 loc) · 1.69 KB

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