Skip to content

Commit 4003a4a

Browse files
authored
Merge pull request #2249 from cacofishadct/develop
Add paymentId support for few exchange service
2 parents bddcfde + 1a050f7 commit 4003a4a

File tree

7 files changed

+86
-86
lines changed

7 files changed

+86
-86
lines changed

xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountService.java

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88
import java.util.stream.Collectors;
99

1010
import org.knowm.xchange.Exchange;
11-
import org.knowm.xchange.binance.BinanceAdapters;
12-
import org.knowm.xchange.binance.dto.BinanceException;
1311
import org.knowm.xchange.binance.dto.account.BinanceAccountInformation;
14-
import org.knowm.xchange.binance.dto.account.DepositAddress;
1512
import org.knowm.xchange.currency.Currency;
1613
import org.knowm.xchange.dto.account.AccountInfo;
1714
import org.knowm.xchange.dto.account.Balance;
@@ -41,53 +38,38 @@ public BinanceAccountService(Exchange exchange) {
4138
public AccountInfo getAccountInfo() throws IOException {
4239
Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow");
4340
BinanceAccountInformation acc = super.account(recvWindow, getTimestamp());
44-
List<Balance> balances = acc.balances.stream()
45-
.map(b -> new Balance(b.getCurrency(), b.getTotal(), b.getAvailable()))
41+
List<Balance> balances = acc.balances.stream().map(b -> new Balance(b.getCurrency(), b.getTotal(), b.getAvailable()))
4642
.collect(Collectors.toList());
4743
return new AccountInfo(new Wallet(balances));
4844
}
4945

5046
@Override
51-
public String withdrawFunds(Currency currency, BigDecimal amount, String address)
52-
throws ExchangeException, NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {
53-
return withdraw0(currency.getCurrencyCode(), address, amount);
47+
public String withdrawFunds(Currency currency, BigDecimal amount,
48+
String address) throws ExchangeException, NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {
49+
return super.withdraw(currency.getCurrencyCode(), address, amount);
5450
}
5551

5652
@Override
57-
public String withdrawFunds(WithdrawFundsParams params)
58-
throws ExchangeException, NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {
59-
if (!(params instanceof DefaultWithdrawFundsParams)) {
53+
public String withdrawFunds(
54+
WithdrawFundsParams params) throws ExchangeException, NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {
55+
if (!(params instanceof DefaultWithdrawFundsParams)) {
6056
throw new RuntimeException("DefaultWithdrawFundsParams must be provided.");
6157
}
6258
String id = null;
6359
if (params instanceof RippleWithdrawFundsParams) {
6460
RippleWithdrawFundsParams rippleParams = null;
65-
rippleParams = (RippleWithdrawFundsParams)params;
66-
id = withdraw0(rippleParams.currency.getCurrencyCode(), rippleParams.address, rippleParams.tag, rippleParams.amount);
61+
rippleParams = (RippleWithdrawFundsParams) params;
62+
id = super.withdraw(rippleParams.currency.getCurrencyCode(), rippleParams.address, rippleParams.tag, rippleParams.amount);
6763
} else {
6864
DefaultWithdrawFundsParams p = (DefaultWithdrawFundsParams) params;
69-
id = withdraw0(p.currency.getCurrencyCode(), p.address, p.amount);
65+
id = super.withdraw(p.currency.getCurrencyCode(), p.address, p.amount);
7066
}
7167
return id;
7268
}
7369

74-
private String withdraw0(String asset, String address, BigDecimal amount) throws IOException, BinanceException {
75-
// the name parameter seams to be mandatory
76-
String name = address.length() <= 10 ? address : address.substring(0, 10);
77-
return super.withdraw(asset, address, amount, name, null, getTimestamp());
78-
}
79-
private String withdraw0(String asset, String address, String addressTag, BigDecimal amount) throws IOException, BinanceException {
80-
// the name parameter seams to be mandatory
81-
String name = address.length() <= 10 ? address : address.substring(0, 10);
82-
Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow");
83-
return super.withdraw(asset, address, addressTag, amount, name, recvWindow, getTimestamp());
84-
}
85-
8670
@Override
8771
public String requestDepositAddress(Currency currency, String... args) throws IOException {
88-
Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow");
89-
DepositAddress depositAddress = binance.depositAddress(BinanceAdapters.toSymbol(currency), recvWindow, System.currentTimeMillis(), apiKey, super.signatureCreator);
90-
return depositAddress.address;
72+
return super.requestDepositAddress(currency).address;
9173
}
9274

9375
@Override
@@ -96,8 +78,7 @@ public TradeHistoryParams createFundingHistoryParams() {
9678
}
9779

9880
@Override
99-
public List<FundingRecord> getFundingHistory(TradeHistoryParams params)
100-
throws IOException {
81+
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
10182
String asset = null;
10283
if (params instanceof TradeHistoryParamCurrency) {
10384
TradeHistoryParamCurrency cp = (TradeHistoryParamCurrency) params;
@@ -133,13 +114,15 @@ public List<FundingRecord> getFundingHistory(TradeHistoryParams params)
133114
List<FundingRecord> result = new ArrayList<>();
134115
if (withdrawals) {
135116
super.withdrawHistory(asset, startTime, endTime, recvWindow, getTimestamp()).forEach(w -> {
136-
result.add(new FundingRecord(w.address, new Date(w.applyTime), Currency.getInstance(w.asset), w.amount, w.id, w.txId, Type.WITHDRAWAL, withdrawStatus(w.status), null, null, null));
117+
result.add(new FundingRecord(w.address, new Date(w.applyTime), Currency.getInstance(w.asset), w.amount, w.id, w.txId, Type.WITHDRAWAL,
118+
withdrawStatus(w.status), null, null, null));
137119
});
138120
}
139121

140122
if (deposits) {
141123
super.depositHistory(asset, startTime, endTime, recvWindow, getTimestamp()).forEach(d -> {
142-
result.add(new FundingRecord(d.address, new Date(d.insertTime), Currency.getInstance(d.asset), d.amount, null, d.txId, Type.DEPOSIT, depositStatus(d.status), null, null, null));
124+
result.add(new FundingRecord(d.address, new Date(d.insertTime), Currency.getInstance(d.asset), d.amount, null, d.txId, Type.DEPOSIT,
125+
depositStatus(d.status), null, null, null));
143126
});
144127
}
145128

xchange-binance/src/main/java/org/knowm/xchange/binance/service/BinanceAccountServiceRaw.java

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
import java.util.List;
66

77
import org.knowm.xchange.Exchange;
8+
import org.knowm.xchange.binance.BinanceAdapters;
89
import org.knowm.xchange.binance.dto.BinanceException;
910
import org.knowm.xchange.binance.dto.account.BinanceAccountInformation;
11+
import org.knowm.xchange.binance.dto.account.DepositAddress;
1012
import org.knowm.xchange.binance.dto.account.DepositList;
1113
import org.knowm.xchange.binance.dto.account.DepositList.BinanceDeposit;
1214
import org.knowm.xchange.binance.dto.account.WapiResponse;
1315
import org.knowm.xchange.binance.dto.account.WithdrawList;
1416
import org.knowm.xchange.binance.dto.account.WithdrawRequest;
17+
import org.knowm.xchange.currency.Currency;
1518

1619
import com.fasterxml.jackson.databind.ObjectMapper;
1720

@@ -27,31 +30,51 @@ public BinanceAccountInformation account(Long recvWindow, long timestamp) throws
2730

2831
// the /wapi endpoint of binance is not stable yet and can be changed in future, there is also a lack of current documentation
2932

30-
public String withdraw(String asset, String address, BigDecimal amount, String name, Long recvWindow
31-
, long timestamp) throws IOException, BinanceException {
33+
public String withdraw(String asset, String address, BigDecimal amount) throws IOException, BinanceException {
34+
// the name parameter seams to be mandatory
35+
String name = address.length() <= 10 ? address : address.substring(0, 10);
36+
return withdraw(asset, address, amount, name, null, getTimestamp());
37+
}
38+
39+
public String withdraw(String asset, String address, String addressTag, BigDecimal amount) throws IOException, BinanceException {
40+
// the name parameter seams to be mandatory
41+
String name = address.length() <= 10 ? address : address.substring(0, 10);
42+
Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow");
43+
return withdraw(asset, address, addressTag, amount, name, recvWindow, getTimestamp());
44+
}
45+
46+
private String withdraw(String asset, String address, BigDecimal amount, String name, Long recvWindow,
47+
long timestamp) throws IOException, BinanceException {
3248
WithdrawRequest result = binance.withdraw(asset, address, null, amount, name, recvWindow, timestamp, super.apiKey, super.signatureCreator);
3349
checkWapiResponse(result);
3450
return result.getData();
3551
}
3652

37-
public String withdraw(String asset, String address, String addressTag, BigDecimal amount, String name, Long recvWindow
38-
, long timestamp) throws IOException, BinanceException {
53+
private String withdraw(String asset, String address, String addressTag, BigDecimal amount, String name, Long recvWindow,
54+
long timestamp) throws IOException, BinanceException {
3955
WithdrawRequest result = binance.withdraw(asset, address, addressTag, amount, name, recvWindow, timestamp, super.apiKey, super.signatureCreator);
4056
checkWapiResponse(result);
4157
return result.getData();
4258
}
4359

44-
public List<BinanceDeposit> depositHistory(String asset, Long startTime, Long endTime, Long recvWindow, long timestamp) throws BinanceException, IOException {
60+
public DepositAddress requestDepositAddress(Currency currency) throws IOException {
61+
Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow");
62+
return binance.depositAddress(BinanceAdapters.toSymbol(currency), recvWindow, System.currentTimeMillis(), apiKey, super.signatureCreator);
63+
}
64+
65+
public List<BinanceDeposit> depositHistory(String asset, Long startTime, Long endTime, Long recvWindow,
66+
long timestamp) throws BinanceException, IOException {
4567
DepositList result = binance.depositHistory(asset, startTime, endTime, recvWindow, timestamp, super.apiKey, super.signatureCreator);
4668
return checkWapiResponse(result);
4769
}
4870

49-
public List<WithdrawList.BinanceWithdraw> withdrawHistory(String asset, Long startTime, Long endTime, Long recvWindow, long timestamp) throws BinanceException, IOException {
71+
public List<WithdrawList.BinanceWithdraw> withdrawHistory(String asset, Long startTime, Long endTime, Long recvWindow,
72+
long timestamp) throws BinanceException, IOException {
5073
WithdrawList result = binance.withdrawHistory(asset, startTime, endTime, recvWindow, timestamp, super.apiKey, super.signatureCreator);
5174
return checkWapiResponse(result);
5275
}
5376

54-
private <T> T checkWapiResponse(WapiResponse<T> result){
77+
private <T> T checkWapiResponse(WapiResponse<T> result) {
5578
if (!result.success) {
5679
BinanceException exception;
5780
try {

xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/HitbtcAuthenticated.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public interface HitbtcAuthenticated extends Hitbtc {
4444

4545
@GET
4646
@Path("account/transactions")
47-
List<HitbtcTransaction> transactions(@QueryParam("currency") String currency, @QueryParam("limit") Integer limit, @QueryParam("offset") Integer offset) throws HttpStatusIOException;
47+
List<HitbtcTransaction> transactions(@QueryParam("currency") String currency, @QueryParam("limit") Integer limit,
48+
@QueryParam("offset") Integer offset) throws HttpStatusIOException;
4849

4950
@POST
5051
@Path("account/transfer")
@@ -53,7 +54,8 @@ HitbtcInternalTransferResponse transferToTrading(@FormParam("amount") BigDecimal
5354

5455
@POST
5556
@Path("account/crypto/withdraw")
56-
Map payout(@FormParam("amount") BigDecimal amount, @FormParam("currency") String currency, @FormParam("address") String address) throws HttpStatusIOException;
57+
Map payout(@FormParam("amount") BigDecimal amount, @FormParam("currency") String currency, @FormParam("address") String address,
58+
@FormParam("paymentId") String paymentId) throws HttpStatusIOException;
5759

5860
/************************ Tradding & Order APIs ************************/
5961

@@ -65,17 +67,15 @@ HitbtcInternalTransferResponse transferToTrading(@FormParam("amount") BigDecimal
6567
@POST
6668
@Path("order")
6769
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
68-
HitbtcOrder postHitbtcNewOrder(
69-
@FormParam("clientOrderId") String clientOrderId, @FormParam("symbol") String symbol, @FormParam("side") String side,
70-
@FormParam("price") BigDecimal price, @FormParam("quantity") BigDecimal quantity,
71-
@FormParam("type") String type, @FormParam("timeInForce") String timeInForce) throws IOException, HitbtcException;
70+
HitbtcOrder postHitbtcNewOrder(@FormParam("clientOrderId") String clientOrderId, @FormParam("symbol") String symbol, @FormParam("side") String side,
71+
@FormParam("price") BigDecimal price, @FormParam("quantity") BigDecimal quantity, @FormParam("type") String type,
72+
@FormParam("timeInForce") String timeInForce) throws IOException, HitbtcException;
7273

7374
@PATCH
7475
@Path("order/{clientOrderId}")
7576
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
7677
HitbtcOrder updateHitbtcOrder(@PathParam("clientOrderId") String clientOrderId, @FormParam("quantity") BigDecimal quantity,
77-
@FormParam("requestClientId") String requestClientId, @FormParam("price") BigDecimal price)
78-
throws IOException, HitbtcException;
78+
@FormParam("requestClientId") String requestClientId, @FormParam("price") BigDecimal price) throws IOException, HitbtcException;
7979

8080
@DELETE
8181
@Path("order")
@@ -95,8 +95,8 @@ HitbtcOrder updateHitbtcOrder(@PathParam("clientOrderId") String clientOrderId,
9595
@GET
9696
@Path("history/trades")
9797
List<HitbtcOwnTrade> getHitbtcTrades(@QueryParam("symbol") String symbol, @QueryParam("sort") String sort, @QueryParam("by") String sortBy,
98-
@QueryParam("from") String from, @QueryParam("till") String till, @QueryParam("limit") long limit,
99-
@QueryParam("offset") long offset) throws IOException, HitbtcException;
98+
@QueryParam("from") String from, @QueryParam("till") String till, @QueryParam("limit") long limit,
99+
@QueryParam("offset") long offset) throws IOException, HitbtcException;
100100

101101
//TODO add query params
102102

@@ -120,8 +120,8 @@ List<HitbtcOwnTrade> getHitbtcTrades(@QueryParam("symbol") String symbol, @Query
120120
*/
121121
@GET
122122
@Path("history/order")
123-
List<HitbtcOrder> getHitbtcOrder(@PathParam("symbol") String symbol,
124-
@PathParam("clientOrderId") String clientOrderId) throws IOException, HitbtcException;
123+
List<HitbtcOrder> getHitbtcOrder(@PathParam("symbol") String symbol,
124+
@PathParam("clientOrderId") String clientOrderId) throws IOException, HitbtcException;
125125

126126
@GET
127127
@Path("/history/order/{id}/trades")

xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/dto/HitbtcAddress.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,23 @@
55
public class HitbtcAddress {
66

77
private final String address;
8+
private final String paymentId;
89

9-
public HitbtcAddress(@JsonProperty("address") String address) {
10+
public HitbtcAddress(@JsonProperty("address") String address, @JsonProperty("paymentId") String paymentId) {
1011
this.address = address;
12+
this.paymentId = paymentId;
1113
}
1214

1315
public String getAddress() {
1416
return address;
1517
}
1618

19+
public String getPaymentId() {
20+
return paymentId;
21+
}
22+
1723
@Override
1824
public String toString() {
19-
return "HitbtcAddress{" +
20-
"address='" + address + '\'' +
21-
'}';
25+
return "HitbtcAddress{" + "address='" + address + '\'' + "paymentId='" + paymentId + '\'' + '}';
2226
}
2327
}

xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountService.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public AccountInfo getAccountInfo() throws IOException {
3232
@Override
3333
public String withdrawFunds(Currency currency, BigDecimal amount, String address) throws IOException {
3434

35-
return withdrawFundsRaw(currency, amount, address);
35+
return withdrawFundsRaw(currency, amount, address, null);
3636
}
3737

3838
@Override
@@ -48,8 +48,7 @@ public String withdrawFunds(WithdrawFundsParams params) throws IOException {
4848

4949
@Override
5050
public String requestDepositAddress(Currency currency, String... args) throws IOException {
51-
52-
return getDepositAddress(currency.toString());
51+
return getDepositAddress(currency).getAddress();
5352
}
5453

5554
@Override
@@ -66,15 +65,9 @@ public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws I
6665
if (params instanceof TradeHistoryParams) {
6766
HitbtcFundingHistoryParams hitbtcTradeHistoryParams = (HitbtcFundingHistoryParams) params;
6867

69-
String currency = hitbtcTradeHistoryParams.getCurrency() != null ?
70-
hitbtcTradeHistoryParams.getCurrency().getCurrencyCode() :
71-
null;
68+
String currency = hitbtcTradeHistoryParams.getCurrency() != null ? hitbtcTradeHistoryParams.getCurrency().getCurrencyCode() : null;
7269

73-
transactions = getTransactions(
74-
currency,
75-
hitbtcTradeHistoryParams.getLimit(),
76-
hitbtcTradeHistoryParams.getOffset()
77-
);
70+
transactions = getTransactions(currency, hitbtcTradeHistoryParams.getLimit(), hitbtcTradeHistoryParams.getOffset());
7871
}
7972

8073
else {

xchange-hitbtc/src/main/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountServiceRaw.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package org.knowm.xchange.hitbtc.v2.service;
22

3+
import java.io.IOException;
4+
import java.math.BigDecimal;
5+
import java.util.List;
6+
import java.util.Map;
7+
38
import org.knowm.xchange.Exchange;
49
import org.knowm.xchange.currency.Currency;
510
import org.knowm.xchange.exceptions.ExchangeException;
@@ -8,35 +13,29 @@
813
import org.knowm.xchange.hitbtc.v2.dto.HitbtcInternalTransferResponse;
914
import org.knowm.xchange.hitbtc.v2.dto.HitbtcTransaction;
1015
import org.knowm.xchange.hitbtc.v2.dto.HitbtcTransferType;
11-
import si.mazi.rescu.HttpStatusIOException;
1216

13-
import java.io.IOException;
14-
import java.math.BigDecimal;
15-
import java.util.List;
16-
import java.util.Map;
17+
import si.mazi.rescu.HttpStatusIOException;
1718

1819
public class HitbtcAccountServiceRaw extends HitbtcBaseService {
1920

2021
public HitbtcAccountServiceRaw(Exchange exchange) {
2122
super(exchange);
2223
}
2324

24-
public String withdrawFundsRaw(Currency currency, BigDecimal amount, String address) throws HttpStatusIOException {
25-
Map response = hitbtc.payout(amount, currency.getCurrencyCode(), address);
25+
public String withdrawFundsRaw(Currency currency, BigDecimal amount, String address, String paymentId) throws HttpStatusIOException {
26+
Map response = hitbtc.payout(amount, currency.getCurrencyCode(), address, paymentId);
2627

2728
/*
28-
todo:
29-
if there isn't enough money we get a 400 with body:
30-
31-
{"error":{"code":20001,"message":"Insufficient funds","description":"Check that the funds are sufficient, given commissions"}}
32-
33-
...but currently 400 errors don't reach this code
29+
* todo: if there isn't enough money we get a 400 with body:
30+
* {"error":{"code":20001,"message":"Insufficient funds","description":"Check that the funds are sufficient, given commissions"}} ...but currently
31+
* 400 errors don't reach this code
3432
*/
3533

3634
return response.get("id").toString();
3735
}
3836

39-
public HitbtcInternalTransferResponse transferFunds(Currency currency, BigDecimal amount, HitbtcTransferType hitbtcTransferType) throws IOException {
37+
public HitbtcInternalTransferResponse transferFunds(Currency currency, BigDecimal amount,
38+
HitbtcTransferType hitbtcTransferType) throws IOException {
4039
return hitbtc.transferToTrading(amount, currency.getCurrencyCode(), hitbtcTransferType.getType());
4140
}
4241

@@ -67,10 +66,8 @@ public List<HitbtcBalance> getTradingBalance() throws IOException {
6766
return hitbtc.getTradingBalance();
6867
}
6968

70-
public String getDepositAddress(String currency) throws IOException {
71-
72-
HitbtcAddress hitbtcDepositAddress = hitbtc.getHitbtcDepositAddress(currency);
73-
return hitbtcDepositAddress.getAddress();
69+
public HitbtcAddress getDepositAddress(Currency currency) throws IOException {
70+
return hitbtc.getHitbtcDepositAddress(currency.toString());
7471
}
7572

7673
public List<HitbtcTransaction> getTransactions(String currency, Integer limit, Integer offset) throws HttpStatusIOException {

xchange-hitbtc/src/test/java/org/knowm/xchange/hitbtc/v2/service/HitbtcAccountServiceRawIntegration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void testGetPaymentBalance() throws IOException {
7272
@Test
7373
public void testGetDepositAddress() throws IOException {
7474

75-
String response = service.getDepositAddress("BTC");
75+
String response = service.getDepositAddress(Currency.BTC).getAddress();
7676

7777
Assert.assertTrue(StringUtils.isNotEmpty(response));
7878
}

0 commit comments

Comments
 (0)