-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsecurities.go
64 lines (54 loc) · 1.56 KB
/
securities.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
package gomoex
import (
"context"
"github.com/tidwall/gjson"
)
// Security содержит информацию о ценной бумаге.
type Security struct {
Ticker string
LotSize int
ISIN string
Board string
Type string
Instrument string
}
const (
_securitySECID = `SECID`
_securityLotSize = `LOTSIZE`
_securityISIN = `ISIN`
_securityBoard = `BOARDID`
_securityType = `SECTYPE`
_securityInstrument = `INSTRID`
)
func securityConverter(row gjson.Result) (interface{}, error) {
var sec Security
sec.Ticker = row.Get(_securitySECID).String()
sec.LotSize = int(row.Get(_securityLotSize).Int())
sec.ISIN = row.Get(_securityISIN).String()
sec.Board = row.Get(_securityBoard).String()
sec.Type = row.Get(_securityType).String()
sec.Instrument = row.Get(_securityInstrument).String()
return sec, nil
}
// BoardSecurities получает таблицу с торгуемыми бумагами в данном режиме торгов.
//
// Описание запроса - https://iss.moex.com/iss/reference/32
func (iss *ISSClient) BoardSecurities(ctx context.Context, engine, market, board string) (table []Security, err error) {
query := querySettings{
engine: engine,
market: market,
board: board,
object: "securities",
table: "securities",
rowConverter: securityConverter,
}
for raw := range iss.rowsGen(ctx, query.Make()) {
switch row := raw.(type) {
case Security:
table = append(table, row)
case error:
return nil, row
}
}
return table, nil
}