-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdeposit.go
303 lines (262 loc) · 6.55 KB
/
deposit.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
package upbit
import (
"bytes"
"fmt"
"github.com/sangx2/upbit/model"
"github.com/sangx2/upbit/model/exchange"
"github.com/sangx2/upbit/model/exchange/deposit"
"io/ioutil"
"net/url"
"strconv"
)
// GetDeposits 입금 리스트 조회
//
// [QUERY PARAMS]
//
// currency : Currency 코드
//
// state : 입금 상태
//
// uuids : 입금 UUID의 목록
//
// txids : 입금 TXID의 목록
//
// limit : 페이지당 개수
//
// page ; 페이지 번호
//
// orderBy : 정렬 방식
//
// [HEADERS]
//
// Authorization : REQUIRED. Authorization token(JWT)
func (u *Upbit) GetDeposits(currency, state string, uuids, txids []string, limit, page, orderBy string) ([]*deposit.Deposit, *model.Remaining, error) {
switch state {
case exchange.DEPOSIT_STATE_SUBMITTING:
case exchange.DEPOSIT_STATE_SUBMITTED:
case exchange.DEPOSIT_STATE_ALMOST_ACCEPTED:
case exchange.DEPOSIT_STATE_REJECTED:
case exchange.DEPOSIT_STATE_ACCEPTED:
case exchange.DEPOSIT_STATE_PROCESSING:
default:
return nil, nil, fmt.Errorf("invalid state")
}
l, e := strconv.Atoi(limit)
if e != nil {
return nil, nil, e
}
if l < 1 || l > 100 {
return nil, nil, fmt.Errorf("invalid limit. 0 < limit <= 100")
}
switch orderBy {
case exchange.ORDERBY_ASC:
case exchange.ORDERBY_DESC:
default:
orderBy = exchange.ORDERBY_DESC
}
api, e := GetApiInfo(FuncGetDeposits)
if e != nil {
return nil, nil, e
}
var values = url.Values{
"currency": []string{currency},
"state": []string{state},
"uuids": uuids,
"txids": txids,
"limit": []string{limit},
"page": []string{page},
"order_by": []string{orderBy},
}
req, e := u.createRequest(api.Method, BaseURI+api.Url, values, api.Section)
if e != nil {
return nil, nil, e
}
resp, e := u.do(req, api.Group)
if e != nil {
return nil, nil, e
}
defer resp.Body.Close()
deposits, e := deposit.DepositsFromJSON(resp.Body)
if e != nil {
return nil, nil, e
}
return deposits, model.RemainingFromHeader(resp.Header), nil
}
// GetDeposit 개별 입금 조회
//
// [QUERY PARAMS]
//
// uuid : 입금 UUID
//
// txid : 입금 TXID
//
// currency : Currency 코드
//
// [HEADERS]
//
// Authorization : REQUIRED. Authorization token(JWT)
func (u *Upbit) GetDeposit(uuid, txid, currency string) (*deposit.Deposit, *model.Remaining, error) {
if (len(uuid) + len(txid) + len(currency)) == 0 {
return nil, nil, fmt.Errorf("invalid args")
}
api, e := GetApiInfo(FuncGetDeposit)
if e != nil {
return nil, nil, e
}
var values = url.Values{
"uuid": []string{uuid},
"txid": []string{txid},
"currency": []string{currency},
}
req, e := u.createRequest(api.Method, BaseURI+api.Url, values, api.Section)
if e != nil {
return nil, nil, e
}
resp, e := u.do(req, api.Group)
if e != nil {
return nil, nil, e
}
defer resp.Body.Close()
deposit, e := deposit.DepositFromJSON(resp.Body)
if e != nil {
return nil, nil, e
}
return deposit, model.RemainingFromHeader(resp.Header), nil
}
// GenerateDepositCoinAddress 입금 주소 생성 요청
//
// [QUERY PARAMS]
//
// currency : Currency 코드
//
// [HEADERS]
//
// Authorization : REQUIRED. Authorization token(JWT)
//
// 주소 발급 요청 시 결과로 Response1이 반환되며 주소 발급 완료 이전까지 계속 Response1이 반환됩니다.
//
// 주소가 발급된 이후부터는 새로운 주소가 발급되는 것이 아닌 이전에 발급된 주소가 Response2 형태로 반환됩니다.
func (u *Upbit) GenerateDepositCoinAddress(currency string) (*deposit.CoinAddress, *model.Remaining, error) {
api, e := GetApiInfo(FuncGenerateDepositCoinAddress)
if e != nil {
return nil, nil, e
}
var values = url.Values{
"currency": []string{currency},
}
req, e := u.createRequest(api.Method, BaseURI+api.Url, values, api.Section)
if e != nil {
return nil, nil, e
}
resp, e := u.do(req, api.Group)
if e != nil {
return nil, nil, e
}
defer resp.Body.Close()
bodyBytes, e := ioutil.ReadAll(resp.Body)
if e != nil {
return nil, nil, e
}
resp1, e := model.Response1FromJSON(bytes.NewReader(bodyBytes))
if e != nil {
return nil, nil, e
}
if resp1.Success {
return nil, model.RemainingFromHeader(resp.Header), fmt.Errorf(resp1.Message)
} else {
coinAddress, e := deposit.CoinAddressFromJSON(bytes.NewReader(bodyBytes))
if e != nil {
return nil, nil, e
}
return coinAddress, model.RemainingFromHeader(resp.Header), nil
}
}
// GetDepositCoinAddresses 전체 입금 주소 조회
//
// [HEADERS]
//
// Authorization : REQUIRED. Authorization token(JWT)
func (u *Upbit) GetDepositCoinAddresses() ([]*deposit.CoinAddress, *model.Remaining, error) {
api, e := GetApiInfo(FuncGetDepositCoinAddresses)
if e != nil {
return nil, nil, e
}
req, e := u.createRequest(api.Method, BaseURI+api.Url, nil, api.Section)
if e != nil {
return nil, nil, e
}
resp, e := u.do(req, api.Group)
if e != nil {
return nil, nil, e
}
defer resp.Body.Close()
coinAddresses, e := deposit.CoinAddressesFromJSON(resp.Body)
if e != nil {
return nil, nil, e
}
return coinAddresses, model.RemainingFromHeader(resp.Header), nil
}
// GetDepositCoinAddress 개별 입금 주소 조회
//
// [QUERY PARAMS]
//
// currency : Currency 코드
//
// [HEADERS]
//
// Authorization : REQUIRED. Authorization token(JWT)
func (u *Upbit) GetDepositCoinAddress(currency string) (*deposit.CoinAddress, *model.Remaining, error) {
api, e := GetApiInfo(FuncGetDepositCoinAddress)
if e != nil {
return nil, nil, e
}
var values = url.Values{
"currency": []string{currency},
}
req, e := u.createRequest(api.Method, BaseURI+api.Url, values, api.Section)
if e != nil {
return nil, nil, e
}
resp, e := u.do(req, api.Group)
if e != nil {
return nil, nil, e
}
defer resp.Body.Close()
coinAddress, e := deposit.CoinAddressFromJSON(resp.Body)
if e != nil {
return nil, nil, e
}
return coinAddress, model.RemainingFromHeader(resp.Header), nil
}
// DepositKrw 원화 입금하기
//
// [BODY PARAMS]
//
// amount : 입금 원화 수량
//
// [HEADERS]
//
// Authorization : REQUIRED. Authorization token(JWT)
func (u *Upbit) DepositKrw(amount string) (*deposit.Deposit, *model.Remaining, error) {
api, e := GetApiInfo(FuncDepositKrw)
if e != nil {
return nil, nil, e
}
var values = url.Values{
"amount": []string{amount},
}
req, e := u.createRequest(api.Method, BaseURI+api.Url, values, api.Section)
if e != nil {
return nil, nil, e
}
resp, e := u.do(req, api.Group)
if e != nil {
return nil, nil, e
}
defer resp.Body.Close()
deposit, e := deposit.DepositFromJSON(resp.Body)
if e != nil {
return nil, nil, e
}
return deposit, model.RemainingFromHeader(resp.Header), nil
}