Skip to content

Commit 869a8d5

Browse files
committed
feat: get withdraw fees
1 parent e5f3fb2 commit 869a8d5

File tree

8 files changed

+156
-5
lines changed

8 files changed

+156
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<dependency>
115115
<groupId>com.squareup.okio</groupId>
116116
<artifactId>okio</artifactId>
117-
<version>2.8.0</version>
117+
<version>3.7.0</version>
118118
</dependency>
119119
<dependency>
120120
<groupId>com.squareup.okhttp3</groupId>

src/main/java/com/cryptomarket/sdk/Adapter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,11 @@ public List<String> stringlistFromStringMap(Object value, String key) throws Par
264264
}
265265
return listFromValue(list, String.class);
266266
}
267+
268+
public <T> String listToJson(List<T> list, Class<T> cls) throws ParseException {
269+
Type type = Types.newParameterizedType(List.class, cls);
270+
JsonAdapter<List<T>> listAdapter = moshi.adapter(type);
271+
return ConvertingException.ioAndJsonDataAndAssertionToParse(listAdapter::toJson, list);
272+
273+
}
267274
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.cryptomarket.sdk.models;
2+
3+
public class Fee {
4+
private String fee;
5+
private String networkFee;
6+
private String amount;
7+
private String currency;
8+
9+
public Fee(String fee, String networkFee, String amount, String currency) {
10+
this.fee = fee;
11+
this.networkFee = networkFee;
12+
this.amount = amount;
13+
this.currency = currency;
14+
}
15+
16+
public String getFee() {
17+
return fee;
18+
}
19+
20+
public void setFee(String fee) {
21+
this.fee = fee;
22+
}
23+
24+
public String getNetworkFee() {
25+
return networkFee;
26+
}
27+
28+
public void setNetworkFee(String networkFee) {
29+
this.networkFee = networkFee;
30+
}
31+
32+
public String getAmount() {
33+
return amount;
34+
}
35+
36+
public void setAmount(String amount) {
37+
this.amount = amount;
38+
}
39+
40+
public String getCurrency() {
41+
return currency;
42+
}
43+
44+
public void setCurrency(String currency) {
45+
this.currency = currency;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return "Fee [fee=" + fee + ", networkFee=" + networkFee + ", amount=" + amount + ", currency=" + currency + "]";
51+
}
52+
53+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.cryptomarket.sdk.models;
2+
3+
import com.squareup.moshi.Json;
4+
5+
public class FeeRequest {
6+
private String currency;
7+
private String amount;
8+
@Json(name = "network_code")
9+
private String networkCode;
10+
11+
public FeeRequest(String currency, String amount, String networkCode) {
12+
this.currency = currency;
13+
this.amount = amount;
14+
this.networkCode = networkCode;
15+
}
16+
17+
public String getCurrency() {
18+
return currency;
19+
}
20+
21+
public void setCurrency(String currency) {
22+
this.currency = currency;
23+
}
24+
25+
public String getAmount() {
26+
return amount;
27+
}
28+
29+
public void setAmount(String amount) {
30+
this.amount = amount;
31+
}
32+
33+
public String getNetworkCode() {
34+
return networkCode;
35+
}
36+
37+
public void setNetworkCode(String networkCode) {
38+
this.networkCode = networkCode;
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "FeeRequest [currency=" + currency + ", amount=" + amount + ", networkCode=" + networkCode + "]";
44+
}
45+
}

src/main/java/com/cryptomarket/sdk/rest/CryptomarketRestClient.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.cryptomarket.sdk.models.Candle;
3030
import com.cryptomarket.sdk.models.Commission;
3131
import com.cryptomarket.sdk.models.Currency;
32+
import com.cryptomarket.sdk.models.Fee;
33+
import com.cryptomarket.sdk.models.FeeRequest;
3234
import com.cryptomarket.sdk.models.Order;
3335
import com.cryptomarket.sdk.models.OrderBook;
3436
import com.cryptomarket.sdk.models.Price;
@@ -1067,6 +1069,19 @@ public String getEstimateWithdrawalFee(String currency, String amount, @Nullable
10671069
*/
10681070
public String getEstimateWithdrawalFee(ParamsBuilder paramsBuilder) throws CryptomarketSDKException;
10691071

1072+
/**
1073+
* Get estimates of withdrawal fees
1074+
* <p>
1075+
* Requires the "Payment information" API key Access Right
1076+
* <p>
1077+
* https://api.exchange.cryptomkt.com/#estimate-withdrawal-fees
1078+
*
1079+
* @param feeRequests a list of fee requests
1080+
* @return the list of fees
1081+
* @throws CryptomarketSDKException
1082+
*/
1083+
public List<Fee> getEstimateWithdrawalFees(List<FeeRequest> feeRequests) throws CryptomarketSDKException;
1084+
10701085
/**
10711086
* Converts between currencies
10721087
* <p>

src/main/java/com/cryptomarket/sdk/rest/CryptomarketRestClientImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import com.cryptomarket.sdk.models.Candle;
3333
import com.cryptomarket.sdk.models.Commission;
3434
import com.cryptomarket.sdk.models.Currency;
35+
import com.cryptomarket.sdk.models.Fee;
36+
import com.cryptomarket.sdk.models.FeeRequest;
3537
import com.cryptomarket.sdk.models.Order;
3638
import com.cryptomarket.sdk.models.OrderBook;
3739
import com.cryptomarket.sdk.models.Price;
@@ -739,7 +741,16 @@ public String getEstimateWithdrawalFee(ParamsBuilder paramsBuilder)
739741
"wallet/crypto/fee/estimate",
740742
paramsBuilder.build());
741743
return adapter.objectFromJsonValue(jsonResponse, "fee", String.class);
744+
}
742745

746+
@Override
747+
public List<Fee> getEstimateWithdrawalFees(List<FeeRequest> feeRequests) throws CryptomarketSDKException {
748+
var payload = adapter.listToJson(feeRequests, FeeRequest.class);
749+
String jsonResponse = httpClient.post(
750+
"wallet/crypto/fees/estimate",
751+
payload);
752+
System.out.println(jsonResponse);
753+
return adapter.listFromJson(jsonResponse, Fee.class);
743754
}
744755

745756
@Override

src/test/java/com/cryptomarket/sdk/Checker.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.cryptomarket.sdk.models.Candle;
1313
import com.cryptomarket.sdk.models.Commission;
1414
import com.cryptomarket.sdk.models.Currency;
15+
import com.cryptomarket.sdk.models.Fee;
1516
import com.cryptomarket.sdk.models.HistoryPoint;
1617
import com.cryptomarket.sdk.models.NativeTransaction;
1718
import com.cryptomarket.sdk.models.Network;
@@ -287,16 +288,14 @@ public class Checker {
287288
// obj.getReportType().toString()
288289
fields.forEach(checkString);
289290
};
290-
291-
public static Consumer<SubAccount> checkSubAccount = obj -> {
291+
static Consumer<SubAccount> checkSubAccount = obj -> {
292292
List<String> fields = new ArrayList<>(Arrays.asList(
293293
obj.getSubAccountId(),
294294
obj.getEmail(),
295295
obj.getStatus().toString()));
296296
fields.forEach(checkString);
297297
};
298-
299-
public static Consumer<? super SubAccountSettings> checkSubAccountSettings = obj -> {
298+
static Consumer<? super SubAccountSettings> checkSubAccountSettings = obj -> {
300299
List<String> fields = new ArrayList<>(Arrays.asList(
301300
obj.getSubAccountId(),
302301
obj.isDepositAddressGenerationEnabled().toString(),
@@ -305,4 +304,14 @@ public class Checker {
305304
obj.getUpdatedAt()));
306305
fields.forEach(checkString);
307306
};
307+
static Consumer<Fee> checkFee = obj -> {
308+
List<String> fields = new ArrayList<>(Arrays.asList(
309+
obj.getFee(),
310+
obj.getNetworkFee(),
311+
obj.getCurrency(),
312+
obj.getAmount()
313+
// obj.getUpdatedAt()
314+
));
315+
fields.forEach(checkString);
316+
};
308317
}

src/test/java/com/cryptomarket/sdk/TestRestClientWalletManagement.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.cryptomarket.sdk.exceptions.CryptomarketSDKException;
1212
import com.cryptomarket.sdk.models.Address;
1313
import com.cryptomarket.sdk.models.Balance;
14+
import com.cryptomarket.sdk.models.FeeRequest;
1415
import com.cryptomarket.sdk.models.Transaction;
1516
import com.cryptomarket.sdk.rest.CryptomarketRestClient;
1617
import com.cryptomarket.sdk.rest.CryptomarketRestClientImpl;
@@ -111,6 +112,16 @@ public void testWithdrawCryptoRollback() throws CryptomarketSDKException {
111112
}
112113
}
113114

115+
116+
@Test
117+
public void testGetEstimateWithdrawFees() throws CryptomarketSDKException {
118+
var fees = client.getEstimateWithdrawalFees(List.of(new FeeRequest("EOS", "100", null),new FeeRequest("ETH", "100", null)));
119+
if (fees.size()!=2) {
120+
fail("invalid amount of fees");
121+
}
122+
fees.forEach(Checker.checkFee);
123+
}
124+
114125
@Test
115126
public void testGetEstimateWithdrawFee() throws CryptomarketSDKException {
116127
String estimate = client.getEstimateWithdrawalFee("EOS", "100", null);

0 commit comments

Comments
 (0)