cryptocurrencydata

package module
v0.0.0-...-8bceaf1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2018 License: MIT Imports: 8 Imported by: 0

README

Cryptocurrencydata

Build Status GoDoc Go Report Card

Provides a golang library to receive current and historic data from coinmarketcap's API.

Please note that there limitations in how many request you can do to their API. Please find details here: https://coinmarketcap.com/api/

THIS IS A LIBRARY, NOT YOUR WISHING SOLUTION TO MAKE YOU RICH ALTHROUGHT IT MAY HELPS YOU TO GET THERE! if you do become rich, please send me all your wins ;)

Why?

This library is created out of interest in playing with cryptocurrencies and go (lang). As of writing test and playgrounds for wallets, bots and advisories I thought this might be useful to share. I do not consider this library as perfect, conclusive or even pretty but it works awesome. If you have suggestions, comments or improvements or even start using it, please let me know :)

Install
go get -u github.com/skycube/cryptocurrencydata
Basic Usage

The below will show a basic usage of some of the available methods. All examples can be found in: Basic examples can be found here:

examples/examples.go

Get Value in USD for "bitcoin,ethereum,skycoin" currencies
d, err := cryptocurrencydata.PriceUSDByIDs([]string{"bitcoin", "ethereum", "skycoin"})
if err != nil {
    fmt.Printf("%v", err)
}
fmt.Println("# PriceUSDByIDs")
for _, v := range d {
    fmt.Printf("%-10s \t $%.2f\n", v.ID, v.Value)
}

Output:

# GetPriceUSDByCurrencyIDs
bitcoin    	 $10638.00
ethereum   	 $787.79
skycoin    	 $14.02
Multiple currencies values change last 1 hour
d, err := cryptocurrencydata.GetPercentChange1HByCurrencyIDs([]string{"bitcoin", "ethereum", "skycoin"})
if err != nil {
    fmt.Printf("%v", err)
}
fmt.Println("# GetPercentChange1HByCurrencyIDs")
for _, v := range d {
    fmt.Printf("%-10s \t %.2f\n", v.ID, v.Value)
}

Output:

# GetPercentChange1HByCurrencyIDs
bitcoin    	 0.55
ethereum   	 0.31
skycoin    	 2.50
Get full currencies data details by currency ids
d, err := cryptocurrencydata.GetCurrencyDataByIDs([]string{"bitcoin", "ethereum", "skycoin"})
if err != nil {
    fmt.Printf("%v", err)
}
fmt.Println("# GetCurrencyDataByIDs")
for _, v := range d {
    fmt.Printf("%v\n", v)
}

Output:

# GetCurrencyDataByCurrencyIDs
&{bitcoin Bitcoin BTC 1 10638 1 6.91178e+09 1.79837645256e+11 1.6905212e+07 1.6905212e+07 2.1e+07 0.55 -3.61 -0.32 2018-03-07 11:39:26 +0000 UTC}
&{ethereum Ethereum ETH 2 787.794 0.074382 1.86455e+09 7.7233590834e+10 9.80378e+07 9.80378e+07 0 0.31 -5.76 -9.69 2018-03-07 11:39:12 +0000 UTC}
&{skycoin Skycoin SKY 120 14.0169 0.00132345 552055 1.07331524e+08 7.657294e+06 2.5e+07 1e+08 2.5 -5.5 -16.3 2018-03-07 11:39:10 +0000 UTC}
Get single currency history
d, err := cryptocurrencydata.GetCurrencyHistoryByCurrencyID("skycoin")
if err != nil {
    fmt.Printf("%v", err)
}
fmt.Println("# GetCurrencyHistoryByCurrencyID")
for _, v := range d {
    fmt.Printf("timestamp %v timeUTC: %v MarketSupply: %d PriceUSD: $%.2f PriceBTC: $%.2f VolUSD: $%d\n", v.Timestamp, v.TimeUTC, v.MarketSupply, v.PriceUSD, v.PriceBTC, v.VolUSD)
}

Output:

