Skip to content

gorjan-mishevski/puzzle

Repository files navigation

Puzzle_Crypto_Logo

               

PUZZLE

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.

Installation

go get github.com/gorjan-mishevski/puzzle

Usage

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:

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:

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:

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:

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
                                                mapped.
                                "BTC": <puzzle.MultiPriceTo>
                                        ...
                "EUR": <puzzle.MultiPriceFrom>
                        ...
                        
        "DYNAMIC": ...

Releases

No releases published

Packages

No packages published

Languages