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;
}
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());
}
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);
}
}
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);
}
}
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);
}
}
Aggregations