Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
add altcoin markets graph data
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Mar 27, 2018
1 parent ef3b2cc commit 4be870a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
27 changes: 22 additions & 5 deletions coinmarketcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import (
)

var (
baseURL = "https://api.coinmarketcap.com/v1"
graphURL = "https://graphs2.coinmarketcap.com/currencies"
marketGraphURL = "https://graphs2.coinmarketcap.com/global/marketcap-total"
baseURL = "https://api.coinmarketcap.com/v1"
coinGraphURL = "https://graphs2.coinmarketcap.com/currencies"
globalMarketGraphURL = "https://graphs2.coinmarketcap.com/global/marketcap-total"
altcoinMarketGraphURL = "https://graphs2.coinmarketcap.com/global/marketcap-altcoin"
)

// GetMarketData get information about the global market data of the cryptocurrencies
Expand All @@ -35,7 +36,23 @@ func GetMarketData() (GlobalMarketData, error) {

// GetMarketGraphData get graph data points of global market
func GetMarketGraphData(start int64, end int64) (MarketGraph, error) {
url := fmt.Sprintf("%s/%d/%d", marketGraphURL, start*1000, end*1000)
url := fmt.Sprintf("%s/%d/%d", globalMarketGraphURL, start*1000, end*1000)
resp, err := makeReq(url)
if err != nil {
return MarketGraph{}, err
}
var data MarketGraph
err = json.Unmarshal(resp, &data)
if err != nil {
return MarketGraph{}, err
}

return data, nil
}

// GetAltcoinMarketGraphData get graph data points of altcoin market
func GetAltcoinMarketGraphData(start int64, end int64) (MarketGraph, error) {
url := fmt.Sprintf("%s/%d/%d", altcoinMarketGraphURL, start*1000, end*1000)
resp, err := makeReq(url)
if err != nil {
return MarketGraph{}, err
Expand Down Expand Up @@ -92,7 +109,7 @@ func GetAllCoinData(limit int) (map[string]Coin, error) {

// GetCoinGraphData get graph data points for a crypto currency
func GetCoinGraphData(coin string, start int64, end int64) (CoinGraph, error) {
url := fmt.Sprintf("%s/%s/%d/%d", graphURL, coin, start*1000, end*1000)
url := fmt.Sprintf("%s/%s/%d/%d", coinGraphURL, coin, start*1000, end*1000)
resp, err := makeReq(url)
if err != nil {
return CoinGraph{}, err
Expand Down
19 changes: 19 additions & 0 deletions coinmarketcap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,25 @@ func TestGetMarketGraphData(t *testing.T) {
}
}

func TestGetAltcoinMarketGraphData(t *testing.T) {
var threeMonths int64 = (60 * 60 * 24 * 90)
end := time.Now().Unix()
start := end - threeMonths

graph, err := GetAltcoinMarketGraphData(start, end)
if err != nil {
t.FailNow()
}

if graph.MarketCapByAvailableSupply[0][0] == 0 {
t.FailNow()
}

if graph.VolumeUSD[0][0] == 0 {
t.FailNow()
}
}

func TestGetCoinData(t *testing.T) {
coin, err := GetCoinData("ethereum")
if err != nil {
Expand Down

0 comments on commit 4be870a

Please sign in to comment.