forked from hurisheng/go-futu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqot_getmarketstate.go
65 lines (58 loc) · 1.62 KB
/
qot_getmarketstate.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
61
62
63
64
65
package futuapi
import (
"context"
"github.com/headshot289/go-futu-api/pb/qotcommon"
"github.com/headshot289/go-futu-api/pb/qotgetmarketstate"
"github.com/headshot289/go-futu-api/protocol"
)
const (
ProtoIDQotGetMarketState = 3223 //Qot_GetMarketState 获取指定品种的市场状态
)
//获取标的市场状态
func (api *FutuAPI) GetMarketState(ctx context.Context, securities []*Security) ([]*MarketInfo, error) {
// 请求参数
req := qotgetmarketstate.Request{
C2S: &qotgetmarketstate.C2S{
SecurityList: securityList(securities).pb(),
},
}
// 发送请求,同步返回结果
ch := make(qotgetmarketstate.ResponseChan)
if err := api.get(ProtoIDQotGetMarketState, &req, ch); err != nil {
return nil, err
}
select {
case <-ctx.Done():
return nil, ErrInterrupted
case resp, ok := <-ch:
if !ok {
return nil, ErrChannelClosed
}
return marketInfoListFromPB(resp.GetS2C().GetMarketInfoList()), protocol.Error(resp)
}
}
func marketInfoListFromPB(pb []*qotgetmarketstate.MarketInfo) []*MarketInfo {
if pb == nil {
return nil
}
m := make([]*MarketInfo, len(pb))
for i, v := range pb {
m[i] = marketInfoFromPB(v)
}
return m
}
type MarketInfo struct {
Security *Security //股票代码
Name string // 股票名称
MarketState qotcommon.QotMarketState //Qot_Common.QotMarketState,市场状态
}
func marketInfoFromPB(pb *qotgetmarketstate.MarketInfo) *MarketInfo {
if pb == nil {
return nil
}
return &MarketInfo{
Security: securityFromPB(pb.GetSecurity()),
Name: pb.GetName(),
MarketState: qotcommon.QotMarketState(pb.GetMarketState()),
}
}