forked from adshao/go-binance
/
savings_service.go
296 lines (265 loc) · 8.42 KB
/
savings_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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package binance
import (
"context"
"net/http"
)
// ListSavingsFlexibleProductsService https://binance-docs.github.io/apidocs/spot/en/#get-flexible-product-list-user_data
type ListSavingsFlexibleProductsService struct {
c *Client
status string
featured string
current int64
size int64
}
// Status represent the product status ("ALL", "SUBSCRIBABLE", "UNSUBSCRIBABLE") - Default: "ALL"
func (s *ListSavingsFlexibleProductsService) Status(status string) *ListSavingsFlexibleProductsService {
s.status = status
return s
}
// Featured ("ALL", "TRUE") - Default: "ALL"
func (s *ListSavingsFlexibleProductsService) Featured(featured string) *ListSavingsFlexibleProductsService {
s.featured = featured
return s
}
// Current query page. Default: 1, Min: 1
func (s *ListSavingsFlexibleProductsService) Current(current int64) *ListSavingsFlexibleProductsService {
s.current = current
return s
}
// Size Default: 50, Max: 100
func (s *ListSavingsFlexibleProductsService) Size(size int64) *ListSavingsFlexibleProductsService {
s.size = size
return s
}
// Do send request
func (s *ListSavingsFlexibleProductsService) Do(ctx context.Context, opts ...RequestOption) ([]*SavingsFlexibleProduct, error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/lending/daily/product/list",
secType: secTypeSigned,
}
m := params{}
if s.status != "" {
m["status"] = s.status
}
if s.featured != "" {
m["featured"] = s.featured
}
if s.current != 0 {
m["current"] = s.current
}
if s.size != 0 {
m["size"] = s.size
}
r.setParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
var res []*SavingsFlexibleProduct
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
// SavingsFlexibleProduct define a flexible product (Savings)
type SavingsFlexibleProduct struct {
Asset string `json:"asset"`
AvgAnnualInterestRate string `json:"avgAnnualInterestRate"`
CanPurchase bool `json:"canPurchase"`
CanRedeem bool `json:"canRedeem"`
DailyInterestPerThousand string `json:"dailyInterestPerThousand"`
Featured bool `json:"featured"`
MinPurchaseAmount string `json:"minPurchaseAmount"`
ProductId string `json:"productId"`
PurchasedAmount string `json:"purchasedAmount"`
Status string `json:"status"`
UpLimit string `json:"upLimit"`
UpLimitPerUser string `json:"upLimitPerUser"`
}
// PurchaseSavingsFlexibleProductService https://binance-docs.github.io/apidocs/spot/en/#purchase-flexible-product-user_data
type PurchaseSavingsFlexibleProductService struct {
c *Client
productId string
amount float64
}
// ProductId represent the id of the flexible product to purchase
func (s *PurchaseSavingsFlexibleProductService) ProductId(productId string) *PurchaseSavingsFlexibleProductService {
s.productId = productId
return s
}
// Amount is the quantity of the product to purchase
func (s *PurchaseSavingsFlexibleProductService) Amount(amount float64) *PurchaseSavingsFlexibleProductService {
s.amount = amount
return s
}
// Do send request
func (s *PurchaseSavingsFlexibleProductService) Do(ctx context.Context, opts ...RequestOption) (uint64, error) {
r := &request{
method: http.MethodPost,
endpoint: "/sapi/v1/lending/daily/purchase",
secType: secTypeSigned,
}
m := params{
"productId": s.productId,
"amount": s.amount,
}
r.setParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return 0, err
}
var res *PurchaseSavingsFlexibleProductResponse
if err = json.Unmarshal(data, &res); err != nil {
return 0, err
}
return res.PurchaseId, nil
}
type PurchaseSavingsFlexibleProductResponse struct {
PurchaseId uint64 `json:"purchaseId"`
}
// RedeemSavingsFlexibleProductService https://binance-docs.github.io/apidocs/spot/en/#redeem-flexible-product-user_data
type RedeemSavingsFlexibleProductService struct {
c *Client
productId string
amount float64
redeemType string
}
// ProductId represent the id of the flexible product to redeem
func (s *RedeemSavingsFlexibleProductService) ProductId(productId string) *RedeemSavingsFlexibleProductService {
s.productId = productId
return s
}
// Amount is the quantity of the product to redeem
func (s *RedeemSavingsFlexibleProductService) Amount(amount float64) *RedeemSavingsFlexibleProductService {
s.amount = amount
return s
}
// Type ("FAST", "NORMAL")
func (s *RedeemSavingsFlexibleProductService) Type(redeemType string) *RedeemSavingsFlexibleProductService {
s.redeemType = redeemType
return s
}
// Do send request
func (s *RedeemSavingsFlexibleProductService) Do(ctx context.Context, opts ...RequestOption) error {
r := &request{
method: http.MethodPost,
endpoint: "/sapi/v1/lending/daily/redeem",
secType: secTypeSigned,
}
m := params{
"productId": s.productId,
"amount": s.amount,
}
if s.redeemType != "" {
m["type"] = s.redeemType
}
r.setParams(m)
_, err := s.c.callAPI(ctx, r, opts...)
return err
}
// ListSavingsFixedAndActivityProductsService https://binance-docs.github.io/apidocs/spot/en/#get-fixed-and-activity-project-list-user_data
type ListSavingsFixedAndActivityProductsService struct {
c *Client
asset string
projectType string
status string
isSortAsc bool
sortBy string
current int64
size int64
}
// Asset desired asset
func (s *ListSavingsFixedAndActivityProductsService) Asset(asset string) *ListSavingsFixedAndActivityProductsService {
s.asset = asset
return s
}
// Type set project type ("ACTIVITY", "CUSTOMIZED_FIXED")
func (s *ListSavingsFixedAndActivityProductsService) Type(projectType string) *ListSavingsFixedAndActivityProductsService {
s.projectType = projectType
return s
}
// IsSortAsc default "true"
func (s *ListSavingsFixedAndActivityProductsService) IsSortAsc(isSortAsc bool) *ListSavingsFixedAndActivityProductsService {
s.isSortAsc = isSortAsc
return s
}
// Status ("ALL", "SUBSCRIBABLE", "UNSUBSCRIBABLE") - default "ALL"
func (s *ListSavingsFixedAndActivityProductsService) Status(status string) *ListSavingsFixedAndActivityProductsService {
s.status = status
return s
}
// SortBy ("START_TIME", "LOT_SIZE", "INTEREST_RATE", "DURATION") - default "START_TIME"
func (s *ListSavingsFixedAndActivityProductsService) SortBy(sortBy string) *ListSavingsFixedAndActivityProductsService {
s.sortBy = sortBy
return s
}
// Current Currently querying page. Start from 1. Default:1
func (s *ListSavingsFixedAndActivityProductsService) Current(current int64) *ListSavingsFixedAndActivityProductsService {
s.current = current
return s
}
// Size Default:10, Max:100
func (s *ListSavingsFixedAndActivityProductsService) Size(size int64) *ListSavingsFixedAndActivityProductsService {
s.size = size
return s
}
// Do send request
func (s *ListSavingsFixedAndActivityProductsService) Do(ctx context.Context, opts ...RequestOption) ([]*SavingsFixedProduct, error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/lending/project/list",
secType: secTypeSigned,
}
m := params{
"type": s.projectType,
}
if s.asset != "" {
m["asset"] = s.asset
}
if s.status != "" {
m["status"] = s.status
}
if s.isSortAsc != true {
m["isSortAsc"] = s.isSortAsc
}
if s.sortBy != "" {
m["sortBy"] = s.sortBy
}
if s.current != 1 {
m["current"] = s.current
}
if s.size != 10 {
m["size"] = s.size
}
r.setParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
var res []*SavingsFixedProduct
if err = json.Unmarshal(data, &res); err != nil {
return nil, err
}
return res, nil
}
// SavingsFixedProduct define a fixed product (Savings)
type SavingsFixedProduct struct {
Asset string `json:"asset"`
DisplayPriority int `json:"displayPriority"`
Duration int `json:"duration"`
InterestPerLot string `json:"interestPerLot"`
InterestRate string `json:"interestRate"`
LotSize string `json:"lotSize"`
LotsLowLimit int `json:"lotsLowLimit"`
LotsPurchased int `json:"lotsPurchased"`
LotsUpLimit int `json:"lotsUpLimit"`
MaxLotsPerUser int `json:"maxLotsPerUser"`
NeedKyc bool `json:"needKyc"`
ProjectId string `json:"projectId"`
ProjectName string `json:"projectName"`
Status string `json:"status"`
Type string `json:"type"`
WithAreaLimitation bool `json:"withAreaLimitation"`
}