-
Notifications
You must be signed in to change notification settings - Fork 1
/
price.go
56 lines (45 loc) · 1.26 KB
/
price.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
package client
import (
"context"
"fmt"
)
type PriceService service
type Price struct {
Usd float64 `json:"usd"`
Usd24hChange float64 `json:"usd_24h_change"`
}
type PriceResponse struct {
Data map[string]*Price `json:"data"`
ErrorCode int `json:"error_code"`
}
func (i PriceResponse) String() string {
return Stringify(i)
}
type PriceListOptions struct {
ListOptions
Addresses []string `url:"addresses,omitempty"`
}
func (s *PriceService) List(ctx context.Context, opts *PriceListOptions) (map[string]*Price, *Response, error) {
var u = "prices"
return s.listTokensMapPrice(ctx, u, opts)
}
func (s *PriceService) listTokensMapPrice(ctx context.Context, u string, opts *PriceListOptions) (map[string]*Price, *Response, error) {
opts.Addresses = ConvertArrayOptsToApiParam(opts.Addresses)
u, err := addOptions(u, opts)
if err != nil {
return nil, nil, err
}
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var pricesResponse *PriceResponse
resp, err := s.client.Do(ctx, req, &pricesResponse)
if err != nil {
return nil, resp, err
}
if pricesResponse.ErrorCode != 0 {
return nil, resp, fmt.Errorf("error code %d", pricesResponse.ErrorCode)
}
return pricesResponse.Data, resp, nil
}