forked from hurisheng/go-futu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqot_updatekl.go
60 lines (50 loc) · 1.25 KB
/
qot_updatekl.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
package futuapi
import (
"context"
"github.com/headshot289/go-futu-api/pb/qotcommon"
"github.com/headshot289/go-futu-api/pb/qotupdatekl"
"github.com/headshot289/go-futu-api/protocol"
"google.golang.org/protobuf/proto"
)
const (
ProtoIDQotUpdateKL = 3007 //Qot_UpdateKL 推送 K 线
)
// 实时 K 线回调
func (api *FutuAPI) UpdateKL(ctx context.Context) (<-chan *UpdateKLResp, error) {
ch := make(updateKLChan)
if err := api.update(ProtoIDQotUpdateKL, ch); err != nil {
return nil, err
}
return ch, nil
}
type UpdateKLResp struct {
KLine *RTKLine
Err error
}
type updateKLChan chan *UpdateKLResp
var _ protocol.RespChan = make(updateKLChan)
func (ch updateKLChan) Send(b []byte) error {
var resp qotupdatekl.Response
if err := proto.Unmarshal(b, &resp); err != nil {
return err
}
ch <- &UpdateKLResp{
KLine: rtKLineFromUpdatePB(resp.GetS2C()),
Err: protocol.Error(&resp),
}
return nil
}
func (ch updateKLChan) Close() {
close(ch)
}
func rtKLineFromUpdatePB(pb *qotupdatekl.S2C) *RTKLine {
if pb == nil {
return nil
}
return &RTKLine{
RehabType: qotcommon.RehabType(pb.GetRehabType()),
KLType: qotcommon.KLType(pb.GetKlType()),
Security: securityFromPB(pb.GetSecurity()),
KLines: kLineListFromPB(pb.GetKlList()),
}
}