-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_request_options.go
313 lines (255 loc) · 10.6 KB
/
index_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package moexiss
import "net/url"
// Language represents a language of answers of MoEx ISS API
type Language string
// Possible values of Language type
const (
LangUndefined Language = ""
LangEn Language = "en"
LangRu Language = "ru"
)
// string representations of Language values
func (s Language) String() string {
switch s {
case LangEn:
return string(LangEn)
case LangRu:
return string(LangRu)
default:
return string(LangUndefined)
}
}
// IndexRequestOptions contains options which can be used as arguments
// for building requests of 'Index'
// MoEx ISS API docs: https://iss.moex.com/iss/reference/28
type IndexRequestOptions struct {
// Engines details
enginesLang Language //`engines.lang` query parameter in url.URL
// Markets details
marketsLang Language //`markets.lang` query parameter in url.URL
// Boards details
boardsLang Language //`boards.lang` query parameter in url.URL
// BoardGroups details
boardGroupsLang Language //`boardgroups.lang` query parameter in url.URL
boardGroupsEngine EngineName //`boardgroups.engine` query parameter in url.URL
boardGroupsIsTraded bool //`boardgroups.is_traded` query parameter in url.URL
// Durations details
durationsLang Language //`durations.lang` query parameter in url.URL
// SecurityTypes details
securityTypesLang Language //`securitytypes.lang` query parameter in url.URL
securityTypesEngine EngineName //`securitytypes.engine` query parameter in url.URL
// SecurityGroups details
securityGroupsLang Language //`securitygroups.lang` query parameter in url.URL
securityGroupsEngine EngineName //`securitygroups.trade_engine` query parameter in url.URL
securityGroupsHideInactive bool //`securitygroups.hide_inactive` query parameter in url.URL
// SecurityCollections details
securityCollectionsLang Language //`securitycollections.lang` query parameter in url.URL
}
// IndexReqOptionsBuilder represents a builder of IndexRequestOptions struct
type IndexReqOptionsBuilder struct {
options *IndexRequestOptions
}
// NewIndexReqOptionsBuilder is a constructor for IndexReqOptionsBuilder
func NewIndexReqOptionsBuilder() *IndexReqOptionsBuilder {
return &IndexReqOptionsBuilder{options: &IndexRequestOptions{}}
}
// Build builds IndexRequestOptions from IndexReqOptionsBuilder
func (b *IndexReqOptionsBuilder) Build() *IndexRequestOptions {
return b.options
}
/* Options of Engine*/
// IndexReqOptionsEngineBuilder facet of IndexReqOptionsBuilder
type IndexReqOptionsEngineBuilder struct {
IndexReqOptionsBuilder
}
// Engine chains to type *IndexReqOptionsBuilder and returns *IndexReqOptionsEngineBuilder
func (b *IndexReqOptionsBuilder) Engine() *IndexReqOptionsEngineBuilder {
return &IndexReqOptionsEngineBuilder{*b}
}
// Lang sets 'enginesLang' parameter to a request of directories of Engine
func (e *IndexReqOptionsEngineBuilder) Lang(lang Language) *IndexReqOptionsEngineBuilder {
e.options.enginesLang = lang
return e
}
/* Options of Market*/
// IndexReqOptionsMarketBuilder facet of IndexReqOptionsBuilder
type IndexReqOptionsMarketBuilder struct {
IndexReqOptionsBuilder
}
// Market chains to type *IndexReqOptionsBuilder and returns *IndexReqOptionsMarketBuilder
func (b *IndexReqOptionsBuilder) Market() *IndexReqOptionsMarketBuilder {
return &IndexReqOptionsMarketBuilder{*b}
}
// Lang sets 'marketsLang' parameter to a request of directories of Market
func (e *IndexReqOptionsMarketBuilder) Lang(lang Language) *IndexReqOptionsMarketBuilder {
e.options.marketsLang = lang
return e
}
/* Options of Board*/
// IndexReqOptionsBoardBuilder facet of IndexReqOptionsBuilder
type IndexReqOptionsBoardBuilder struct {
IndexReqOptionsBuilder
}
// Board chains to type *IndexReqOptionsBuilder and returns *IndexReqOptionsBoardBuilder
func (b *IndexReqOptionsBuilder) Board() *IndexReqOptionsBoardBuilder {
return &IndexReqOptionsBoardBuilder{*b}
}
// Lang sets 'boardsLang' parameter to a request of directories of Board
func (e *IndexReqOptionsBoardBuilder) Lang(lang Language) *IndexReqOptionsBoardBuilder {
e.options.boardsLang = lang
return e
}
/* Options of BoardGroup*/
// IndexReqOptionsBoardGroupBuilder facet of IndexReqOptionsBuilder
type IndexReqOptionsBoardGroupBuilder struct {
IndexReqOptionsBuilder
}
// BoardGroup chains to type *IndexReqOptionsBuilder and returns *IndexReqOptionsBoardGroupBuilder
func (b *IndexReqOptionsBuilder) BoardGroup() *IndexReqOptionsBoardGroupBuilder {
return &IndexReqOptionsBoardGroupBuilder{*b}
}
// Lang sets 'boardGroupsLang' parameter to a request of directories of BoardGroup
func (e *IndexReqOptionsBoardGroupBuilder) Lang(lang Language) *IndexReqOptionsBoardGroupBuilder {
e.options.boardGroupsLang = lang
return e
}
// IsTraded sets 'boardGroupsIsTraded' parameter to a request of directories of BoardGroup
func (e *IndexReqOptionsBoardGroupBuilder) IsTraded(isTrading bool) *IndexReqOptionsBoardGroupBuilder {
e.options.boardGroupsIsTraded = isTrading
return e
}
// WithEngine sets 'boardGroupsEngine' parameter to a request of directories of BoardGroup
func (e *IndexReqOptionsBoardGroupBuilder) WithEngine(engine EngineName) *IndexReqOptionsBoardGroupBuilder {
e.options.boardGroupsEngine = engine
return e
}
/* Options of Duration*/
// IndexReqOptionsDurationBuilder facet of IndexReqOptionsBuilder
type IndexReqOptionsDurationBuilder struct {
IndexReqOptionsBuilder
}
// Duration chains to type *IndexReqOptionsBuilder and returns *IndexReqOptionsDurationBuilder
func (b *IndexReqOptionsBuilder) Duration() *IndexReqOptionsDurationBuilder {
return &IndexReqOptionsDurationBuilder{*b}
}
// Lang sets 'durationsLang' parameter to a request of directories of Duration
// and returns *IndexReqOptionsDurationBuilder
func (e *IndexReqOptionsDurationBuilder) Lang(lang Language) *IndexReqOptionsDurationBuilder {
e.options.durationsLang = lang
return e
}
/* Options of SecurityType*/
// IndexReqOptionsSecurityTypeBuilder facet of IndexReqOptionsBuilder
type IndexReqOptionsSecurityTypeBuilder struct {
IndexReqOptionsBuilder
}
// SecurityType chains to type *IndexReqOptionsBuilder and returns *IndexReqOptionsSecurityTypeBuilder
func (b *IndexReqOptionsBuilder) SecurityType() *IndexReqOptionsSecurityTypeBuilder {
return &IndexReqOptionsSecurityTypeBuilder{*b}
}
// Lang sets 'securityTypesLang' parameter to a request of directories of SecurityType
func (e *IndexReqOptionsSecurityTypeBuilder) Lang(lang Language) *IndexReqOptionsSecurityTypeBuilder {
e.options.securityTypesLang = lang
return e
}
// WithEngine sets 'securityTypesEngine' parameter to a request of directories of SecurityType
func (e *IndexReqOptionsSecurityTypeBuilder) WithEngine(engine EngineName) *IndexReqOptionsSecurityTypeBuilder {
e.options.securityTypesEngine = engine
return e
}
/* Options of SecurityGroup*/
// IndexReqOptionsSecurityGroupBuilder facet of IndexReqOptionsBuilder
type IndexReqOptionsSecurityGroupBuilder struct {
IndexReqOptionsBuilder
}
// SecurityGroup chains to type *IndexReqOptionsBuilder and returns *IndexReqOptionsSecurityGroupBuilder
func (b *IndexReqOptionsBuilder) SecurityGroup() *IndexReqOptionsSecurityGroupBuilder {
return &IndexReqOptionsSecurityGroupBuilder{*b}
}
// Lang sets 'securityGroupsLang' parameter to a request of directories of SecurityGroup
func (e *IndexReqOptionsSecurityGroupBuilder) Lang(lang Language) *IndexReqOptionsSecurityGroupBuilder {
e.options.securityGroupsLang = lang
return e
}
// HideInactive sets 'securityGroupsHideInactive' parameter to a request of directories of SecurityGroup
func (e *IndexReqOptionsSecurityGroupBuilder) HideInactive(isHiding bool) *IndexReqOptionsSecurityGroupBuilder {
e.options.securityGroupsHideInactive = isHiding
return e
}
// WithEngine sets 'securityGroupsEngine' parameter to a request of directories of SecurityGroup
func (e *IndexReqOptionsSecurityGroupBuilder) WithEngine(engine EngineName) *IndexReqOptionsSecurityGroupBuilder {
e.options.securityGroupsEngine = engine
return e
}
/* Options of SecurityCollection*/
// IndexReqOptionsSecurityCollectionBuilder facet of IndexReqOptionsBuilder
type IndexReqOptionsSecurityCollectionBuilder struct {
IndexReqOptionsBuilder
}
// SecurityCollection chains to type *IndexReqOptionsBuilder and returns *IndexReqOptionsSecurityCollectionBuilder
func (b *IndexReqOptionsBuilder) SecurityCollection() *IndexReqOptionsSecurityCollectionBuilder {
return &IndexReqOptionsSecurityCollectionBuilder{*b}
}
// Lang sets 'securityCollectionsLang' parameter to a request of directories of SecurityCollection
func (e *IndexReqOptionsSecurityCollectionBuilder) Lang(lang Language) *IndexReqOptionsSecurityCollectionBuilder {
e.options.securityCollectionsLang = lang
return e
}
// addIndexRequestOptions sets parameters into *url.URL
// from IndexRequestOptions struct and returns it back
func addIndexRequestOptions(url *url.URL, options *IndexRequestOptions) *url.URL {
if options == nil {
return url
}
q := url.Query()
if options.enginesLang != LangUndefined {
q.Set("engines.lang", options.enginesLang.String())
}
if options.marketsLang != LangUndefined {
q.Set("markets.lang", options.marketsLang.String())
}
if options.boardsLang != LangUndefined {
q.Set("boards.lang", options.boardsLang.String())
}
addBoardGroupsParams(&q, *options)
if options.durationsLang != LangUndefined {
q.Set("durations.lang", options.durationsLang.String())
}
addSecurityTypesParams(&q, *options)
addSecurityGroupsParams(&q, *options)
if options.securityCollectionsLang != LangUndefined {
q.Set("securitycollections.lang", options.securityCollectionsLang.String())
}
url.RawQuery = q.Encode()
return url
}
func addSecurityGroupsParams(q *url.Values, options IndexRequestOptions) {
if options.securityGroupsLang != LangUndefined {
q.Set("securitygroups.lang", options.securityGroupsLang.String())
}
if options.securityGroupsEngine != EngineUndefined {
q.Set("securitygroups.trade_engine", options.securityGroupsEngine.String())
}
if options.securityGroupsHideInactive {
q.Set("securitygroups.hide_inactive", "1")
}
}
func addSecurityTypesParams(q *url.Values, options IndexRequestOptions) {
if options.securityTypesLang != LangUndefined {
q.Set("securitytypes.lang", options.securityTypesLang.String())
}
if options.securityTypesEngine != EngineUndefined {
q.Set("securitytypes.engine", options.securityTypesEngine.String())
}
}
func addBoardGroupsParams(q *url.Values, options IndexRequestOptions) {
if options.boardGroupsLang != LangUndefined {
q.Set("boardgroups.lang", options.boardGroupsLang.String())
}
if options.boardGroupsEngine != EngineUndefined {
q.Set("boardgroups.engine", options.boardGroupsEngine.String())
}
if options.boardGroupsIsTraded {
q.Set("boardgroups.is_traded", "1")
}
}