This repository has been archived by the owner on Sep 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cryptocurrency.go
151 lines (128 loc) · 5.25 KB
/
cryptocurrency.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package coinmarketcap
import (
"encoding/json"
"fmt"
"strings"
"github.com/hexoul/go-coinmarketcap/types"
"github.com/hexoul/go-coinmarketcap/util"
)
// CryptoInfo returns all static metadata for one or more cryptocurrencies
// arg: id, symbol
// src: https://pro-api.coinmarketcap.com/v1/cryptocurrency/info
// doc: https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyInfo
func (s *Client) CryptoInfo(options *types.Options) (*types.CryptoInfoMap, error) {
url := fmt.Sprintf("%s/cryptocurrency/info?%s", baseURL, strings.Join(util.ParseOptions(options), "&"))
_, body, err := s.getResponse(url)
if err != nil {
return nil, err
}
result := new(types.CryptoInfoMap)
if err := json.Unmarshal(body, result); err != nil {
return nil, err
}
return result, nil
}
// CryptoMap returns a paginated list of all cryptocurrencies by CoinMarketCap ID
// arg: symbol, start, limit, listing_status
// src: https://pro-api.coinmarketcap.com/v1/cryptocurrency/map
// doc: https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyMap
func (s *Client) CryptoMap(options *types.Options) (*types.CryptoMapList, error) {
url := fmt.Sprintf("%s/cryptocurrency/map?%s", baseURL, strings.Join(util.ParseOptions(options), "&"))
_, body, err := s.getResponse(url)
if err != nil {
return nil, err
}
result := new(types.CryptoMapList)
if err := json.Unmarshal(body, result); err != nil {
return nil, err
}
return result, nil
}
// CryptoListingsLatest gets a paginated list of all cryptocurrencies with latest market data.
// arg: start, limit, convert, sort, sort_dir, cryptocurrency_type
// src: https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest
// doc: https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyListingsLatest
func (s *Client) CryptoListingsLatest(options *types.Options) (*types.CryptoMarketList, error) {
url := fmt.Sprintf("%s/cryptocurrency/listings/latest?%s", baseURL, strings.Join(util.ParseOptions(options), "&"))
_, body, err := s.getResponse(url)
if err != nil {
return nil, err
}
result := new(types.CryptoMarketList)
if err := json.Unmarshal(body, result); err != nil {
return nil, err
}
return result, nil
}
// CryptoMarketPairsLatest lists all market pairs for the specified cryptocurrency with associated stats.
// arg: id, symbol, start, limit, convert
// src: https://pro-api.coinmarketcap.com/v1/cryptocurrency/market-pairs/latest
// doc: https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyMarketpairsLatest
func (s *Client) CryptoMarketPairsLatest(options *types.Options) (*types.MarketPairs, error) {
url := fmt.Sprintf("%s/cryptocurrency/market-pairs/latest?%s", baseURL, strings.Join(util.ParseOptions(options), "&"))
resp, _, err := s.getResponse(url)
if err != nil {
return nil, err
}
var result = new(types.MarketPairs)
b, err := json.Marshal(resp.Data)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, result); err != nil {
return nil, err
}
return result, nil
}
// CryptoOhlcvLatest returns the latest OHLCV (Open, High, Low, Close, Volume) market values for one or more cryptocurrencies in the currently UTC day.
// arg: id, symbol, convert
// src: https://pro-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/latest
// doc: https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyOhlcvLatest
func (s *Client) CryptoOhlcvLatest(options *types.Options) (*types.OhlcvMap, error) {
url := fmt.Sprintf("%s/cryptocurrency/ohlcv/latest?%s", baseURL, strings.Join(util.ParseOptions(options), "&"))
_, body, err := s.getResponse(url)
if err != nil {
return nil, err
}
result := new(types.OhlcvMap)
if err := json.Unmarshal(body, result); err != nil {
return nil, err
}
return result, nil
}
// CryptoOhlcvHistorical returns an interval of historic OHLCV (Open, High, Low, Close, Volume) market quotes for a cryptocurrency.
// arg: id, symbol, convert, time_period, time_start, time_end, count, interval
// src: https://pro-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical
// doc: https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyOhlcvHistorical
func (s *Client) CryptoOhlcvHistorical(options *types.Options) (*types.OhlcvList, error) {
url := fmt.Sprintf("%s/cryptocurrency/ohlcv/historical?%s", baseURL, strings.Join(util.ParseOptions(options), "&"))
resp, _, err := s.getResponse(url)
if err != nil {
return nil, err
}
result := new(types.OhlcvList)
b, err := json.Marshal(resp.Data)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, result); err != nil {
return nil, err
}
return result, nil
}
// CryptoMarketQuotesLatest gets the latest market quote for 1 or more cryptocurrencies.
// arg: id, symbol, convert
// src: https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest
// doc: https://pro.coinmarketcap.com/api/v1#operation/getV1CryptocurrencyQuotesLatest
func (s *Client) CryptoMarketQuotesLatest(options *types.Options) (*types.CryptoMarketMap, error) {
url := fmt.Sprintf("%s/cryptocurrency/quotes/latest?%s", baseURL, strings.Join(util.ParseOptions(options), "&"))
_, body, err := s.getResponse(url)
if err != nil {
return nil, err
}
result := new(types.CryptoMarketMap)
if err := json.Unmarshal(body, result); err != nil {
return nil, err
}
return result, nil
}