-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathohlc_opts.go
72 lines (61 loc) · 1.66 KB
/
ohlc_opts.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
package oxr
import (
"strings"
"time"
)
// Available periods.
const (
OneMinute period = "1m"
FiveMinute period = "5m"
FifteenMinute period = "15m"
ThirtyMinute period = "30m"
OneHour period = "1h"
TwelveHour period = "12h"
OneDay period = "1d"
OneWeek period = "1w"
OneMonth period = "1mo"
)
type ohlcParams struct {
startTime time.Time
period period
baseCurrency string
destinationCurrencies string
prettyPrint bool
}
type period string
// String implements a fmt.Stringer for period.
func (p period) String() string {
return string(p)
}
// OHLCOption allows the client to specify values for a OHLC request.
type OHLCOption func(params *ohlcParams)
// OHLCWithPrettyPrint sets whether to minify the response.
func OHLCWithPrettyPrint(active bool) OHLCOption {
return func(p *ohlcParams) {
p.prettyPrint = active
}
}
// OHLCForStartTime sets the start time for the given period.
func OHLCForStartTime(startTime time.Time) OHLCOption {
return func(p *ohlcParams) {
p.startTime = startTime
}
}
// OHLCForPeriod sets the length of the period.
func OHLCForPeriod(period period) OHLCOption {
return func(p *ohlcParams) {
p.period = period
}
}
// OHLCForBaseCurrency sets the base currency.
func OHLCForBaseCurrency(currency string) OHLCOption {
return func(p *ohlcParams) {
p.baseCurrency = currency
}
}
// OHLCForDestinationCurrencies sets the destination currencies to be included in the response.
func OHLCForDestinationCurrencies(destinationCurrencies []string) OHLCOption {
return func(p *ohlcParams) {
p.destinationCurrencies = strings.Join(destinationCurrencies, ",")
}
}