-
Notifications
You must be signed in to change notification settings - Fork 1
/
subaccount_service.go
197 lines (172 loc) · 4.68 KB
/
subaccount_service.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
package binance
import (
"context"
"encoding/json"
)
// TransferToSubAccountService transfer to subaccount
type TransferToSubAccountService struct {
c *Client
toEmail string
asset string
amount string
}
// ToEmail set toEmail
func (s *TransferToSubAccountService) ToEmail(toEmail string) *TransferToSubAccountService {
s.toEmail = toEmail
return s
}
// Asset set asset
func (s *TransferToSubAccountService) Asset(asset string) *TransferToSubAccountService {
s.asset = asset
return s
}
// Amount set amount
func (s *TransferToSubAccountService) Amount(amount string) *TransferToSubAccountService {
s.amount = amount
return s
}
func (s *TransferToSubAccountService) transferToSubaccount(ctx context.Context, endpoint string, opts ...RequestOption) (data []byte, err error) {
r := &request{
method: "POST",
endpoint: endpoint,
secType: secTypeSigned,
}
m := params{
"toEmail": s.toEmail,
"asset": s.asset,
"amount": s.amount,
}
r.setParams(m)
data, err = s.c.callAPI(ctx, r, opts...)
if err != nil {
return []byte{}, err
}
return data, nil
}
// Do send request
func (s *TransferToSubAccountService) Do(ctx context.Context, opts ...RequestOption) (res *TransferToSubAccountResponse, err error) {
data, err := s.transferToSubaccount(ctx, "/sapi/v1/sub-account/transfer/subToSub", opts...)
if err != nil {
return nil, err
}
res = &TransferToSubAccountResponse{}
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// TransferToSubAccountResponse define transfer to subaccount response
type TransferToSubAccountResponse struct {
TxnID int64 `json:"txnId"`
}
type SubaccountAssetsService struct {
c *Client
email string
}
// Email set email
func (s *SubaccountAssetsService) Email(email string) *SubaccountAssetsService {
s.email = email
return s
}
func (s *SubaccountAssetsService) subaccountAssets(ctx context.Context, endpoint string, opts ...RequestOption) (data []byte, err error) {
r := &request{
method: "GET",
endpoint: endpoint,
secType: secTypeSigned,
}
m := params{
"email": s.email,
}
r.setParams(m)
data, err = s.c.callAPI(ctx, r, opts...)
if err != nil {
return []byte{}, err
}
return data, nil
}
// Do send request
func (s *SubaccountAssetsService) Do(ctx context.Context, opts ...RequestOption) (res *SubaccountAssetsResponse, err error) {
data, err := s.subaccountAssets(ctx, "/sapi/v3/sub-account/assets", opts...)
if err != nil {
return nil, err
}
res = &SubaccountAssetsResponse{}
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// TransferToSubAccountResponse define transfer to subaccount response
type SubaccountAssetsResponse struct {
Balances []AssetBalance `json:"balances"`
}
type AssetBalance struct {
Asset string `json:"asset"`
Free float64 `json:"free"`
Locked float64 `json:"locked"`
}
type SubaccountSpotSummaryService struct {
c *Client
email *string
page *int32
size *int32
}
// Email set email
func (s *SubaccountSpotSummaryService) Email(email string) *SubaccountSpotSummaryService {
s.email = &email
return s
}
func (s *SubaccountSpotSummaryService) Page(page int32) *SubaccountSpotSummaryService {
s.page = &page
return s
}
func (s *SubaccountSpotSummaryService) Size(size int32) *SubaccountSpotSummaryService {
s.size = &size
return s
}
func (s *SubaccountSpotSummaryService) subaccountSpotSummary(ctx context.Context, endpoint string, opts ...RequestOption) (data []byte, err error) {
r := &request{
method: "GET",
endpoint: endpoint,
secType: secTypeSigned,
}
if s.size != nil {
r.setParam("size", *s.size)
}
if s.page != nil {
r.setParam("page", *s.page)
}
if s.email != nil {
r.setParam("email", *s.email)
}
data, err = s.c.callAPI(ctx, r, opts...)
if err != nil {
return []byte{}, err
}
return data, nil
}
// Do send request
func (s *SubaccountSpotSummaryService) Do(ctx context.Context, opts ...RequestOption) (res *SubaccountSpotSummaryResponse, err error) {
data, err := s.subaccountSpotSummary(ctx, "/sapi/v1/sub-account/spotSummary", opts...)
if err != nil {
return nil, err
}
res = &SubaccountSpotSummaryResponse{}
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// TransferToSubAccountResponse define transfer to subaccount response
type SubaccountSpotSummaryResponse struct {
TotalCount int64 `json:"totalCount"`
MasterAccountTotalAsset string `json:"masterAccountTotalAsset"`
SpotSubUserAssetBtcVoList []SpotSubUserAssetBtcVoList `json:"spotSubUserAssetBtcVoList"`
}
type SpotSubUserAssetBtcVoList struct {
Email string `json:"email"`
TotalAsset string `json:"totalAsset"`
}