forked from hurisheng/go-futu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qot_getrt.go
44 lines (39 loc) · 959 Bytes
/
qot_getrt.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
package futuapi
import (
"context"
"github.com/Lawrence93Ho/go-futu-api/pb/qotgetrt"
"github.com/Lawrence93Ho/go-futu-api/protocol"
)
const (
ProtoIDQotGetRT = 3008 //Qot_GetRT 获取分时
)
// 获取实时分时
func (api *FutuAPI) GetRTData(ctx context.Context, security *Security) (*RTData, error) {
// 请求参数
req := qotgetrt.Request{C2S: &qotgetrt.C2S{
Security: security.pb(),
}}
// 发送请求,同步返回结果
ch := make(qotgetrt.ResponseChan)
if err := api.get(ProtoIDQotGetRT, &req, ch); err != nil {
return nil, err
}
select {
case <-ctx.Done():
return nil, ErrInterrupted
case resp, ok := <-ch:
if !ok {
return nil, ErrChannelClosed
}
return rtDataFromGetPB(resp.GetS2C()), protocol.Error(resp)
}
}
func rtDataFromGetPB(pb *qotgetrt.S2C) *RTData {
if pb == nil {
return nil
}
return &RTData{
Security: securityFromPB(pb.GetSecurity()),
TimeShares: timeShareListFromPB(pb.GetRtList()),
}
}