# GetCurrencyHistoryByCurrencyID
timestamp 1519029250000 timeUTC: 2018-02-19 08:34:10 +0000 UTC MarketSupply: 147280561 PriceUSD: $19.76 PriceBTC: $0.00 VolUSD: $670990
timestamp 1496298589000 timeUTC: 2017-06-01 06:29:49 +0000 UTC MarketSupply: 8866853 PriceUSD: $1.63 PriceBTC: $0.00 VolUSD: $73770
timestamp 1507642758000 timeUTC: 2017-10-10 13:39:18 +0000 UTC MarketSupply: 17325056 PriceUSD: $2.92 PriceBTC: $0.00 VolUSD: $9757
timestamp 1509521956000 timeUTC: 2017-11-01 07:39:16 +0000 UTC MarketSupply: 24330265 PriceUSD: $4.10 PriceBTC: $0.00 VolUSD: $33590
timestamp 1509845958000 timeUTC: 2017-11-05 01:39:18 +0000 UTC MarketSupply: 24284342 PriceUSD: $4.09 PriceBTC: $0.00 VolUSD: $13874
timestamp 1513735163000 timeUTC: 2017-12-20 01:59:23 +0000 UTC MarketSupply: 107126489 PriceUSD: $16.92 PriceBTC: $0.00 VolUSD: $320845
...

Todo

  • Optional parameters
  • Code documentation (yes I know...)
  • SpelLChaeck
  • tests
Things may going to happen
  • Do things better, prettier, writing GO is always learning and improving
  • Additional data feeds
  • Configuration/ pass in URLs (i.e. override incoming with proxy)
Things not going to happen
  • Trotteling number of requests (as remote API limits the number of request; 10 per minute)
  • Single currency lookups, can't find a use case for this
  • Store (local) to prevent duplicate lookups
  • Support more than one thread at a time
  • Proxy responses internaly (~maybe)
  • Logging
  • Abstractions (this is not chinese JAVA University project)
Contribute

Please see CONTRIBUTE.md

Thanks

Thanks to everyone reading this, using this and specialy to those who helped me along :) Be kind, do kind, and contribute your thoughts :)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCurrencyHistoryByCurrencyID

func GetCurrencyHistoryByCurrencyID(id string) (map[int64]*CryptocurrencyHistory, error)

GetCurrencyHistoryByCurrencyID get historic data for a currency by ID

Types

type CryptocurrencyHistory

type CryptocurrencyHistory struct {
	Timestamp    int64
	TimeUTC      time.Time
	MarketSupply int64
	PriceBTC     float64
	PriceUSD     float64
	VolUSD       int64
}

CryptocurrencyHistory is the type of a historic currency

type Cyptocurrency

type Cyptocurrency struct {
	ID               string
	Name             string
	Symbol           string
	Rank             int64
	PriceUSD         float64
	PriceBTC         float64
	VolumeUSD24H     float64
	MarketCapUSD     float64
	AvailableSupply  float64
	TotalSupply      float64
	MaxSupply        float64
	PercentChange1H  float64
	PercentChange24H float64
	PercentChange7D  float64
	LastUpdated      time.Time
}

Cyptocurrency is the type of a current currency

func GetCurrencyDataByCurrencyIDs

func GetCurrencyDataByCurrencyIDs(ids []string) ([]*Cyptocurrency, error)

GetCurrencyDataByCurrencyIDs get all current details about a given crypto currency

type ValueResponse

type ValueResponse struct {
	ID    string
	Value float64
}

ValueResponse is the single value response type

func GetAvailableSupplyByCurrencyIDs

func GetAvailableSupplyByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetAvailableSupplyByCurrencyIDs get current available supply for given IDs

func GetMarketCapUSDByCurrencyIDs

func GetMarketCapUSDByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetMarketCapUSDByCurrencyIDs get current market cap in USD for given IDs

func GetMaxSupplyByCurrencyIDs

func GetMaxSupplyByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetMaxSupplyByCurrencyIDs get current max supply for given IDs

func GetPercentChange1HByCurrencyIDs

func GetPercentChange1HByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetPercentChange1HByCurrencyIDs get change in percentage over last 1 hour for given IDs

func GetPercentChange24HByCurrencyIDs

func GetPercentChange24HByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetPercentChange24HByCurrencyIDs get change in percentage over last 24 hours for given IDs

func GetPercentChange7DHByCurrencyIDs

func GetPercentChange7DHByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetPercentChange7DHByCurrencyIDs get change in percentage over last 7 days for given IDs

func GetPriceBTCByCurrencyIDs

func GetPriceBTCByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetPriceBTCByCurrencyIDs get current price in BTC for given IDs

func GetPriceUSDByCurrencyIDs

func GetPriceUSDByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetPriceUSDByCurrencyIDs get current price in USD for given IDs

func GetTotalSupplyByCurrencyIDs

func GetTotalSupplyByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetTotalSupplyByCurrencyIDs get current toal supply for given IDs

func GetVolumeUSD24HByCurrencyIDs

func GetVolumeUSD24HByCurrencyIDs(ids []string) ([]*ValueResponse, error)

GetVolumeUSD24HByCurrencyIDs get current volume over last 24 hours in USD for given IDs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL