forked from karalef/coincap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markets.go
59 lines (54 loc) · 2.9 KB
/
markets.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
package coincap
import "net/url"
// MarketsRequest contains the parameters you can use to provide a request for market data.
type MarketsRequest struct {
ExchangeID string // search by unique exchange ID
BaseSymbol string // return all results with this base symbol
BaseID string // return all results with this base id
QuoteSymbol string // return all results with this quote symbol
QuoteID string // return all results with this quote ID
AssetSymbol string // return all results with this asset symbol
AssetID string // return all results with this asset ID
}
// Market contains the market data response from the api.
type Market struct {
ExchangeID string `json:"exchangeId"` // unique identifier for exchange
Rank int `json:"rank,string"` // rank in terms of volume transacted in this market
BaseSymbol string `json:"baseSymbol"` // most common symbol used to identify this asset
BaseID string `json:"baseId"` // unique identifier for this asset. base is the asset purchased
QuoteSymbol string `json:"quoteSymbol"` // most common symbol used to identify this asset
QuoteID string `json:"quoteId"` // unique identifier for this asset. quote is the asset used to purchase base
PriceQuote float64 `json:"priceQuote,string"` // amount of quote asset traded for 1 unit of base asset
PriceUsd float64 `json:"priceUsd,string"` // quote price translated to USD
VolumeUsd24Hr float64 `json:"volumeUsd24Hr,string"` // volume transacted in this market in the last 24 hours
PercentExchangeVolume float64 `json:"percentExchangeVolume,string"` // amount of daily volume this market transacts compared to others on this exchange
TradesCount24Hr int `json:"tradesCount24Hr,string"` // number of trades on this market in the last 24 hours
Updated Timestamp `json:"updated"` // last time information was received from this market
}
// Markets requests market data for all markets matching the criteria set in the MarketRequest params.
func (c *Client) Markets(params MarketsRequest, trim *TrimParams) ([]Market, Timestamp, error) {
q := make(url.Values)
trim.setTo(&q)
if params.ExchangeID != "" {
q.Set("exchange", params.ExchangeID)
}
if params.BaseSymbol != "" {
q.Set("baseSymbol", params.BaseSymbol)
}
if params.BaseID != "" {
q.Set("baseId", params.BaseID)
}
if params.QuoteSymbol != "" {
q.Set("quoteSymbol", params.QuoteSymbol)
}
if params.QuoteID != "" {
q.Set("quoteId", params.QuoteID)
}
if params.AssetSymbol != "" {
q.Set("assetSymbol", params.AssetSymbol)
}
if params.AssetID != "" {
q.Set("assetId", params.AssetID)
}
return request[[]Market](c, "markets", q)
}