forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asset_dividend_service.go
88 lines (79 loc) · 2.13 KB
/
asset_dividend_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
package binance
import (
"context"
"encoding/json"
)
// AssetDividendService fetches the saving purchases
type AssetDividendService struct {
c *Client
asset *string
startTime *int64
endTime *int64
limit *int
}
// Asset sets the asset parameter.
func (s *AssetDividendService) Asset(asset string) *AssetDividendService {
s.asset = &asset
return s
}
// Limit sets the limit parameter.
func (s *AssetDividendService) Limit(limit int) *AssetDividendService {
s.limit = &limit
return s
}
// StartTime sets the startTime parameter.
// If present, EndTime MUST be specified. The difference between EndTime - StartTime MUST be between 0-90 days.
func (s *AssetDividendService) StartTime(startTime int64) *AssetDividendService {
s.startTime = &startTime
return s
}
// EndTime sets the endTime parameter.
// If present, StartTime MUST be specified. The difference between EndTime - StartTime MUST be between 0-90 days.
func (s *AssetDividendService) EndTime(endTime int64) *AssetDividendService {
s.endTime = &endTime
return s
}
// Do sends the request.
func (s *AssetDividendService) Do(ctx context.Context) (*DividendResponseWrapper, error) {
r := &request{
method: "GET",
endpoint: "/sapi/v1/asset/assetDividend",
secType: secTypeSigned,
}
if s.asset != nil {
r.setParam("asset", *s.asset)
}
if s.limit != nil {
r.setParam("limit", *s.limit)
} else {
r.setParam("limit", 20)
}
if s.startTime != nil {
r.setParam("startTime", *s.startTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
data, err := s.c.callAPI(ctx, r)
if err != nil {
return nil, err
}
res := new(DividendResponseWrapper)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// DividendResponseWrapper represents a wrapper around a AssetDividendService.
type DividendResponseWrapper struct {
Rows *[]DividendResponse `json:"rows"`
}
// DividendResponse represents a response from AssetDividendService.
type DividendResponse struct {
Amount string `json:"amount"`
Asset string `json:"asset"`
Info string `json:"enInfo"`
Time int64 `json:"divTime"`
TranID int64 `json:"tranId"`
}