-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathqot_getorderbook.go
45 lines (39 loc) · 1.08 KB
/
qot_getorderbook.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
package futuapi
import (
"context"
"github.com/hurisheng/go-futu-api/pb/qotcommon"
"github.com/hurisheng/go-futu-api/pb/qotgetorderbook"
"github.com/hurisheng/go-futu-api/protocol"
"google.golang.org/protobuf/proto"
)
const ProtoIDQotGetOrderBook = 3012 //Qot_GetOrderBook 获取买卖盘
func init() {
workers[ProtoIDQotGetOrderBook] = protocol.NewGetter()
}
// 获取实时摆盘
func (api *FutuAPI) GetOrderBook(ctx context.Context, security *qotcommon.Security, num int32) (*qotgetorderbook.S2C, error) {
if security == nil {
return nil, ErrParameters
}
// 请求参数
req := &qotgetorderbook.Request{
C2S: &qotgetorderbook.C2S{
Security: security,
Num: proto.Int32(num),
},
}
// 发送请求,同步返回结果
ch := make(chan *qotgetorderbook.Response)
if err := api.proto.RegisterGet(ProtoIDQotGetOrderBook, req, protocol.NewProtobufChan(ch)); err != nil {
return nil, err
}
select {
case <-ctx.Done():
return nil, ErrInterrupted
case resp, ok := <-ch:
if !ok {
return nil, ErrChannelClosed
}
return resp.GetS2C(), protocol.Error(resp)
}
}