package module
Version: v0.0.0-...-b016698 Latest Latest

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

Go to latest
Published: Jan 5, 2018 License: MIT Imports: 7 Imported by: 0





Golang CryptoCompare library

If you are searching for a nice wrapper library that used CryptoCompare API this is the one. ☝️

This library has a lot of struct's (or type asserted response instead of interface{}) that extend the response, thus ensuring nice clean access to the data and providing easy way to add more functionalities with methods on the structs.

Currently I deliberatly don't add any interfaces and methods becouse I want you to use whatever methods fits best.


go get github.com/gorjan-mishevski/puzzle


Example 1

Let's start simple. Get the current value from a given currency.
EX: I want to know what is the rate from US to ETH, BTC.

1 USD dollar 💵 -> ETH 💎
response := puzzle.BaseAgainsMultiPrice("USD", []string{"ETH", "BTC"})

1st Argument is the currency you take as base.
2nd Argument is a slice of currencies you want the rate.


response <*puzzle.Currency>
        base: "USD"
        rates: <map[string]float64>
                ["ETH"]: 0.001556
                ["BTC"]: 0.000002355

Example 2

Let's see how to get from multiple currencies to multiples rates.
response := puzzle.MultiPrice([]string{"USD", "EUR"}, []string{"ETH", "BTC"})

1st Argument wants a slice of currencies to be taken as base.
2nd Argument is a slice of currencies you want the rate.


response <map[string]map[string]float64>
        "USD": <map[string]float64>
                "ETH": 0.0000034
                "BTC": 0.0000000344
        "EUR": <map[string]float64>
                "ETH": 0.0000034
                "BTC": 0.0000000344

Example 3

We can check the rates for a given day.
response := puzzle.PriceHistoryByDay("USD", []string{"ETH", "BTC"}, 1452680400)

1st Argument is the base we want to converto from.
2nd Argument the currency we want to get it's rate.
3rd Argument is the timestamp. Note, it will get the price at the end of the day GMT based on the requested timestamp.


response <*puzzle.Currency>
        base: "USD"
        rates: <map[string]float64>
                ["ETH"]: 0.001556
                ["BTC"]: 0.000002355

Example 4

Now let's get more complicated. Let's say we want a complete trading information with dynamic to -> from currencies.
response := puzzle.MultiPriceTradingInfo([]string{"USD", "EUR"}, []string{"ETH", "BTC"})


response <puzzle.MultiPriceMarket>
        "RAW": <map[string]puzzle.MultiPriceFrom>
                "USD": <puzzle.MultiPriceFrom>
                        From: "USD"
                        To: <map[string]puzzle.MultiPriceTo>
                                "ETH": <puzzle.MultiPriceTo>
                                        Name: "ETH"
                                        Field: <map[string]interface{}>
                                                ... Here we have random field data.
                                                For now they are as interface but they can be
                                "BTC": <puzzle.MultiPriceTo>
                "EUR": <puzzle.MultiPriceFrom>
        "DYNAMIC": ...




This section is empty.


This section is empty.


func MultiPrice

func MultiPrice(from []string, to []string) (unpacked map[string]map[string]float64)

MultiPrice - Calculates the value for the searched currency. Return example: unpacked["ETH"]["USD"] gives the value ETH -> USD.


type Currency

type Currency struct {
	// contains filtered or unexported fields

Currency - Normalized return data from BaseAgainsMultiPrice.

func BaseAgainsMultiPrice

func BaseAgainsMultiPrice(base string, to []string) *Currency

BaseAgainsMultiPrice - Given a base currency it will load the corresponding rate value. Ex: "USD"(1$) -> "ETH"(0.00X), "BTC(0.00X)"

func PriceHistoryByDay

func PriceHistoryByDay(base string, to []string, timeStamp int32) *Currency

PriceHistoryByDay - Given a base currency it will load the corresponding rate value based on that day. The day is calculated from the timeStamp and will provide the value for that day.

func (*Currency) Base

func (c *Currency) Base() string

Base - Returns the base currency we are asking for rates. Ex: Base = "USD".

func (*Currency) Rates

func (c *Currency) Rates() map[string]float64

Rates - Returns the rates from the base currency to the requested ones. Ex: Base "USD" to "BTH, LIT"

type MultiPriceFrom

type MultiPriceFrom struct {
	From string
	// Contains list of the targetet currency.
	To map[string]MultiPriceTo

MultiPriceFrom - Contains the name of the currency you take as base to compare to. Ex: "USD"

type MultiPriceMarket

type MultiPriceMarket struct {
	// Type - This can be Ex: "RAW" or "DISPLAY"
	Type map[string]map[string]MultiPriceFrom

MultiPriceMarket - Contains the outermost layer of the response.

func MultiPriceTradingInfo

func MultiPriceTradingInfo(from []string, to []string) MultiPriceMarket

MultiPriceTradingInfo - Contains data from multiple currencies to multiple currencies.

type MultiPriceTo

type MultiPriceTo struct {
	Name  string
	Field map[string]interface{}

MultiPriceTo - Contains the targetet currency. Ex: "ETH"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL