forked from hurisheng/go-futu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqot_updatebroker.go
58 lines (48 loc) · 1.28 KB
/
qot_updatebroker.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
package futuapi
import (
"context"
"github.com/headshot289/go-futu-api/pb/qotupdatebroker"
"github.com/headshot289/go-futu-api/protocol"
"google.golang.org/protobuf/proto"
)
const (
ProtoIDQotUpdateBroker = 3015 //Qot_UpdateBroker 推送经纪队列
)
// 实时经纪队列回调
func (api *FutuAPI) UpdateBroker(ctx context.Context) (<-chan *UpdateBrokerResp, error) {
ch := make(updateBrokerChan)
if err := api.update(ProtoIDQotUpdateBroker, ch); err != nil {
return nil, err
}
return ch, nil
}
type UpdateBrokerResp struct {
BrokerQueue *BrokerQueue
Err error
}
type updateBrokerChan chan *UpdateBrokerResp
var _ protocol.RespChan = make(updateBrokerChan)
func (ch updateBrokerChan) Send(b []byte) error {
var resp qotupdatebroker.Response
if err := proto.Unmarshal(b, &resp); err != nil {
return err
}
ch <- &UpdateBrokerResp{
BrokerQueue: brokerQueueFromUpdatePB(resp.GetS2C()),
Err: protocol.Error(&resp),
}
return nil
}
func (ch updateBrokerChan) Close() {
close(ch)
}
func brokerQueueFromUpdatePB(pb *qotupdatebroker.S2C) *BrokerQueue {
if pb == nil {
return nil
}
return &BrokerQueue{
Security: securityFromPB(pb.GetSecurity()),
Asks: brokerListFromPB(pb.GetBrokerAskList()),
Bids: brokerListFromPB(pb.GetBrokerBidList()),
}
}