-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.go
131 lines (106 loc) · 4.89 KB
/
api.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
package finam
import "context"
// какой api реализован
type IFinamClient interface {
// AccessTokens проверка подлинности токена
AccessTokens(ctx context.Context) (ok bool, err error)
// GetPortfolio получить данные по портфелю
GetPortfolio(ctx context.Context, opts ...Option) (Portfolio, error)
// GetSecurity получить список инструментов (Максимальное Количество запросов в минуту = 1 )
GetSecurity(ctx context.Context, board, symbol string) (Securities, error)
// GetCandles получить свечи
GetCandles(ctx context.Context, board, symbol string, timeFrame TimeFrame, opts ...Option) ([]Candle, error)
// получить список заявок
GetOrders(ctx context.Context, opts ...Option) ([]Order, error)
// отменить заявку
DeleteOrder(ctx context.Context, transactionId int64) error
//// создать новую заявку
//SendOrder(ctx context.Context, order NewOrderRequest) (int64, error)
//// купить по рынку
BuyMarket(ctx context.Context, symbol, board string, lot int32) (int64, error)
// выставить лимитную заявку на покупку
BuyLimit(ctx context.Context, board, symbol string, lot int32, price float64) (int64, error)
// продать по рынку
SellMarket(ctx context.Context, board, symbol string, lot int32) (int64, error)
// выставить лимитную заявку на продажу
SellLimit(ctx context.Context, board, symbol string, lot int32, price float64) (int64, error)
// TODO
// получить список стоп-заявок
// создать новую стоп-заявку
// отменить стоп-заявку
}
// все методы api это обертки над сервисами
// GetPortfolio получить данные по портфелю
func (c *Client) GetPortfolio(ctx context.Context, opts ...Option) (Portfolio, error) {
p := &Options{
IncludePositions: true,
}
for _, opt := range opts {
opt(p)
}
s := c.NewGetPortfolioService().
IncludePositions(p.IncludePositions).
IncludeMoney(p.IncludeMoney).
IncludeCurrencies(p.IncludeCurrencies).
IncludeMaxBuySell(p.IncludeMaxBuySell)
return s.Do(ctx)
}
// GetSecurity получить список инструментов (Максимальное Количество запросов в минуту = 1 )
func (c *Client) GetSecurity(ctx context.Context, board, symbol string) (Securities, error) {
return c.NewSecurityService().Board(board).Symbol(symbol).Do(ctx)
}
// получить список заявок
func (c *Client) GetOrders(ctx context.Context, opts ...Option) ([]Order, error) {
p := &Options{}
for _, opt := range opts {
opt(p)
}
s := c.NewGetOrderService().
IncludeActive(p.IncludeActive).
IncludeCanceled(p.IncludeActive).
IncludeCanceled(p.IncludeCanceled)
return s.Do(ctx)
}
// DeleteOrder удаление заявки
// clientId - торговый код клиента (обязательный)
// transactionId int64 (обязательный)
func (c *Client) DeleteOrder(ctx context.Context, transactionId int64) error {
return c.NewCancelOrderService(transactionId).Do(ctx)
}
// GetCandles получить свечи
// Для запроса количества свечей в запросе необходимо указать count и либо from (начиная с указанной даты) либо to (до указанной даты).
// Для запроса за интервал необходимо указать from и to.
func (c *Client) GetCandles(ctx context.Context, board, symbol string, timeFrame TimeFrame, opts ...Option) ([]Candle, error) {
p := &Options{}
for _, opt := range opts {
opt(p)
}
s := c.NewCandlesService(board, symbol, timeFrame).Count(p.Count)
if p.EndTime != nil {
s.endTime = p.EndTime
}
if p.StartTime != nil {
s.startTime = p.StartTime
}
return s.Do(ctx)
}
// BuyMarket купить по рынку
func (c *Client) BuyMarket(ctx context.Context, board, symbol string, lot int32) (int64, error) {
s := c.NewCreateOrderService(board, symbol, SideBuy, lot)
return s.Do(ctx)
}
// SellMarket продать по рынку
func (c *Client) SellMarket(ctx context.Context, board, symbol string, lot int32) (int64, error) {
s := c.NewCreateOrderService(board, symbol, SideSell, lot)
return s.Do(ctx)
}
// BuyLimit купить по рынку
func (c *Client) BuyLimit(ctx context.Context, board, symbol string, lot int32, price float64) (int64, error) {
s := c.NewCreateOrderService(board, symbol, SideBuy, lot).Price(price)
return s.Do(ctx)
}
// SellLimit продать по рынку
func (c *Client) SellLimit(ctx context.Context, board, symbol string, lot int32, price float64) (int64, error) {
s := c.NewCreateOrderService(board, symbol, SideSell, lot).Price(price)
return s.Do(ctx)
}