forked from binance/binance-connector-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstaking.go
517 lines (466 loc) · 13.3 KB
/
staking.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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
package binance_connector
import (
"context"
"encoding/json"
"net/http"
)
// Get Staking Product List (USER_DATA)
type GetStakingProductListService struct {
c *Client
product string
asset *string
current *int64
size *int64
}
// Product set product
func (s *GetStakingProductListService) Product(product string) *GetStakingProductListService {
s.product = product
return s
}
// Asset set asset
func (s *GetStakingProductListService) Asset(asset string) *GetStakingProductListService {
s.asset = &asset
return s
}
// Current set current
func (s *GetStakingProductListService) Current(current int64) *GetStakingProductListService {
s.current = ¤t
return s
}
// Size set size
func (s *GetStakingProductListService) Size(size int64) *GetStakingProductListService {
s.size = &size
return s
}
// Do send request
func (s *GetStakingProductListService) Do(ctx context.Context, opts ...RequestOption) (res []*StakingProductListResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/staking/productList",
secType: secTypeSigned,
}
r.setParam("product", s.product)
if s.asset != nil {
r.setParam("asset", *s.asset)
}
if s.current != nil {
r.setParam("current", *s.current)
}
if s.size != nil {
r.setParam("size", *s.size)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = make([]*StakingProductListResponse, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
// StakingProductListResponse define staking product list response
type StakingProductListResponse struct {
ProjectId string `json:"projectId"`
Detail struct {
Asset string `json:"asset"`
RewardAsset string `json:"rewardAsset"`
Duration int64 `json:"duration"`
Renewable bool `json:"renewable"`
Apy string `json:"apy"`
} `json:"detail"`
Quota struct {
TotalPersonalQuota string `json:"totalPersonalQuota"`
Minimum string `json:"minimum"`
} `json:"quota"`
}
// Purchase Staking Product(USER_DATA)
type PurchaseStakingProductService struct {
c *Client
product string
productId string
amount float64
renewable *string
}
// Product set product
func (s *PurchaseStakingProductService) Product(product string) *PurchaseStakingProductService {
s.product = product
return s
}
// ProductId set productId
func (s *PurchaseStakingProductService) ProductId(productId string) *PurchaseStakingProductService {
s.productId = productId
return s
}
// Amount set amount
func (s *PurchaseStakingProductService) Amount(amount float64) *PurchaseStakingProductService {
s.amount = amount
return s
}
// Renewable set renewable
func (s *PurchaseStakingProductService) Renewable(renewable string) *PurchaseStakingProductService {
s.renewable = &renewable
return s
}
// Do send request
func (s *PurchaseStakingProductService) Do(ctx context.Context, opts ...RequestOption) (res *PurchaseStakingProductResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/sapi/v1/staking/purchase",
secType: secTypeSigned,
}
r.setParam("product", s.product)
r.setParam("productId", s.productId)
r.setParam("amount", s.amount)
if s.renewable != nil {
r.setParam("renewable", *s.renewable)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(PurchaseStakingProductResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// PurchaseStakingProductResponse define purchase staking product response
type PurchaseStakingProductResponse struct {
PositionId string `json:"positionId"`
Success bool `json:"success"`
}
// Redeem Staking Product(USER_DATA)
type RedeemStakingProductService struct {
c *Client
product string
positionId *string
productId string
amount *float64
}
// Product set product
func (s *RedeemStakingProductService) Product(product string) *RedeemStakingProductService {
s.product = product
return s
}
// PositionId set positionId
func (s *RedeemStakingProductService) PositionId(positionId string) *RedeemStakingProductService {
s.positionId = &positionId
return s
}
// ProductId set productId
func (s *RedeemStakingProductService) ProductId(productId string) *RedeemStakingProductService {
s.productId = productId
return s
}
// Amount set amount
func (s *RedeemStakingProductService) Amount(amount float64) *RedeemStakingProductService {
s.amount = &amount
return s
}
// Do send request
func (s *RedeemStakingProductService) Do(ctx context.Context, opts ...RequestOption) (res *RedeemStakingProductResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/sapi/v1/staking/redeem",
secType: secTypeSigned,
}
r.setParam("product", s.product)
if s.positionId != nil {
r.setParam("positionId", *s.positionId)
}
r.setParam("productId", s.productId)
if s.amount != nil {
r.setParam("amount", *s.amount)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(RedeemStakingProductResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// RedeemStakingProductResponse define redeem staking product response
type RedeemStakingProductResponse struct {
Success bool `json:"success"`
}
// Get Staking Product Position(USER_DATA)
type GetStakingProductPositionService struct {
c *Client
product string
productId *string
asset *string
current *int64
size *int64
}
// Product set product
func (s *GetStakingProductPositionService) Product(product string) *GetStakingProductPositionService {
s.product = product
return s
}
// ProductId set productId
func (s *GetStakingProductPositionService) ProductId(productId string) *GetStakingProductPositionService {
s.productId = &productId
return s
}
// Asset set asset
func (s *GetStakingProductPositionService) Asset(asset string) *GetStakingProductPositionService {
s.asset = &asset
return s
}
// Current set current
func (s *GetStakingProductPositionService) Current(current int64) *GetStakingProductPositionService {
s.current = ¤t
return s
}
// Size set size
func (s *GetStakingProductPositionService) Size(size int64) *GetStakingProductPositionService {
s.size = &size
return s
}
// Do send request
func (s *GetStakingProductPositionService) Do(ctx context.Context, opts ...RequestOption) (res []*GetStakingProductPositionResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/staking/position",
secType: secTypeSigned,
}
r.setParam("product", s.product)
if s.productId != nil {
r.setParam("productId", *s.productId)
}
if s.asset != nil {
r.setParam("asset", *s.asset)
}
if s.current != nil {
r.setParam("current", *s.current)
}
if s.size != nil {
r.setParam("size", *s.size)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = make([]*GetStakingProductPositionResponse, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
// GetStakingProductPositionResponse define get staking product position response
type GetStakingProductPositionResponse struct {
PositionId string `json:"positionId"`
ProjectId string `json:"projectId"`
Asset string `json:"asset"`
Amount string `json:"amount"`
PurchaseTime string `json:"purchaseTime"`
Duration string `json:"duration"`
AccrualDays string `json:"accrualDays"`
RewardAsset string `json:"rewardAsset"`
APY string `json:"APY"`
RewardAmt string `json:"rewardAmt"`
ExtraRewardAsset string `json:"extraRewardAsset"`
ExtraRewardAPY string `json:"extraRewardAPY"`
EstExtraRewardAmt string `json:"estExtraRewardAmt"`
NextInterestPay string `json:"nextInterestPay"`
NextInterestPayDate string `json:"nextInterestPayDate"`
PayInterestPeriod string `json:"payInterestPeriod"`
RedeemAmountEarly string `json:"redeemAmountEarly"`
InterestEndDate string `json:"interestEndDate"`
DeliverDate string `json:"deliverDate"`
RedeemPeriod string `json:"redeemPeriod"`
RedeemingAmt string `json:"redeemingAmt"`
PartialAmtDeliverDate string `json:"partialAmtDeliverDate"`
CanRedeemEarly bool `json:"canRedeemEarly"`
Renewable bool `json:"renewable"`
Type string `json:"type"`
Status string `json:"status"`
}
// Get Staking History(USER_DATA)
type GetStakingHistoryService struct {
c *Client
product string
txnType string
asset *string
startTime *uint64
endTime *uint64
current *int64
size *int64
}
// Product set product
func (s *GetStakingHistoryService) Product(product string) *GetStakingHistoryService {
s.product = product
return s
}
// TxnType set txnType
func (s *GetStakingHistoryService) TxnType(txnType string) *GetStakingHistoryService {
s.txnType = txnType
return s
}
// Asset set asset
func (s *GetStakingHistoryService) Asset(asset string) *GetStakingHistoryService {
s.asset = &asset
return s
}
// StartTime set startTime
func (s *GetStakingHistoryService) StartTime(startTime uint64) *GetStakingHistoryService {
s.startTime = &startTime
return s
}
// EndTime set endTime
func (s *GetStakingHistoryService) EndTime(endTime uint64) *GetStakingHistoryService {
s.endTime = &endTime
return s
}
// Current set current
func (s *GetStakingHistoryService) Current(current int64) *GetStakingHistoryService {
s.current = ¤t
return s
}
// Size set size
func (s *GetStakingHistoryService) Size(size int64) *GetStakingHistoryService {
s.size = &size
return s
}
// Do send request
func (s *GetStakingHistoryService) Do(ctx context.Context, opts ...RequestOption) (res []*GetStakingHistoryResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/staking/stakingRecord",
secType: secTypeSigned,
}
r.setParam("product", s.product)
r.setParam("type", s.txnType)
if s.asset != nil {
r.setParam("asset", *s.asset)
}
if s.startTime != nil {
r.setParam("startTime", *s.startTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.current != nil {
r.setParam("current", *s.current)
}
if s.size != nil {
r.setParam("size", *s.size)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = make([]*GetStakingHistoryResponse, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
// GetStakingHistoryResponse define get staking history response
type GetStakingHistoryResponse struct {
PositionId string `json:"positionId"`
Time uint64 `json:"time"`
Asset string `json:"asset"`
Project string `json:"project"`
Amount string `json:"amount"`
LockPeriod string `json:"lockPeriod"`
DeliverDate string `json:"deliverDate"`
Type string `json:"type"`
Status string `json:"status"`
}
// Set Auto Staking(USER_DATA)
type SetAutoStakingService struct {
c *Client
product string
positionId string
renewable string
}
// Product set product
func (s *SetAutoStakingService) Product(product string) *SetAutoStakingService {
s.product = product
return s
}
// PositionId set positionId
func (s *SetAutoStakingService) PositionId(positionId string) *SetAutoStakingService {
s.positionId = positionId
return s
}
// Renewable set renewable
func (s *SetAutoStakingService) Renewable(renewable string) *SetAutoStakingService {
s.renewable = renewable
return s
}
// Do send request
func (s *SetAutoStakingService) Do(ctx context.Context, opts ...RequestOption) (res *SetAutoStakingResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/sapi/v1/staking/setAutoStaking",
secType: secTypeSigned,
}
r.setParam("product", s.product)
r.setParam("positionId", s.positionId)
r.setParam("renewable", s.renewable)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(SetAutoStakingResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// SetAutoStakingResponse define set auto staking response
type SetAutoStakingResponse struct {
Success bool `json:"success"`
}
// Get Personal Left Quota of Staking Product(USER_DATA)
type PersonalLeftQuotaService struct {
c *Client
product string
productId string
}
// Product set product
func (s *PersonalLeftQuotaService) Product(product string) *PersonalLeftQuotaService {
s.product = product
return s
}
// ProductId set productId
func (s *PersonalLeftQuotaService) ProductId(productId string) *PersonalLeftQuotaService {
s.productId = productId
return s
}
// Do send request
func (s *PersonalLeftQuotaService) Do(ctx context.Context, opts ...RequestOption) (res []*PersonalLeftQuotaResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/staking/personalLeftQuota",
secType: secTypeSigned,
}
r.setParam("product", s.product)
r.setParam("productId", s.productId)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = make([]*PersonalLeftQuotaResponse, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
// PersonalLeftQuotaResponse define get staking asset response
type PersonalLeftQuotaResponse struct {
LeftPersonalQuota string `json:"leftPersonalQuota"`
}