-
Notifications
You must be signed in to change notification settings - Fork 36
/
qot_getsecuritysnapshot.go
42 lines (37 loc) · 1.1 KB
/
qot_getsecuritysnapshot.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
package futuapi
import (
"context"
"github.com/hurisheng/go-futu-api/pb/qotcommon"
"github.com/hurisheng/go-futu-api/pb/qotgetsecuritysnapshot"
"github.com/hurisheng/go-futu-api/protocol"
)
const ProtoIDQotGetSecuritySnapshot = 3203 //Qot_GetSecuritySnapshot 获取股票快照
func init() {
workers[ProtoIDQotGetSecuritySnapshot] = protocol.NewGetter()
}
// 获取快照
func (api *FutuAPI) GetMarketSnapshot(ctx context.Context, securities []*qotcommon.Security) ([]*qotgetsecuritysnapshot.Snapshot, error) {
if len(securities) == 0 {
return nil, ErrParameters
}
// 请求参数
req := &qotgetsecuritysnapshot.Request{
C2S: &qotgetsecuritysnapshot.C2S{
SecurityList: securities,
},
}
// 发送请求,同步返回结果
ch := make(chan *qotgetsecuritysnapshot.Response)
if err := api.proto.RegisterGet(ProtoIDQotGetSecuritySnapshot, 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().GetSnapshotList(), protocol.Error(resp)
}
}