-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcryptocurrencies.go
54 lines (40 loc) · 1.33 KB
/
cryptocurrencies.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
package tasty
import (
"fmt"
"net/http"
"net/url"
)
// Retrieve a set of cryptocurrencies given an array of one or more symbols.
func (c *Client) GetCryptocurrencies(symbols []string) ([]CryptocurrencyInfo, *http.Response, error) {
path := "/instruments/cryptocurrencies"
type instrumentResponse struct {
Data struct {
Cryptocurrencies []CryptocurrencyInfo `json:"items"`
} `json:"data"`
}
type symbolsQuery struct {
// Symbols is the list of symbols
Symbols []string `url:"symbol[]"`
}
query := symbolsQuery{Symbols: symbols}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, query, nil, instrumentRes)
if err != nil {
return []CryptocurrencyInfo{}, resp, err
}
return instrumentRes.Data.Cryptocurrencies, resp, nil
}
// Retrieve a cryptocurrency given a symbol.
func (c *Client) GetCryptocurrency(symbol Cryptocurrency) (CryptocurrencyInfo, *http.Response, error) {
symbolString := url.PathEscape(string(symbol))
path := fmt.Sprintf("/instruments/cryptocurrencies/%s", symbolString)
type instrumentResponse struct {
Crypto CryptocurrencyInfo `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.customRequest(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return CryptocurrencyInfo{}, resp, err
}
return instrumentRes.Crypto, resp, nil
}