forked from karalef/coincap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assets.go
82 lines (71 loc) · 3.86 KB
/
assets.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
package coincap
import "net/url"
// Asset contains CoinCap asset data from exchanges.
type Asset struct {
ID string `json:"id"` // unique identifier for asset
Rank int `json:"rank,string"` // rank in terms of the asset's market cap
Symbol string `json:"symbol"` // most common symbol used to identify this asset on an exchange
Name string `json:"name"` // proper name for asset
Supply float64 `json:"supply,string"` // available supply for trading
MaxSupply float64 `json:"maxSupply,string"` // total quantity of asset issued
MarketCapUsd float64 `json:"marketCapUsd,string"` // supply x price
VolumeUsd24Hr float64 `json:"volumeUsd24Hr,string"` // quantity of trading volume in USD over last 24 hours
PriceUsd float64 `json:"priceUsd,string"` // volume-weighted price based on real-time market data, translated to USD
ChangePercent24Hr float64 `json:"changePercent24Hr,string"` // the direction and value change in the last 24 hours
Vwap24Hr float64 `json:"vwap24Hr,string"` // Volume Weighted Average Price in the last 24 hours
}
// Assets returns a list of all CoinCap assets.
func (c *Client) Assets() ([]Asset, Timestamp, error) {
return c.AssetsSearch("", nil)
}
// AssetsSearch returns a list of CoinCap assets with params.
func (c *Client) AssetsSearch(search string, trim *TrimParams) ([]Asset, Timestamp, error) {
q := make(url.Values)
if search != "" {
q.Set("search", search)
}
trim.setTo(&q)
return request[[]Asset](c, "assets", q)
}
// AssetsSearchByIDs returns a list of CoinCap assets.
func (c *Client) AssetsSearchByIDs(ids []string) ([]Asset, Timestamp, error) {
if ids == nil {
return nil, 0, nil
}
return request[[]Asset](c, "assets", url.Values{"ids": ids})
}
// AssetByID returns an asset by its ID.
func (c *Client) AssetByID(id string) (*Asset, Timestamp, error) {
return request[*Asset](c, "assets/"+id, nil)
}
// AssetHistory contains the USD price of an asset at a given timestamp.
type AssetHistory struct {
PriceUSD float64 `json:"priceUsd,string"` // volume-weighted price in USD based on real-time market data
Time Timestamp `json:"time"` // timestamp correlating to the given price
}
// AssetHistory returns USD price history of a given asset.
func (c *Client) AssetHistory(id string, interval *IntervalParams) ([]AssetHistory, Timestamp, error) {
q := make(url.Values)
var err = interval.setTo(&q, false)
if err != nil {
return nil, 0, err
}
return request[[]AssetHistory](c, "assets/"+id+"/history", q)
}
// AssetMarket contains the markets info of an asset.
type AssetMarket struct {
ExchangeID string `json:"exchangeId"` // unique identifier for exchange
BaseID string `json:"baseId"` // unique identifier for this asset, base is asset purchased
QuoteID string `json:"quoteId"` // unique identifier for this asset, quote is asset used to purchase based
BaseSymbol string `json:"baseSymbol"` // most common symbol used to identify asset, base is asset purchased
QuoteSymbol string `json:"quoteSymbol"` // most common symbol used to identify asset, quote is asset used to purchase base
VolumeUsd24Hr float64 `json:"volumeUsd24Hr,string"` // volume transacted on this market in last 24 hours
PriceUsd float64 `json:"priceUsd,string"` // the amount of quote asset traded for one unit of base asset
VolumePercent float64 `json:"volumePercent,string"` // percent of quote asset volume
}
// AssetMarkets returns markets info of a given asset.
func (c *Client) AssetMarkets(id string, trim *TrimParams) ([]AssetMarket, Timestamp, error) {
q := make(url.Values)
trim.setTo(&q)
return request[[]AssetMarket](c, "assets/"+id+"/markets", q)
}