forked from hurisheng/go-futu-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrd_getfunds.go
39 lines (35 loc) · 925 Bytes
/
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
package futuapi
import (
"context"
"github.com/headshot289/go-futu-api/pb/trdcommon"
"github.com/headshot289/go-futu-api/pb/trdgetfunds"
"github.com/headshot289/go-futu-api/protocol"
)
const (
ProtoIDTrdGetFunds = 2101 //Trd_GetFunds 获取账户资金
)
// 查询账户资金
func (api *FutuAPI) GetFunds(ctx context.Context, header *TrdHeader, refresh bool, currency trdcommon.Currency) (*Funds, error) {
req := trdgetfunds.Request{
C2S: &trdgetfunds.C2S{
Header: header.pb(),
RefreshCache: &refresh,
},
}
if currency != 0 {
req.C2S.Currency = (*int32)(¤cy)
}
ch := make(trdgetfunds.ResponseChan)
if err := api.get(ProtoIDTrdGetFunds, &req, ch); err != nil {
return nil, err
}
select {
case <-ctx.Done():
return nil, ErrInterrupted
case resp, ok := <-ch:
if !ok {
return nil, ErrChannelClosed
}
return fundsFromPB(resp.GetS2C().GetFunds()), protocol.Error(resp)
}
}