Skip to content

Commit bf89eb1

Browse files
committed
feat: new fee methods
1 parent 1c46c84 commit bf89eb1

File tree

6 files changed

+159
-36
lines changed

6 files changed

+159
-36
lines changed

src/main/java/com/cryptomarket/sdk/models/FeeRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ public class FeeRequest {
88
@Json(name = "network_code")
99
private String networkCode;
1010

11+
public FeeRequest(String currency, String amount) {
12+
this.currency = currency;
13+
this.amount = amount;
14+
}
15+
1116
public FeeRequest(String currency, String amount, String networkCode) {
1217
this.currency = currency;
1318
this.amount = amount;

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

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,14 +1380,65 @@ public String getEstimateWithdrawalFee(String currency, String amount, @Nullable
13801380
* <p>
13811381
* Requires the "Payment information" API key Access Right
13821382
* <p>
1383-
* https://api.exchange.cryptomkt.com/#estimate-withdrawal-fees
1383+
* https://api.exchange.cryptomkt.com/#estimate-withdrawal-fee
13841384
*
13851385
* @param feeRequests a list of fee requests
13861386
* @return the list of fees
13871387
* @throws CryptomarketSDKException
13881388
*/
13891389
public List<Fee> getEstimateWithdrawalFees(List<FeeRequest> feeRequests) throws CryptomarketSDKException;
13901390

1391+
1392+
/**
1393+
* Get estimates of withdrawal fees
1394+
* <p>
1395+
* Requires the "Payment information" API key Access Right
1396+
* <p>
1397+
* https://api.exchange.cryptomkt.com/#bulk-estimate-deposit-fee
1398+
*
1399+
* @param feeRequests a list of fee requests
1400+
* @return the list of fees
1401+
* @throws CryptomarketSDKException
1402+
*/
1403+
public List<Fee> getBulkEstimateWithdrawalFees(List<FeeRequest> feeRequests) throws CryptomarketSDKException;
1404+
1405+
1406+
/**
1407+
* Get an estimate of the deposit fee
1408+
* <p>
1409+
* Requires the "Payment information" API key Access Right
1410+
* <p>
1411+
* https://api.exchange.cryptomkt.com/#estimate-deposit-fee
1412+
*
1413+
* @param currency the currency code for deposit
1414+
* @param amount the expected deposit amount
1415+
* @param networkCode Optional. Network code
1416+
* @return The expected fee
1417+
* @throws CryptomarketSDKException
1418+
*/
1419+
public String getEstimateDepositFee(String currency, String amount, @Nullable String networkCode)
1420+
throws CryptomarketSDKException;
1421+
1422+
/**
1423+
* @see #getEstimateWithdrawalFee(String, String, String)
1424+
* @param paramsBuilder
1425+
* @throws CryptomarketSDKException
1426+
*/
1427+
public String getEstimateDepositFee(ParamsBuilder paramsBuilder) throws CryptomarketSDKException;
1428+
1429+
/**
1430+
* Get estimates of deposit fees
1431+
* <p>
1432+
* Requires the "Payment information" API key Access Right
1433+
* <p>
1434+
* https://api.exchange.cryptomkt.com/#bulk-estimate-deposit-fee
1435+
*
1436+
* @param feeRequests a list of fee requests
1437+
* @return the list of fees
1438+
* @throws CryptomarketSDKException
1439+
*/
1440+
public List<Fee> getBulkEstimateDepositFees(List<FeeRequest> feeRequests) throws CryptomarketSDKException;
1441+
13911442
/**
13921443
* Converts between currencies
13931444
* <p>
@@ -1537,10 +1588,10 @@ public String transferMoneyToAnotherUser(ParamsBuilder paramsBuilder)
15371588
* 'updated_at',
15381589
* 'last_activity_at' 'or 'id'.
15391590
* Default is 'created_at'
1540-
* @param from Optional. Interval initial value when ordering by
1541-
* 'created_at'. As Datetime
1542-
* @param till Optional. Interval end value when ordering by
1543-
* 'created_at'. As Datetime
1591+
* @param from Optional. Optional. Interval initial value
1592+
* (inclusive). The value type depends on orderByy
1593+
* @param till Optional. Interval end value (inclusive). The value
1594+
* type depends on orderBy
15441595
* @param idFrom Optional. Interval initial value when ordering by
15451596
* id. Min is 0
15461597
* @param idTill Optional. Interval end value when ordering by id.

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,45 @@ public List<Fee> getEstimateWithdrawalFees(List<FeeRequest> feeRequests) throws
912912
return adapter.listFromJson(jsonResponse, Fee.class);
913913
}
914914

915+
916+
@Override
917+
public List<Fee> getBulkEstimateWithdrawalFees(List<FeeRequest> feeRequests) throws CryptomarketSDKException {
918+
var payload = adapter.listToJson(feeRequests, FeeRequest.class);
919+
String jsonResponse = httpClient.post(
920+
"wallet/crypto/fee/deposit/estimate/bulk",
921+
payload);
922+
return adapter.listFromJson(jsonResponse, Fee.class);
923+
}
924+
925+
@Override
926+
public String getEstimateDepositFee(String currency, String amount, String networkCode)
927+
throws CryptomarketSDKException {
928+
return getEstimateDepositFee(new ParamsBuilder()
929+
.currency(currency)
930+
.networkCode(networkCode)
931+
.amount(amount));
932+
}
933+
934+
@Override
935+
public String getEstimateDepositFee(ParamsBuilder paramsBuilder) throws CryptomarketSDKException {
936+
paramsBuilder.checkRequired(Arrays.asList(
937+
ArgNames.CURRENCY,
938+
ArgNames.AMOUNT));
939+
String jsonResponse = httpClient.get(
940+
"wallet/crypto/fee/deposit/estimate",
941+
paramsBuilder.build());
942+
return adapter.objectFromJsonValue(jsonResponse, "fee", String.class);
943+
}
944+
945+
@Override
946+
public List<Fee> getBulkEstimateDepositFees(List<FeeRequest> feeRequests) throws CryptomarketSDKException {
947+
var payload = adapter.listToJson(feeRequests, FeeRequest.class);
948+
String jsonResponse = httpClient.post(
949+
"wallet/crypto/fee/deposit/estimate/bulk",
950+
payload);
951+
return adapter.listFromJson(jsonResponse, Fee.class);
952+
}
953+
915954
@Override
916955
public List<String> convertBetweenCurrencies(
917956
String fromCurrency, String toCurrency,

src/main/java/com/cryptomarket/sdk/websocket/CryptomarketWSWalletClient.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -145,40 +145,40 @@ public void getWalletBalance(String currency,
145145
* <p>
146146
* https://api.exchange.cryptomkt.com/#get-transactions-history
147147
*
148-
* @param resultBiConsumer recieves a list of transactions, and a
149-
* CryptomarketSDKException if
150-
* there was a problem (or null if there was none)
151-
* @param transactionIds Optional. List of transaction identifiers to query
152-
* @param types Optional. List of types to query. valid types are:
153-
* 'DEPOSIT', 'WITHDRAW', 'TRANSFER' and 'SWAP'
154-
* @param subtypes Optional. List of subtypes to query. valid
155-
* subtypes are: 'UNCLASSIFIED', 'BLOCKCHAIN',
156-
* 'AIRDROP', 'AFFILIATE', 'STAKING', 'BUY_CRYPTO',
157-
* 'OFFCHAIN', 'FIAT', 'SUB_ACCOUNT',
158-
* 'WALLET_TO_SPOT', 'SPOT_TO_WALLET',
159-
* 'WALLET_TO_DERIVATIVES', 'DERIVATIVES_TO_WALLET',
160-
* 'CHAIN_SWITCH_FROM', 'CHAIN_SWITCH_TO' and
161-
* 'INSTANT_EXCHANGE'
162-
* @param statuses Optional. List of statuses to query. valid
163-
* subtypes are: 'CREATED', 'PENDING', 'FAILED',
164-
* 'SUCCESS' and 'ROLLED_BACK'
148+
* @param resultBiConsumer recieves a list of transactions, and a
149+
* CryptomarketSDKException if
150+
* there was a problem (or null if there was none)
151+
* @param transactionIds Optional. List of transaction identifiers to query
152+
* @param types Optional. List of types to query. valid types are:
153+
* 'DEPOSIT', 'WITHDRAW', 'TRANSFER' and 'SWAP'
154+
* @param subtypes Optional. List of subtypes to query. valid
155+
* subtypes are: 'UNCLASSIFIED', 'BLOCKCHAIN',
156+
* 'AIRDROP', 'AFFILIATE', 'STAKING', 'BUY_CRYPTO',
157+
* 'OFFCHAIN', 'FIAT', 'SUB_ACCOUNT',
158+
* 'WALLET_TO_SPOT', 'SPOT_TO_WALLET',
159+
* 'WALLET_TO_DERIVATIVES', 'DERIVATIVES_TO_WALLET',
160+
* 'CHAIN_SWITCH_FROM', 'CHAIN_SWITCH_TO' and
161+
* 'INSTANT_EXCHANGE'
162+
* @param statuses Optional. List of statuses to query. valid
163+
* subtypes are: 'CREATED', 'PENDING', 'FAILED',
164+
* 'SUCCESS' and 'ROLLED_BACK'
165165
* @param orderBy Optional. sorting parameter.'created_at',
166166
* 'updated_at',
167167
* 'last_activity_at' 'or 'id'.
168168
* Default is 'created_at'
169-
* @param from Optional. Interval initial value when ordering by
170-
* 'created_at'. As Datetime
171-
* @param till Optional. Interval end value when ordering by
172-
* 'created_at'. As Datetime
173-
* @param idFrom Optional. Interval initial value when ordering by
174-
* id. Min is 0
175-
* @param idTill Optional. Interval end value when ordering by id.
176-
* Min is 0
177-
* @param sort Optional. Sort direction. 'ASC' or 'DESC'. Default
178-
* is 'DESC'
179-
* @param limit Optional. Transactions per query. Defaul is 100.
180-
* Max is 1000
181-
* @param offset Optional. Default is 0. Max is 100000
169+
* @param from Optional. Optional. Interval initial value
170+
* (inclusive). The value type depends on orderBy
171+
* @param till Optional. Interval end value (inclusive). The value
172+
* type depends on orderBy
173+
* @param idFrom Optional. Interval initial value when ordering by
174+
* id. Min is 0
175+
* @param idTill Optional. Interval end value when ordering by id.
176+
* Min is 0
177+
* @param sort Optional. Sort direction. 'ASC' or 'DESC'. Default
178+
* is 'DESC'
179+
* @param limit Optional. Transactions per query. Defaul is 100.
180+
* Max is 1000
181+
* @param offset Optional. Default is 0. Max is 100000
182182
* @param groupTransactions Optional. Flag indicating whether the returned
183183
* transactions will be parts of a single operation.
184184
* Default is false.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public class Checker {
307307
static Consumer<Fee> checkFee = obj -> {
308308
List<String> fields = new ArrayList<>(Arrays.asList(
309309
obj.getFee(),
310-
obj.getNetworkFee(),
310+
// obj.getNetworkFee(),
311311
obj.getCurrency(),
312312
obj.getAmount()
313313
// obj.getUpdatedAt()

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ public void testGetEstimateWithdrawFees() throws CryptomarketSDKException {
124124
fees.forEach(Checker.checkFee);
125125
}
126126

127+
@Test
128+
public void testGetBulkEstimateWithdrawFees() throws CryptomarketSDKException {
129+
var fees = client
130+
.getBulkEstimateWithdrawalFees(List.of(new FeeRequest("EOS", "100", null), new FeeRequest("ETH", "100", null)));
131+
if (fees.size() != 2) {
132+
fail("invalid amount of fees");
133+
}
134+
fees.forEach(Checker.checkFee);
135+
}
136+
127137
@Test
128138
public void testGetEstimateWithdrawFee() throws CryptomarketSDKException {
129139
String estimate = client.getEstimateWithdrawalFee("EOS", "100", null);
@@ -132,6 +142,24 @@ public void testGetEstimateWithdrawFee() throws CryptomarketSDKException {
132142
}
133143
}
134144

145+
@Test
146+
public void testGetEstimateDepositFees() throws CryptomarketSDKException {
147+
var fees = client
148+
.getBulkEstimateDepositFees(List.of(new FeeRequest("EOS", "100"), new FeeRequest("ETH", "100")));
149+
if (fees.size() != 2) {
150+
fail("invalid amount of fees");
151+
}
152+
fees.forEach(Checker.checkFee);
153+
}
154+
155+
@Test
156+
public void testGetEstimateDepositFee() throws CryptomarketSDKException {
157+
String estimate = client.getEstimateDepositFee("EOS", "100", null);
158+
if (estimate.equals("")) {
159+
fail();
160+
}
161+
}
162+
135163
@Test
136164
public void testCryptoAddressBelongsToCurrentAccount() throws CryptomarketSDKException {
137165
List<Address> addresses = client.getDepositCryptoAddresses("ADA", null);

0 commit comments

Comments
 (0)