forked from hurisheng/go-futu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqot_getkl.go
52 lines (47 loc) · 1.26 KB
/
qot_getkl.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
package futuapi
import (
"context"
"github.com/headshot289/go-futu-api/pb/qotcommon"
"github.com/headshot289/go-futu-api/pb/qotgetkl"
"github.com/headshot289/go-futu-api/protocol"
)
const (
ProtoIDQotGetKL = 3006 //Qot_GetKL 获取 K 线
)
// 获取实时 K 线
func (api *FutuAPI) GetCurKL(ctx context.Context, security *Security, num int32, rehabType qotcommon.RehabType, klType qotcommon.KLType) (*RTKLine, error) {
// 请求参数
req := qotgetkl.Request{
C2S: &qotgetkl.C2S{
Security: security.pb(),
ReqNum: &num,
RehabType: (*int32)(&rehabType),
KlType: (*int32)(&klType),
},
}
// 发送请求,同步返回结果
ch := make(qotgetkl.ResponseChan)
if err := api.get(ProtoIDQotGetKL, &req, ch); err != nil {
return nil, err
}
select {
case <-ctx.Done():
return nil, ErrInterrupted
case resp, ok := <-ch:
if !ok {
return nil, ErrChannelClosed
}
return rtKLineFromGetPB(resp.GetS2C(), rehabType, klType), protocol.Error(resp)
}
}
func rtKLineFromGetPB(pb *qotgetkl.S2C, rehabType qotcommon.RehabType, klType qotcommon.KLType) *RTKLine {
if pb == nil {
return nil
}
return &RTKLine{
RehabType: rehabType,
KLType: klType,
Security: securityFromPB(pb.GetSecurity()),
KLines: kLineListFromPB(pb.GetKlList()),
}
}