forked from ccxt/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeposit_service.go
174 lines (154 loc) · 4.2 KB
/
deposit_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
package binance
import (
"context"
"encoding/json"
"net/http"
)
// ListDepositsService fetches deposit history.
//
// See https://binance-docs.github.io/apidocs/spot/en/#deposit-history-user_data
type ListDepositsService struct {
c *Client
coin *string
status *int
startTime *int64
endTime *int64
offset *int
limit *int
txId *string
}
// Coin sets the coin parameter.
func (s *ListDepositsService) Coin(coin string) *ListDepositsService {
s.coin = &coin
return s
}
// Status sets the status parameter.
func (s *ListDepositsService) Status(status int) *ListDepositsService {
s.status = &status
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 *ListDepositsService) StartTime(startTime int64) *ListDepositsService {
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 *ListDepositsService) EndTime(endTime int64) *ListDepositsService {
s.endTime = &endTime
return s
}
// Offset set offset
func (s *ListDepositsService) Offset(offset int) *ListDepositsService {
s.offset = &offset
return s
}
// Limit set limit
func (s *ListDepositsService) Limit(limit int) *ListDepositsService {
s.limit = &limit
return s
}
func (s *ListDepositsService) TxID(id string) *ListDepositsService {
s.txId = &id
return s
}
// Do sends the request.
func (s *ListDepositsService) Do(ctx context.Context, opts ...RequestOption) (res []*Deposit, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/capital/deposit/hisrec",
secType: secTypeSigned,
}
if s.coin != nil {
r.setParam("coin", *s.coin)
}
if s.status != nil {
r.setParam("status", *s.status)
}
if s.startTime != nil {
r.setParam("startTime", *s.startTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.offset != nil {
r.setParam("offset", *s.offset)
}
if s.limit != nil {
r.setParam("limit", *s.limit)
}
if s.txId != nil {
r.setParam("txId", *s.txId)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return
}
res = make([]*Deposit, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return
}
return res, nil
}
// Deposit represents a single deposit entry.
type Deposit struct {
Amount string `json:"amount"`
Coin string `json:"coin"`
Network string `json:"network"`
Status int `json:"status"`
Address string `json:"address"`
AddressTag string `json:"addressTag"`
TxID string `json:"txId"`
InsertTime int64 `json:"insertTime"`
TransferType int64 `json:"transferType"`
UnlockConfirm int64 `json:"unlockConfirm"`
ConfirmTimes string `json:"confirmTimes"`
}
// GetDepositsAddressService retrieves the details of a deposit address.
//
// See https://binance-docs.github.io/apidocs/spot/en/#deposit-address-supporting-network-user_data
type GetDepositsAddressService struct {
c *Client
coin string
network *string
}
// Coin sets the coin parameter (MANDATORY).
func (s *GetDepositsAddressService) Coin(coin string) *GetDepositsAddressService {
s.coin = coin
return s
}
// Network sets the network parameter.
func (s *GetDepositsAddressService) Network(network string) *GetDepositsAddressService {
s.network = &network
return s
}
// Do sends the request.
func (s *GetDepositsAddressService) Do(ctx context.Context, opts ...RequestOption) (*GetDepositAddressResponse, error) {
r := &request{
method: http.MethodGet,
endpoint: "/sapi/v1/capital/deposit/address",
secType: secTypeSigned,
}
r.setParam("coin", s.coin)
if s.network != nil {
r.setParam("network", *s.network)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res := &GetDepositAddressResponse{}
if err := json.Unmarshal(data, res); err != nil {
return nil, err
}
return res, nil
}
// GetDepositAddressResponse represents a response from GetDepositsAddressService.
type GetDepositAddressResponse struct {
Address string `json:"address"`
Tag string `json:"tag"`
Coin string `json:"coin"`
URL string `json:"url"`
}