-
Notifications
You must be signed in to change notification settings - Fork 9
/
contract.go
64 lines (54 loc) · 1.62 KB
/
contract.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
package goingecko
import (
"encoding/json"
"fmt"
"net/url"
"github.com/JulianToledano/goingecko/contract"
"github.com/JulianToledano/goingecko/types"
)
func (c *Client) ContractInfo(id, contractAddress string) (*contract.ContractAddressInfo, error) {
rUrl := fmt.Sprintf("%s/%s/%s/%s", c.getContractURL(), id, "contract", contractAddress)
resp, err := c.MakeReq(rUrl)
if err != nil {
return nil, err
}
var data *contract.ContractAddressInfo
err = json.Unmarshal([]byte(resp), &data)
if err != nil {
return nil, err
}
return data, nil
}
func (c *Client) ContractMarketChart(id, contractAddress, vsCurrency, days string) (*types.MarketChart, error) {
params := url.Values{}
params.Add("vs_currency", vsCurrency)
params.Add("days", days)
rUrl := fmt.Sprintf("%s/%s/%s/%s/%s?%s", c.getContractURL(), id, "contract", contractAddress, "market_chart", params.Encode())
resp, err := c.MakeReq(rUrl)
if err != nil {
return nil, err
}
var data *types.MarketChart
err = json.Unmarshal([]byte(resp), &data)
if err != nil {
return nil, err
}
return data, nil
}
func (c *Client) ContractMarketChartRange(id, contractAddress, vsCurrency, from, to string) (*types.MarketChart, error) {
params := url.Values{}
params.Add("vs_currency", vsCurrency)
params.Add("from", from)
params.Add("to", to)
rUrl := fmt.Sprintf("%s/%s/%s/%s/%s?%s", c.getContractURL(), id, "contract", contractAddress, "market_chart/range", params.Encode())
resp, err := c.MakeReq(rUrl)
if err != nil {
return nil, err
}
var data *types.MarketChart
err = json.Unmarshal([]byte(resp), &data)
if err != nil {
return nil, err
}
return data, nil
}