-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathquote.go
More file actions
62 lines (55 loc) · 2.46 KB
/
Copy pathquote.go
File metadata and controls
62 lines (55 loc) · 2.46 KB
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
package finam
import (
"context"
"net/http"
"time"
)
// Информация о котировке
type Quote struct {
Symbol string `json:"symbol,omitempty"` // Символ инструмента
Timestamp time.Time `json:"timestamp,omitempty"` // Метка времени
Ask Decimal `json:"ask,omitempty"` // Аск. 0 при отсутствии активного аска
AskSize Decimal `json:"ask_size,omitempty"` // Размер аска
Bid Decimal `json:"bid,omitempty"` // Бид. 0 при отсутствии активного бида
BidSize Decimal `json:"bid_size,omitempty"` // Размер бида
Last Decimal `json:"last,omitempty"` // Цена последней сделки
LastSize Decimal `json:"last_size,omitempty"` // Размер последней сделки
Volume Decimal `json:"volume,omitempty"` // Дневной объем сделок
Turnover Decimal `json:"turnover,omitempty"` // Дневной оборот сделок
Open Decimal `json:"open,omitempty"` // Цена открытия. Дневная
High Decimal `json:"high,omitempty"` // Максимальная цена. Дневная
Low Decimal `json:"low,omitempty"` // Минимальная цена. Дневная
Close Decimal `json:"close,omitempty"` // Цена закрытия. Дневная
Change Decimal `json:"change,omitempty"` // Изменение цены (last минус close)
}
type QuoteRequest struct {
client *Client
symbol string
}
type QuoteResponse struct {
Symbol string `json:"symbol,omitempty"` // Символ инструмента
Quote Quote `json:"quote,omitempty"` // Информация о котировке
}
func (c *Client) NewQuoteRequest(symbol string) *QuoteRequest {
return &QuoteRequest{
client: c,
symbol: symbol,
}
}
// Получение последней котировки по инструменту
// https://api.finam.ru/v1/instruments/YDEX@MISX/quotes/latest
func (r *QuoteRequest) Do(ctx context.Context) (QuoteResponse, error) {
var err error
var result QuoteResponse
req := NewRequest(http.MethodGet, apiURL).URLJoin("v1/instruments").URLJoin(r.symbol).URLJoin("quotes/latest")
req.authorization = true
resp, err := r.client.SendRequest(req)
if err != nil {
return result, err
}
err = resp.DecodeJSON(&result)
if err != nil {
return result, err
}
return result, nil
}