Search in sources :

Example 1 with BitstampWithdrawal

use of org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal in project XChange by knowm.

the class BitstampAccountServiceRaw method withdrawXLM.

public BitstampWithdrawal withdrawXLM(BigDecimal amount, String address, String memo) throws IOException {
    try {
        Long longMemo = null;
        if (memo != null) {
            try {
                longMemo = Long.valueOf(memo);
            } catch (NumberFormatException exception) {
                throw new RuntimeException("Bitstamp supports only numbers for xlm memo field");
            }
        }
        BitstampWithdrawal response = bitstampAuthenticatedV2.withdrawXLM(apiKeyForV2Requests, signatureCreatorV2, uuidNonceFactory, timestampFactory, API_VERSION, amount, address, longMemo);
        return checkAndReturnWithdrawal(response);
    } catch (BitstampException e) {
        throw handleError(e);
    }
}
Also used : BitstampWithdrawal(org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal) BitstampException(org.knowm.xchange.bitstamp.dto.BitstampException)

Example 2 with BitstampWithdrawal

use of org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal in project XChange by knowm.

the class BitstampAccountServiceRaw method withdrawBitstampFunds.

/**
 * This method can withdraw any currency if withdrawal endpoint is configured in
 * BitstampAuthenticatedV2
 */
public BitstampWithdrawal withdrawBitstampFunds(Currency currency, BigDecimal amount, final String address, final String tag) throws IOException {
    BitstampWithdrawal response;
    if (currency.equals(Currency.XRP)) {
        Long dt = null;
        try {
            dt = Long.valueOf(tag);
        } catch (NumberFormatException e) {
        // dt may be part of address,
        }
        response = withdrawRippleFunds(amount, address, dt);
    } else if (currency.equals(Currency.XLM)) {
        response = withdrawXLM(amount, address, tag);
    } else {
        response = withdrawAddrAmount(currency, amount, address);
    }
    if (response.error != null) {
        throw new ExchangeException("Failed to withdraw: " + response.error);
    }
    if (response.getId() == null) {
        return null;
    }
    return response;
}
Also used : BitstampWithdrawal(org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Example 3 with BitstampWithdrawal

use of org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal in project XChange by knowm.

the class BitstampAccountDemo method raw.

private static void raw(BitstampAccountServiceRaw accountService) throws IOException {
    // Get the account information
    BitstampBalance bitstampBalance = accountService.getBitstampBalance();
    System.out.println("BitstampBalance: " + bitstampBalance);
    BitstampDepositAddress depositAddress = accountService.getBitstampBitcoinDepositAddress();
    System.out.println("BitstampDepositAddress address: " + depositAddress);
    final List<DepositTransaction> unconfirmedDeposits = accountService.getUnconfirmedDeposits();
    System.out.println("Unconfirmed deposits:");
    for (DepositTransaction unconfirmedDeposit : unconfirmedDeposits) {
        System.out.println(unconfirmedDeposit);
    }
    final List<WithdrawalRequest> withdrawalRequests = accountService.getWithdrawalRequests(50000000l);
    System.out.println("Withdrawal requests:");
    for (WithdrawalRequest unconfirmedDeposit : withdrawalRequests) {
        System.out.println(unconfirmedDeposit);
    }
    BitstampWithdrawal withdrawResult = accountService.withdrawBitstampFunds(Currency.BTC, new BigDecimal(1).movePointLeft(4), "XXX");
    System.out.println("BitstampBooleanResponse = " + withdrawResult);
}
Also used : BitstampDepositAddress(org.knowm.xchange.bitstamp.dto.account.BitstampDepositAddress) DepositTransaction(org.knowm.xchange.bitstamp.dto.account.DepositTransaction) BitstampWithdrawal(org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal) BitstampBalance(org.knowm.xchange.bitstamp.dto.account.BitstampBalance) WithdrawalRequest(org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest) BigDecimal(java.math.BigDecimal)

Example 4 with BitstampWithdrawal

use of org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal in project XChange by knowm.

the class BitstampAccountService method withdrawFunds.

@Override
public String withdrawFunds(WithdrawFundsParams params) throws ExchangeException, NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {
    BitstampWithdrawal response;
    // XRP, XLM and HBAR add extra param to transaction address which will be the addressTag
    if (params instanceof DefaultWithdrawFundsParams) {
        DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params;
        response = withdrawBitstampFunds(defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress(), defaultParams.getAddressTag());
        if (response.error != null) {
            throw new ExchangeException("Failed to withdraw: " + response.error);
        }
    } else {
        throw new IllegalStateException("Unsupported WithdrawFundsParams sub class");
    }
    if (response.getId() == null) {
        return null;
    }
    return Long.toString(response.getId());
}
Also used : DefaultWithdrawFundsParams(org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams) BitstampWithdrawal(org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal) NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Example 5 with BitstampWithdrawal

use of org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal in project XChange by knowm.

the class BitstampAccountServiceRaw method withdrawAddrAmount.

/**
 * To prevent code repetition we try to resolve client method
 */
public BitstampWithdrawal withdrawAddrAmount(Currency currency, BigDecimal amount, String address) {
    try {
        Class<? extends BitstampAuthenticatedV2> clientClass = bitstampAuthenticatedV2.getClass();
        Method withdrawMethod = clientClass.getMethod("withdraw" + currency.getCurrencyCode(), String.class, ParamsDigest.class, SynchronizedValueFactory.class, SynchronizedValueFactory.class, String.class, BigDecimal.class, String.class);
        BitstampWithdrawal response = (BitstampWithdrawal) withdrawMethod.invoke(bitstampAuthenticatedV2, apiKeyForV2Requests, signatureCreatorV2, uuidNonceFactory, timestampFactory, API_VERSION, amount, address);
        return checkAndReturnWithdrawal(response);
    } catch (BitstampException e) {
        throw handleError(e);
    } catch (Exception e) {
        throw new RuntimeException("Failed to call bitstamp withdraw method on authenticated client", e);
    }
}
Also used : BitstampWithdrawal(org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal) BitstampException(org.knowm.xchange.bitstamp.dto.BitstampException) Method(java.lang.reflect.Method) FundsExceededException(org.knowm.xchange.exceptions.FundsExceededException) IOException(java.io.IOException) BitstampException(org.knowm.xchange.bitstamp.dto.BitstampException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Aggregations

BitstampWithdrawal (org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal)6 BitstampException (org.knowm.xchange.bitstamp.dto.BitstampException)3 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)3 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 BitstampBalance (org.knowm.xchange.bitstamp.dto.account.BitstampBalance)1 BitstampDepositAddress (org.knowm.xchange.bitstamp.dto.account.BitstampDepositAddress)1 BitstampRippleDepositAddress (org.knowm.xchange.bitstamp.dto.account.BitstampRippleDepositAddress)1 DepositTransaction (org.knowm.xchange.bitstamp.dto.account.DepositTransaction)1 WithdrawalRequest (org.knowm.xchange.bitstamp.dto.account.WithdrawalRequest)1 FundsExceededException (org.knowm.xchange.exceptions.FundsExceededException)1 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)1 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)1 DefaultWithdrawFundsParams (org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams)1