-
Notifications
You must be signed in to change notification settings - Fork 36
/
trd_getfunds.go
51 lines (43 loc) · 1.18 KB
/
trd_getfunds.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/hurisheng/go-futu-api/pb/trdcommon"
"github.com/hurisheng/go-futu-api/pb/trdgetfunds"
"github.com/hurisheng/go-futu-api/protocol"
"google.golang.org/protobuf/proto"
)
const ProtoIDTrdGetFunds = 2101 //Trd_GetFunds 获取账户资金
func init() {
workers[ProtoIDTrdGetFunds] = protocol.NewGetter()
}
// 查询账户资金
func (api *FutuAPI) GetFunds(ctx context.Context, header *trdcommon.TrdHeader,
refresh *OptionalBool, currency trdcommon.Currency) (*trdcommon.Funds, error) {
if header == nil {
return nil, ErrParameters
}
req := &trdgetfunds.Request{
C2S: &trdgetfunds.C2S{
Header: header,
},
}
if refresh != nil {
req.C2S.RefreshCache = proto.Bool(refresh.Value)
}
if currency != trdcommon.Currency_Currency_Unknown {
req.C2S.Currency = proto.Int32(int32(currency))
}
ch := make(chan *trdgetfunds.Response)
if err := api.proto.RegisterGet(ProtoIDTrdGetFunds, 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().GetFunds(), protocol.Error(resp)
}
}