Search in sources :

Example 1 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException 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 2 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class BitstampTradeService method placeMarketOrder.

@Override
public String placeMarketOrder(MarketOrder order) throws IOException, BitstampException {
    BitstampAuthenticatedV2.Side side = order.getType().equals(BID) ? BitstampAuthenticatedV2.Side.buy : BitstampAuthenticatedV2.Side.sell;
    BitstampOrder bitstampOrder = placeBitstampMarketOrder(order.getCurrencyPair(), side, order.getOriginalAmount());
    if (bitstampOrder.getErrorMessage() != null) {
        throw new ExchangeException(bitstampOrder.getErrorMessage());
    }
    return Long.toString(bitstampOrder.getId());
}
Also used : BitstampOrder(org.knowm.xchange.bitstamp.dto.trade.BitstampOrder) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) BitstampAuthenticatedV2(org.knowm.xchange.bitstamp.BitstampAuthenticatedV2)

Example 3 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class LatokenMarketDataService method getTrades.

@Override
public Trades getTrades(CurrencyPair pair, Object... args) throws IOException {
    try {
        int limit = maxTrades;
        if (args != null && args.length == 1) {
            Object arg0 = args[0];
            if (!(arg0 instanceof Integer)) {
                throw new ExchangeException("Maximal number of trades must be an Integer!");
            } else {
                limit = (Integer) arg0;
            }
        }
        LatokenTrades latokenTrades = getLatokenTrades(pair, limit);
        return LatokenAdapters.adaptTrades(this.exchange, latokenTrades);
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : LatokenException(org.knowm.xchange.latoken.dto.LatokenException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) LatokenTrades(org.knowm.xchange.latoken.dto.marketdata.LatokenTrades)

Example 4 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class LatokenExchange method remoteInit.

@Override
public void remoteInit() {
    try {
        // Load the static meta-data and override with the dynamic one
        Map<Currency, CurrencyMetaData> currenciesMetaData = exchangeMetaData.getCurrencies();
        Map<CurrencyPair, CurrencyPairMetaData> pairsMetaData = exchangeMetaData.getCurrencyPairs();
        List<LatokenPair> allPairs = latoken.getAllPairs();
        List<LatokenCurrency> allCurrencies = latoken.getAllCurrencies();
        // Save pairs map on the exchange
        this.exchangeSpecification.setExchangeSpecificParametersItem("pairs", allPairs);
        // Update Currency meta-data
        for (LatokenCurrency latokenCurrency : allCurrencies) {
            Currency currency = LatokenAdapters.adaptCurrency(latokenCurrency);
            addCurrencyMetadata(currenciesMetaData, currency, PRECISION);
        }
        // Update CurrencyPair meta-data
        for (LatokenPair latokenPair : allPairs) {
            CurrencyPair pair = LatokenAdapters.adaptCurrencyPair(latokenPair);
            CurrencyPairMetaData pairMetadata = LatokenAdapters.adaptPairMetaData(latokenPair);
            addCurrencyPairMetadata(pairsMetaData, pair, pairMetadata);
        }
    } catch (Exception e) {
        throw new ExchangeException("Failed to initialize: " + e.getMessage(), e);
    }
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) LatokenCurrency(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenCurrency) Currency(org.knowm.xchange.currency.Currency) LatokenCurrency(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenCurrency) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) LatokenPair(org.knowm.xchange.latoken.dto.exchangeinfo.LatokenPair) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 5 with ExchangeException

use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.

the class LatokenTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    if (params instanceof TradeHistoryParamCurrencyPair == false) {
        throw new ExchangeException("CurrencyPair must be provided to get user trades.");
    }
    TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
    CurrencyPair pair = pairParams.getCurrencyPair();
    if (pair == null) {
        throw new ExchangeException("CurrencyPair must be provided to get user trades.");
    }
    // Limit is an optional parameter
    Integer limit = null;
    if (params instanceof TradeHistoryParamLimit) {
        TradeHistoryParamLimit limitParams = (TradeHistoryParamLimit) params;
        limit = limitParams.getLimit();
    }
    try {
        LatokenUserTrades latokenTrades = getLatokenUserTrades(pair, limit);
        return LatokenAdapters.adaptUserTrades(this.exchange, latokenTrades);
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : LatokenException(org.knowm.xchange.latoken.dto.LatokenException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) LatokenUserTrades(org.knowm.xchange.latoken.dto.trade.LatokenUserTrades) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Aggregations

ExchangeException (org.knowm.xchange.exceptions.ExchangeException)138 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)30 IOException (java.io.IOException)17 BiboxException (org.knowm.xchange.bibox.BiboxException)16 NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)16 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)16 BigDecimal (java.math.BigDecimal)15 Currency (org.knowm.xchange.currency.Currency)15 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)15 ArrayList (java.util.ArrayList)13 List (java.util.List)13 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)13 Exchange (org.knowm.xchange.Exchange)11 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)11 CancelOrderByIdParams (org.knowm.xchange.service.trade.params.CancelOrderByIdParams)11 Collectors (java.util.stream.Collectors)10 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)10 Test (org.junit.Test)9 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)9 Date (java.util.Date)8