Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/abrander/coinmarketcap

Go bindings for the coinmarketcap API
https://github.com/abrander/coinmarketcap

bitcoin-price coinmarketcap coinmarketcap-api ethereum-price golang golang-package

Last synced: about 1 month ago
JSON representation

Go bindings for the coinmarketcap API

Awesome Lists containing this project

README

        

# `import "github.com/abrander/coinmarketcap"`

This package provides access to the public [CoinMarketCap](https://coinmarketcap.com/) [API](https://coinmarketcap.com/api/).

[![GoDoc][1]][2]
[![Travis][3]][4]
[![Coverage][5]][6]

[1]: https://godoc.org/github.com/abrander/coinmarketcap?status.svg
[2]: https://godoc.org/github.com/abrander/coinmarketcap

[3]: https://travis-ci.org/abrander/coinmarketcap.svg?branch=master
[4]: https://travis-ci.org/abrander/coinmarketcap

[5]: https://coveralls.io/repos/github/abrander/coinmarketcap/badge.svg?branch=master
[6]: https://coveralls.io/github/abrander/coinmarketcap?branch=master

## Overview

This package uses the [functional options pattern](https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis)
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

```golang
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

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