-
Notifications
You must be signed in to change notification settings - Fork 36
/
trd_getorderlist.go
54 lines (47 loc) · 1.35 KB
/
trd_getorderlist.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
package futuapi
import (
"context"
"github.com/hurisheng/go-futu-api/pb/trdcommon"
"github.com/hurisheng/go-futu-api/pb/trdgetorderlist"
"github.com/hurisheng/go-futu-api/protocol"
"google.golang.org/protobuf/proto"
)
const ProtoIDTrdGetOrderList = 2201 //Trd_GetOrderList 获取订单列表
func init() {
workers[ProtoIDTrdGetOrderList] = protocol.NewGetter()
}
// 查询今日订单
func (api *FutuAPI) GetOrderList(ctx context.Context, header *trdcommon.TrdHeader,
filter *trdcommon.TrdFilterConditions, status []trdcommon.OrderStatus, refresh *OptionalBool) ([]*trdcommon.Order, error) {
if header == nil {
return nil, ErrParameters
}
req := &trdgetorderlist.Request{
C2S: &trdgetorderlist.C2S{
Header: header,
FilterConditions: filter,
},
}
if len(status) != 0 {
req.C2S.FilterStatusList = make([]int32, len(status))
for i, v := range status {
req.C2S.FilterStatusList[i] = int32(v)
}
}
if refresh != nil {
req.C2S.RefreshCache = proto.Bool(refresh.Value)
}
ch := make(chan *trdgetorderlist.Response)
if err := api.proto.RegisterGet(ProtoIDTrdGetOrderList, 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().GetOrderList(), protocol.Error(resp)
}
}