forked from bitfinexcom/bitfinex-api-go
/
currencies.go
50 lines (47 loc) · 1.36 KB
/
currencies.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
package rest
import (
"github.com/bitfinexcom/bitfinex-api-go/v2"
"path"
"strings"
)
// TradeService manages the Trade endpoint.
type CurrenciesService struct {
requestFactory
Synchronous
}
// Retreive currency and symbol service configuration data
// see https://docs.bitfinex.com/reference#rest-public-conf for more info
func (cs *CurrenciesService) Conf(label, symbol, unit, explorer, pairs bool) ([]bitfinex.CurrencyConf, error) {
segments := make([]string, 0)
if label {
segments = append(segments, string(bitfinex.CurrencyLabelMap))
}
if symbol {
segments = append(segments, string(bitfinex.CurrencySymbolMap))
}
if unit {
segments = append(segments, string(bitfinex.CurrencyUnitMap))
}
if explorer {
segments = append(segments, string(bitfinex.CurrencyExplorerMap))
}
if pairs {
segments = append(segments, string(bitfinex.CurrencyExchangeMap))
}
req := NewRequestWithMethod(path.Join("conf", strings.Join(segments,",")), "GET")
raw, err := cs.Request(req)
if err != nil {
return nil, err
}
// add mapping to raw data
parsedRaw := make([]bitfinex.RawCurrencyConf, len(raw))
for index, d := range raw {
parsedRaw = append(parsedRaw, bitfinex.RawCurrencyConf{Mapping: segments[index], Data: d})
}
// parse to config object
configs, err := bitfinex.NewCurrencyConfFromRaw(parsedRaw)
if err != nil {
return nil, err
}
return configs, nil
}