-
Notifications
You must be signed in to change notification settings - Fork 3
/
mining_service.go
124 lines (108 loc) · 2.64 KB
/
mining_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
package binance
import (
"context"
"encoding/json"
"log"
"net/http"
)
// GetAccountService get account info
type GetMiningService struct {
c *Client
algo string
userName string
coin *string
startDate *string
endDate *string
pageIndex *string
pageSize *string
recvWindow *string
}
func (s *GetMiningService) Algo(algo string) *GetMiningService {
s.algo = algo
return s
}
func (s *GetMiningService) UserName(userName string) *GetMiningService {
s.userName = userName
return s
}
func (s *GetMiningService) Coin(coin string) *GetMiningService {
s.coin = &coin
return s
}
func (s *GetMiningService) StartDate(startDate string) *GetMiningService {
s.startDate = &startDate
return s
}
func (s *GetMiningService) EndDate(endDate string) *GetMiningService {
s.endDate = &endDate
return s
}
func (s *GetMiningService) PageIndex(pageIndex string) *GetMiningService {
s.pageIndex = &pageIndex
return s
}
func (s *GetMiningService) PageSize(pageSize string) *GetMiningService {
s.pageSize = &pageSize
return s
}
func (s *GetMiningService) RecvWindow(recvWindow string) *GetMiningService {
s.recvWindow = &recvWindow
return s
}
type MiningResponse struct {
AccountProfits []struct {
Time int64 `json:"time"`
Type int `json:"type"`
HashTransfer interface{} `json:"hashTransfer"`
TransferAmount interface{} `json:"transferAmount"`
DayHashRate int64 `json:"dayHashRate"`
ProfitAmount float64 `json:"profitAmount"`
CoinName string `json:"coinName"`
Status int `json:"status"`
} `json:"accountProfits"`
TotalNum int `json:"totalNum"`
PageSize int `json:"pageSize"`
}
// Do send request
func (s *GetMiningService) Do(ctx context.Context, opts ...RequestOption) (res *MiningResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/mining/payment/list",
secType: secTypeSigned,
}
if s.algo != "" {
r.setParam("algo", s.algo)
}
if s.userName != "" {
r.setParam("userName", s.userName)
}
if s.coin != nil {
r.setParam("coin", *s.coin)
}
if s.startDate != nil {
r.setParam("startDate", *s.startDate)
}
if s.endDate != nil {
r.setParam("endDate", *s.endDate)
}
if s.pageIndex != nil {
r.setParam("pageIndex", *s.pageIndex)
}
if s.pageSize != nil {
r.setParam("pageSize", *s.pageSize)
}
if s.recvWindow != nil {
r.setParam("recvWindow", *s.recvWindow)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
log.Println("data", string(data))
res = new(MiningResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}