forked from hurisheng/go-futu-api
/
qot_updateticker.go
56 lines (47 loc) · 1.23 KB
/
qot_updateticker.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
package futuapi
import (
"context"
"github.com/headshot289/go-futu-api/pb/qotupdateticker"
"github.com/headshot289/go-futu-api/protocol"
"google.golang.org/protobuf/proto"
)
const (
ProtoIDQotUpdateTicker = 3011 //Qot_UpdateTicker 推送逐笔
)
// 实时逐笔回调,异步处理已订阅股票的实时逐笔推送
func (api *FutuAPI) UpdateTicker(ctx context.Context) (<-chan *UpdateTickerResp, error) {
ch := make(updateTickerChan)
if err := api.update(ProtoIDQotUpdateTicker, ch); err != nil {
return nil, err
}
return ch, nil
}
type UpdateTickerResp struct {
Ticker *RTTicker
Err error
}
type updateTickerChan chan *UpdateTickerResp
var _ protocol.RespChan = make(updateTickerChan)
func (ch updateTickerChan) Send(b []byte) error {
var resp qotupdateticker.Response
if err := proto.Unmarshal(b, &resp); err != nil {
return err
}
ch <- &UpdateTickerResp{
Ticker: rtTickerFromUpdatePB(resp.GetS2C()),
Err: protocol.Error(&resp),
}
return nil
}
func (ch updateTickerChan) Close() {
close(ch)
}
func rtTickerFromUpdatePB(pb *qotupdateticker.S2C) *RTTicker {
if pb == nil {
return nil
}
return &RTTicker{
Security: securityFromPB(pb.GetSecurity()),
Tickers: tickerListFromPB(pb.GetTickerList()),
}
}