forked from hurisheng/go-futu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qot_getsubinfo.go
51 lines (45 loc) · 1.26 KB
/
qot_getsubinfo.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
package futuapi
import (
"context"
"github.com/Lawrence93Ho/go-futu-api/pb/qotgetsubinfo"
"github.com/Lawrence93Ho/go-futu-api/protocol"
)
const (
ProtoIDQotGetSubInfo = 3003 //Qot_GetSubInfo 获取订阅信息
)
// 获取订阅信息
func (api *FutuAPI) QuerySubscription(ctx context.Context, isAll bool) (*Subscription, error) {
// 请求参数
req := qotgetsubinfo.Request{C2S: &qotgetsubinfo.C2S{
IsReqAllConn: &isAll,
}}
// 发送请求,同步返回结果
ch := make(qotgetsubinfo.ResponseChan)
if err := api.get(ProtoIDQotGetSubInfo, &req, ch); err != nil {
return nil, err
}
select {
case <-ctx.Done():
return nil, ErrInterrupted
case resp, ok := <-ch:
if !ok {
return nil, ErrChannelClosed
}
return subscriptionFromPB(resp.GetS2C()), protocol.Error(resp)
}
}
type Subscription struct {
ConnSubInfos []*ConnSubInfo //单条连接订阅信息
TotalUsedQuota int32 //*FutuOpenD 已使用的订阅额度
RemainQuota int32 //*FutuOpenD 剩余订阅额度
}
func subscriptionFromPB(pb *qotgetsubinfo.S2C) *Subscription {
if pb == nil {
return nil
}
return &Subscription{
TotalUsedQuota: pb.GetTotalUsedQuota(),
RemainQuota: pb.GetRemainQuota(),
ConnSubInfos: connSubInfoListFromPB(pb.GetConnSubInfoList()),
}
}