-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwallet.go
260 lines (217 loc) · 7.16 KB
/
wallet.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
package coinpayments
import "net/url"
//balancesResponse is the api response of a "balances" call
type balancesResponse map[string]struct {
Balance int `json:"balance"`
Balancef string `json:"balancef"`
Status string `json:"status"`
}
//Balances calls the "balances" command
func (c *Client) Balances(optionals ...OptionalValue) (*balancesResponse, error) {
values := &url.Values{}
addOptionals(optionals, values)
var resp struct {
errResponse
Result *balancesResponse `json:"result"`
}
if err := c.call("balances", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//getDepositAddressResponse is the api response of a "get_deposit_address" call
type getDepositAddressResponse struct {
Address string `json:"address"`
PubKey string `json:"pubkey"`
DestTag int `json:"dest_tag"`
}
//GetDepositAddress calls the "get_deposit_address" command
func (c *Client) GetDepositAddress(currency string, optionals ...OptionalValue) (*getDepositAddressResponse, error) {
values := &url.Values{}
values.Set("currency", currency)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *getDepositAddressResponse `json:"result"`
}
if err := c.call("get_deposit_address", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//createTransferResponse is the api response of a "create_transfer" call
type createTransferResponse struct {
ID string `json:"id"`
Status int `json:"status"`
}
//CreateTransfer calls the "create_transfer" command
func (c *Client) CreateTransfer(amount, currency string, optionals ...OptionalValue) (*createTransferResponse, error) {
values := &url.Values{}
values.Set("amount", amount)
values.Set("currency", currency)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *createTransferResponse `json:"result"`
}
if err := c.call("create_transfer", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//createWithdrawalResponse is the api response of a "create_withdrawal" call
type createWithdrawalResponse struct {
ID string `json:"id"`
Status int `json:"status"`
Amount string `json:"amount"`
}
//CreateWithdrawal calls the "create_withdrawal" command
func (c *Client) CreateWithdrawal(amount, currency string, optionals ...OptionalValue) (*createWithdrawalResponse, error) {
values := &url.Values{}
values.Set("amount", amount)
values.Set("currency", currency)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *createWithdrawalResponse `json:"result"`
}
if err := c.call("create_withdrawal", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//cancelWithdrawalResponse is the api response of a "cancel_withdrawal" call
type cancelWithdrawalResponse struct{}
//CancelWithdrawal calls the "create_withdrawal" command
func (c *Client) CancelWithdrawal(id string, optionals ...OptionalValue) (*cancelWithdrawalResponse, error) {
values := &url.Values{}
values.Set("id", id)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *cancelWithdrawalResponse `json:"result"`
}
if err := c.call("cancel_withdrawal", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//convertResponse is the api response of a "convert" call
type convertResponse struct {
ID string `json:"id"`
}
//Convert calls the "convert" command
func (c *Client) Convert(amount, from, to string, optionals ...OptionalValue) (*convertResponse, error) {
values := &url.Values{}
values.Set("amount", amount)
values.Set("from", from)
values.Set("to", to)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *convertResponse `json:"result"`
}
if err := c.call("convert", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//convertLimitsResponse is the api response of a "convert_limits" call
type convertLimitsResponse struct {
Min string `json:"min"`
Max string `json:"max"`
}
//ConvertLimits calls the "convert_limits" command
func (c *Client) ConvertLimits(from, to string, optionals ...OptionalValue) (*convertLimitsResponse, error) {
values := &url.Values{}
values.Set("from", from)
values.Set("to", to)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *convertLimitsResponse `json:"result"`
}
if err := c.call("convert_limits", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//getWithdrawalHistoryResponse is the api response of a "get_withdrawal_history" call
type getWithdrawalHistoryResponse []struct {
ID string `json:"id"`
TimeCreated int `json:"time_created"`
Status int `json:"status"`
StatusText string `json:"status_text"`
Coin string `json:"coin"`
Amount int `json:"amount"`
Amountf string `json:"amountf"`
Note string `json:"note"`
SendAddress string `json:"send_address"`
SendDestTag string `json:"send_dest_tag"`
SendTXID string `json:"send_txid"`
}
//GetWithdrawalHistory calls the "get_withdrawal_history" command
func (c *Client) GetWithdrawalHistory(optionals ...OptionalValue) (*getWithdrawalHistoryResponse, error) {
values := &url.Values{}
addOptionals(optionals, values)
var resp struct {
errResponse
Result *getWithdrawalHistoryResponse `json:"result"`
}
if err := c.call("get_withdrawal_history", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//getWithdrawalInfoResponse is the api response of a "get_withdrawal_info" call
type getWithdrawalInfoResponse struct {
TimeCreated int `json:"time_created"`
Status int `json:"status"`
StatusText string `json:"status_text"`
Coin string `json:"coin"`
Amount int `json:"amount"`
Amountf string `json:"amountf"`
Note string `json:"note"`
SendAddress string `json:"send_address"`
SendTXID string `json:"send_txid"`
}
//GetWithdrawalInfo calls the "get_withdrawal_info" command
func (c *Client) GetWithdrawalInfo(id string, optionals ...OptionalValue) (*getWithdrawalInfoResponse, error) {
values := &url.Values{}
values.Set("id", id)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *getWithdrawalInfoResponse `json:"result"`
}
if err := c.call("get_withdrawal_info", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//getConversionInfoResponse is the api response of a "get_conversion_info" call
type getConversionInfoResponse struct {
TimeCreated string `json:"time_created"`
Status int `json:"status"`
StatusText string `json:"status_text"`
Coin1 string `json:"coin1"`
Coin2 string `json:"coin2"`
AmountSent int `json:"amount_sent"`
AmountSentf string `json:"amount_sentf"`
Received int `json:"received"`
Receivedf string `json:"receivedf"`
}
//GetConversionInfo calls the "get_conversion_info" command
func (c *Client) GetConversionInfo(id string, optionals ...OptionalValue) (*getConversionInfoResponse, error) {
values := &url.Values{}
values.Set("id", id)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *getConversionInfoResponse `json:"result"`
}
if err := c.call("get_conversion_info", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}