-
Notifications
You must be signed in to change notification settings - Fork 16
/
exchange_rates.go
67 lines (61 loc) · 1.69 KB
/
exchange_rates.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
/*
* Coinbase Golang API Library
*
* Copyright (C) 2017 Lukas Matt <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package coinbase
import "encoding/json"
/*
Example Response:
{
"data": {
"currency": "BTC",
"rates": {
"AED": "36.73",
"AFN": "589.50",
"ALL": "1258.82",
"AMD": "4769.49",
"ANG": "17.88",
"AOA": "1102.76",
"ARS": "90.37",
"AUD": "12.93",
"AWG": "17.93",
"AZN": "10.48",
"BAM": "17.38",
...
}
}
}
*/
type APIExchangeRatesData struct {
Currency string
// using map[string]float64 `json:",string"`
// will result into ain unmarshalling error.
// Using json.Number gets rid of strconv!
Rates map[string]json.Number
}
type APIExchangeRates struct {
Data APIExchangeRatesData
Errors []Error
}
// GetExchangeRates requires the currency as parameter and returns an APIExchangeRates struct
func (a *APIClient) GetExchangeRates(currency string) (rates APIExchangeRates, err error) {
err = a.Fetch("GET", "/v2/exchange-rates?currency=" + currency, nil, &rates)
if err != nil {
return
}
return
}