-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate_request_options.go
65 lines (55 loc) · 1.92 KB
/
aggregate_request_options.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
package moexiss
import (
"net/url"
"time"
)
//AggregateRequestOptions contains options which can be used as arguments
//for building requests to get aggregated trading results for the date by market.
//MoEx ISS API docs: https://iss.moex.com/iss/reference/214
type AggregateRequestOptions struct {
lang Language // `lang` query parameter in url.URL
date time.Time // `date` query parameter in url.URL
}
//AggregateReqOptionsBuilder represents a builder of AggregateRequestOptions struct
type AggregateReqOptionsBuilder struct {
options *AggregateRequestOptions
}
//NewAggregateReqOptionsBuilder is a constructor of AggregateReqOptionsBuilder
func NewAggregateReqOptionsBuilder() *AggregateReqOptionsBuilder {
return &AggregateReqOptionsBuilder{options: &AggregateRequestOptions{}}
}
//Build builds AggregateRequestOptions from AggregateReqOptionsBuilder
func (b *AggregateReqOptionsBuilder) Build() *AggregateRequestOptions {
return b.options
}
//Lang sets 'lang' parameter to a request
func (b *AggregateReqOptionsBuilder) Lang(lang Language) *AggregateReqOptionsBuilder {
b.options.lang = lang
return b
}
//Date sets 'date' parameter to a request
//'date' is the date for which you want to display the data.
//By default(if none), for the last date in the trading results.
func (b *AggregateReqOptionsBuilder) Date(date time.Time) *AggregateReqOptionsBuilder {
b.options.date = date
return b
}
//addAggregateRequestOptions sets parameters into *url.URL
//from AggregateRequestOptions struct and returns it back
func addAggregateRequestOptions(url *url.URL, options *AggregateRequestOptions) *url.URL {
q := url.Query()
q.Set("iss.meta", "off")
q.Set("iss.json", "extended")
if options == nil {
url.RawQuery = q.Encode()
return url
}
if options.lang != LangUndefined {
q.Set("lang", options.lang.String())
}
if !options.date.IsZero() {
q.Set("date", options.date.Format("2006-01-02"))
}
url.RawQuery = q.Encode()
return url
}