forked from JulianToledano/goingecko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple.go
73 lines (61 loc) · 2.13 KB
/
simple.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package goingecko
import (
"encoding/json"
"fmt"
"net/url"
"strconv"
"github.com/JulianToledano/goingecko/simple"
)
func (c *Client) SimplePrice(ids, vsCurrencies string, includeMarketCap, includeDayVolume, includeDayChange, includeLastTimeUpdated bool) (simple.Price, error) {
params := url.Values{}
params.Add("ids", ids)
params.Add("vs_currencies", vsCurrencies)
params.Add("include_market_cap", strconv.FormatBool(includeMarketCap))
params.Add("include_24hr_vol", strconv.FormatBool(includeDayVolume))
params.Add("include_24hr_change", strconv.FormatBool(includeDayChange))
params.Add("include_last_updated_at", strconv.FormatBool(includeLastTimeUpdated))
rUrl := fmt.Sprintf("%s/%s?%s", simpleURL, "price", params.Encode())
resp, err := c.MakeReq(rUrl)
if err != nil {
return nil, err
}
var data simple.Price
err = json.Unmarshal([]byte(resp), &data)
if err != nil {
return nil, err
}
return data, nil
}
func (c *Client) SimpleTokenPrice(id, contractAddresses, vsCurrencies string, includeMarketCap, includeDayVolume, includeDayChange, includeLastTimeUpdated bool) (simple.TokenPrice, error) {
params := url.Values{}
params.Add("contract_addresses", contractAddresses)
params.Add("vs_currencies", vsCurrencies)
params.Add("include_market_cap", strconv.FormatBool(includeMarketCap))
params.Add("include_24hr_vol", strconv.FormatBool(includeDayVolume))
params.Add("include_24hr_change", strconv.FormatBool(includeDayChange))
params.Add("include_last_updated_at", strconv.FormatBool(includeLastTimeUpdated))
rUrl := fmt.Sprintf("%s/%s/%s?%s", simpleURL, "token_price", id, params.Encode())
resp, err := c.MakeReq(rUrl)
if err != nil {
return nil, err
}
var data simple.TokenPrice
err = json.Unmarshal([]byte(resp), &data)
if err != nil {
return nil, err
}
return data, nil
}
func (c *Client) SimpleSupportedVsCurrency() (*simple.SupportedVsCurrency, error) {
rUrl := fmt.Sprintf("%s/%s", simpleURL, "supported_vs_currencies")
resp, err := c.MakeReq(rUrl)
if err != nil {
return nil, err
}
var data *simple.SupportedVsCurrency
err = json.Unmarshal(resp, &data)
if err != nil {
return nil, err
}
return data, nil
}