1
1
package org .knowm .xchange .binance .service ;
2
2
3
3
import static org .knowm .xchange .binance .BinanceExchange .EXCHANGE_TYPE ;
4
- import static org .knowm .xchange .binance .dto .ExchangeType .FUTURES ;
5
- import static org .knowm .xchange .binance .dto .ExchangeType .SPOT ;
6
4
7
5
import java .io .IOException ;
8
6
import java .math .BigDecimal ;
13
11
import java .util .HashMap ;
14
12
import java .util .List ;
15
13
import java .util .Map ;
14
+ import org .apache .commons .lang3 .StringUtils ;
16
15
import org .knowm .xchange .binance .BinanceAdapters ;
17
16
import org .knowm .xchange .binance .BinanceErrorAdapter ;
18
17
import org .knowm .xchange .binance .BinanceExchange ;
19
18
import org .knowm .xchange .binance .dto .BinanceException ;
20
19
import org .knowm .xchange .binance .dto .ExchangeType ;
21
20
import org .knowm .xchange .binance .dto .account .AssetDetail ;
22
21
import org .knowm .xchange .binance .dto .account .BinanceAccountInformation ;
22
+ import org .knowm .xchange .binance .dto .account .BinanceCurrencyInfo ;
23
+ import org .knowm .xchange .binance .dto .account .BinanceCurrencyInfo .Network ;
23
24
import org .knowm .xchange .binance .dto .account .BinanceFundingHistoryParams ;
24
25
import org .knowm .xchange .binance .dto .account .BinanceMasterAccountTransferHistoryParams ;
25
26
import org .knowm .xchange .binance .dto .account .BinanceSubAccountTransferHistoryParams ;
38
39
import org .knowm .xchange .dto .account .Wallet ;
39
40
import org .knowm .xchange .instrument .Instrument ;
40
41
import org .knowm .xchange .service .account .AccountService ;
42
+ import org .knowm .xchange .service .account .params .RequestDepositAddressParams ;
41
43
import org .knowm .xchange .service .trade .params .DefaultWithdrawFundsParams ;
42
44
import org .knowm .xchange .service .trade .params .HistoryParamsFundingType ;
45
+ import org .knowm .xchange .service .trade .params .NetworkWithdrawFundsParams ;
43
46
import org .knowm .xchange .service .trade .params .RippleWithdrawFundsParams ;
44
47
import org .knowm .xchange .service .trade .params .TradeHistoryParamCurrency ;
45
48
import org .knowm .xchange .service .trade .params .TradeHistoryParamLimit ;
@@ -187,15 +190,26 @@ public String withdrawFunds(WithdrawFundsParams params) throws IOException {
187
190
rippleParams .getCurrency ().getCurrencyCode (),
188
191
rippleParams .getAddress (),
189
192
rippleParams .getTag (),
190
- rippleParams .getAmount ());
193
+ rippleParams .getAmount (),
194
+ Currency .XRP .getCurrencyCode ());
195
+ } else if (params instanceof NetworkWithdrawFundsParams ) {
196
+ NetworkWithdrawFundsParams p = (NetworkWithdrawFundsParams ) params ;
197
+ withdraw =
198
+ super .withdraw (
199
+ p .getCurrency ().getCurrencyCode (),
200
+ p .getAddress (),
201
+ p .getAddressTag (),
202
+ p .getAmount (),
203
+ p .getNetwork ());
191
204
} else {
192
205
DefaultWithdrawFundsParams p = (DefaultWithdrawFundsParams ) params ;
193
206
withdraw =
194
207
super .withdraw (
195
208
p .getCurrency ().getCurrencyCode (),
196
209
p .getAddress (),
197
210
p .getAddressTag (),
198
- p .getAmount ());
211
+ p .getAmount (),
212
+ null );
199
213
}
200
214
return withdraw .getId ();
201
215
} catch (BinanceException e ) {
@@ -215,14 +229,60 @@ public String requestDepositAddress(Currency currency, String... args) throws IO
215
229
@ Override
216
230
public AddressWithTag requestDepositAddressData (Currency currency , String ... args )
217
231
throws IOException {
218
- DepositAddress depositAddress = super .requestDepositAddress (currency );
232
+ return prepareAddressWithTag (super .requestDepositAddress (currency ));
233
+ }
234
+
235
+ @ Override
236
+ public AddressWithTag requestDepositAddressData (
237
+ RequestDepositAddressParams requestDepositAddressParams ) throws IOException {
238
+ if (StringUtils .isEmpty (requestDepositAddressParams .getNetwork ())) {
239
+ return requestDepositAddressData (
240
+ requestDepositAddressParams .getCurrency (),
241
+ requestDepositAddressParams .getExtraArguments ());
242
+ }
243
+
244
+ BinanceCurrencyInfo binanceCurrencyInfo =
245
+ super .getCurrencyInfo (requestDepositAddressParams .getCurrency ())
246
+ .orElseThrow (
247
+ () ->
248
+ new IllegalArgumentException (
249
+ "Currency not supported: " + requestDepositAddressParams .getCurrency ()));
250
+
251
+ Network binanceNetwork =
252
+ binanceCurrencyInfo .getNetworks ().stream ()
253
+ .filter (
254
+ network ->
255
+ requestDepositAddressParams .getNetwork ().equals (network .getId ())
256
+ || network
257
+ .getId ()
258
+ .equals (requestDepositAddressParams .getCurrency ().getCurrencyCode ()))
259
+ .findFirst ()
260
+ .orElseThrow (
261
+ () ->
262
+ new IllegalArgumentException (
263
+ "Network not supported: " + requestDepositAddressParams .getNetwork ()));
264
+
265
+ DepositAddress depositAddress =
266
+ super .requestDepositAddressWithNetwork (
267
+ requestDepositAddressParams .getCurrency (), binanceNetwork .getId ());
268
+
269
+ return prepareAddressWithTag (depositAddress );
270
+ }
271
+
272
+ private static AddressWithTag prepareAddressWithTag (DepositAddress depositAddress ) {
219
273
String destinationTag =
220
274
(depositAddress .addressTag == null || depositAddress .addressTag .isEmpty ())
221
275
? null
222
276
: depositAddress .addressTag ;
223
277
return new AddressWithTag (depositAddress .address , destinationTag );
224
278
}
225
279
280
+ @ Override
281
+ public String requestDepositAddress (RequestDepositAddressParams requestDepositAddressParams )
282
+ throws IOException {
283
+ return requestDepositAddressData (requestDepositAddressParams ).getAddress ();
284
+ }
285
+
226
286
public Map <String , AssetDetail > getAssetDetails () throws IOException {
227
287
try {
228
288
return super .requestAssetDetail ();
0 commit comments