Skip to content

Commit

Permalink
Merge pull request #4902 from tross-nydig/PR/WithdrawalFeesEndpoint
Browse files Browse the repository at this point in the history
[Bitstamp] Implement client code for withdrawal-fees endpoint
  • Loading branch information
timmolter authored Jun 13, 2024
2 parents b3c2811 + 80fe1f3 commit 341810d
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import jakarta.ws.rs.core.MediaType;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;
import org.knowm.xchange.bitstamp.dto.BitstampException;
import org.knowm.xchange.bitstamp.dto.BitstampTransferBalanceResponse;
import org.knowm.xchange.bitstamp.dto.account.BitstampBalance;
import org.knowm.xchange.bitstamp.dto.account.BitstampDepositAddress;
import org.knowm.xchange.bitstamp.dto.account.BitstampRippleDepositAddress;
import org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal;
import org.knowm.xchange.bitstamp.dto.account.DepositTransaction;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalFee;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest;
import org.knowm.xchange.bitstamp.dto.trade.BitstampCancelAllOrdersResponse;
import org.knowm.xchange.bitstamp.dto.trade.BitstampOrder;
Expand Down Expand Up @@ -646,7 +648,7 @@ BitstampTransferBalanceResponse transferSubAccountBalanceToMain(
@POST
@Path("withdrawal-requests/")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
WithdrawalRequest[] getWithdrawalRequests(
List<WithdrawalRequest> getWithdrawalRequests(
@HeaderParam("X-Auth") String apiKey,
@HeaderParam("X-Auth-Signature") ParamsDigest signer,
@HeaderParam("X-Auth-Nonce") SynchronizedValueFactory<String> nonce,
Expand All @@ -655,6 +657,16 @@ WithdrawalRequest[] getWithdrawalRequests(
@FormParam("timedelta") Long timeDelta)
throws BitstampException, IOException;

@POST
@Path("fees/withdrawal/")
List<WithdrawalFee> getWithdrawalFees(
@HeaderParam("X-Auth") String apiKey,
@HeaderParam("X-Auth-Signature") ParamsDigest signer,
@HeaderParam("X-Auth-Nonce") SynchronizedValueFactory<String> nonce,
@HeaderParam("X-Auth-Timestamp") SynchronizedValueFactory<String> timeStamp,
@HeaderParam("X-Auth-Version") String version)
throws BitstampException, IOException;

@POST
@Path("withdrawal/open/")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.knowm.xchange.bitstamp.dto.account;

import java.math.BigDecimal;
import lombok.Builder;
import lombok.Value;
import lombok.extern.jackson.Jacksonized;
import org.knowm.xchange.currency.Currency;

@Jacksonized
@Value
@Builder
public class WithdrawalFee {

String network;

BigDecimal fee;

Currency currency;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.knowm.xchange.bitstamp.dto.account.BitstampRippleDepositAddress;
import org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal;
import org.knowm.xchange.bitstamp.dto.account.DepositTransaction;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalFee;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest;
import org.knowm.xchange.bitstamp.dto.trade.BitstampUserTransaction;
import org.knowm.xchange.client.ExchangeRestProxyBuilder;
Expand Down Expand Up @@ -349,16 +350,27 @@ public List<DepositTransaction> getUnconfirmedDeposits() throws IOException {
public List<WithdrawalRequest> getWithdrawalRequests(Long timeDelta) throws IOException {

try {
final List<WithdrawalRequest> response =
Arrays.asList(
bitstampAuthenticatedV2.getWithdrawalRequests(
return bitstampAuthenticatedV2.getWithdrawalRequests(
apiKeyForV2Requests,
signatureCreatorV2,
uuidNonceFactory,
timestampFactory,
API_VERSION,
timeDelta));
return response;
timeDelta);
} catch (BitstampException e) {
throw handleError(e);
}
}

public List<WithdrawalFee> getWithdrawalFees() throws IOException {

try {
return bitstampAuthenticatedV2.getWithdrawalFees(
apiKeyForV2Requests,
signatureCreatorV2,
uuidNonceFactory,
timestampFactory,
API_VERSION);
} catch (BitstampException e) {
throw handleError(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.knowm.xchange.bitstamp.dto.account;

import static org.assertj.core.api.Assertions.assertThat;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.List;
import org.junit.Test;

public class WithdrawalFeesJSONTest {

@Test
public void testUnmarshal() throws IOException {

// Read in the JSON from the example resources
InputStream is =
WithdrawalFeesJSONTest.class.getResourceAsStream(
"/org/knowm/xchange/bitstamp/dto/account/withdrawal-fees.json");

// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();

List<WithdrawalFee> withdrawalFees =
mapper.readValue(
is,
mapper.getTypeFactory().constructCollectionType(List.class, WithdrawalFee.class));

assertThat(withdrawalFees.size()).isEqualTo(1);
assertThat(withdrawalFees.get(0).getNetwork()).isEqualTo("bitcoin");
assertThat(withdrawalFees.get(0).getCurrency().getCurrencyCode()).isEqualToIgnoringCase("btc");
assertThat(withdrawalFees.get(0).getFee()).isEqualTo(new BigDecimal("0.00015000"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"currency": "btc",
"fee": "0.00015000",
"network": "bitcoin"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.knowm.xchange.bitstamp.dto.account.BitstampDepositAddress;
import org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal;
import org.knowm.xchange.bitstamp.dto.account.DepositTransaction;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalFee;
import org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest;
import org.knowm.xchange.bitstamp.service.BitstampAccountServiceRaw;
import org.knowm.xchange.currency.Currency;
Expand Down Expand Up @@ -67,6 +68,12 @@ private static void raw(BitstampAccountServiceRaw accountService) throws IOExcep
System.out.println(unconfirmedDeposit);
}

final List<WithdrawalFee> withdrawalFees = accountService.getWithdrawalFees();
System.out.println("Withdrawal requests:");
for (WithdrawalFee withdrawalFee : withdrawalFees) {
System.out.println(withdrawalFee);
}

final List<WithdrawalRequest> withdrawalRequests =
accountService.getWithdrawalRequests(50000000l);
System.out.println("Withdrawal requests:");
Expand Down

0 comments on commit 341810d

Please sign in to comment.