use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.
the class EXXTradeService method cancelOrder.
@Override
public boolean cancelOrder(CancelOrderParams cancelOrderParams) throws IOException {
if (!(cancelOrderParams instanceof CancelOrderParams) && !(cancelOrderParams instanceof EXXCancelOrderByCurrencyPair)) {
throw new ExchangeException("You need to provide the currency pair and the order id to cancel an order.");
}
EXXCancelOrderByCurrencyPair params = (EXXCancelOrderByCurrencyPair) cancelOrderParams;
CurrencyPair currencyPair = params.getCurrencyPair();
// etp_btc
String currency = currencyPairFormat(currencyPair);
return cancelExxOrder(params.getId(), currency);
}
use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.
the class LunoTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws ExchangeException, IOException {
if (!(params instanceof TradeHistoryParamCurrencyPair)) {
throw new ExchangeException("THe currency pair is mandatory in order to get user trades.");
}
CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
Long since = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
since = ((TradeHistoryParamsTimeSpan) params).getStartTime().getTime();
}
Integer limit = null;
if (params instanceof TradeHistoryParamLimit) {
limit = ((TradeHistoryParamLimit) params).getLimit();
}
LunoUserTrades lunoTrades = lunoAPI.listTrades(LunoUtil.toLunoPair(currencyPair), since, limit);
List<UserTrade> trades = new ArrayList<>();
for (org.knowm.xchange.luno.dto.trade.LunoUserTrades.UserTrade t : lunoTrades.getTrades()) {
final CurrencyPair pair = LunoUtil.fromLunoPair(t.pair);
// currently there is no trade id!
final String tradeId = null;
final BigDecimal feeAmount;
final Currency feeCurrency;
if (t.feeBase.compareTo(BigDecimal.ZERO) > 0) {
feeAmount = t.feeBase;
feeCurrency = pair.base;
} else {
feeAmount = t.feeCounter;
feeCurrency = pair.counter;
}
trades.add(new UserTrade.Builder().type(t.buy ? OrderType.BID : OrderType.ASK).originalAmount(t.volume).currencyPair(pair).price(t.price).timestamp(t.getTimestamp()).id(tradeId).orderId(t.orderId).feeAmount(feeAmount).feeCurrency(feeCurrency).build());
}
return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.
the class TheRockTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
if (!(params instanceof TradeHistoryParamCurrencyPair)) {
throw new ExchangeException("TheRock API recquires " + TradeHistoryParamCurrencyPair.class);
}
TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
// get all trades starting from a specific trade_id
Long sinceTradeId = null;
if (params instanceof TradeHistoryParamsIdSpan) {
TradeHistoryParamsIdSpan trId = (TradeHistoryParamsIdSpan) params;
try {
sinceTradeId = Long.valueOf(trId.getStartId());
} catch (Throwable ignored) {
}
}
Date after = null;
Date before = null;
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan time = (TradeHistoryParamsTimeSpan) params;
after = time.getStartTime();
before = time.getEndTime();
}
int pageLength = 200;
int page = 0;
if (params instanceof TradeHistoryParamPaging) {
TradeHistoryParamPaging tradeHistoryParamPaging = (TradeHistoryParamPaging) params;
pageLength = tradeHistoryParamPaging.getPageLength();
page = tradeHistoryParamPaging.getPageNumber();
}
return TheRockAdapters.adaptUserTrades(getTheRockUserTrades(pairParams.getCurrencyPair(), sinceTradeId, after, before, pageLength, page), pairParams.getCurrencyPair());
}
use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.
the class BleutradeMarketDataServiceRaw method getBleutradeMarketHistory.
public List<BleutradeTrade> getBleutradeMarketHistory(CurrencyPair currencyPair, int count) throws IOException {
String pairString = BleutradeUtils.toPairString(currencyPair);
BleutradeMarketHistoryReturn response = bleutrade.getBleutradeMarketHistory(pairString, count);
if (!response.getSuccess()) {
throw new ExchangeException(response.getMessage());
}
return response.getResult();
}
use of org.knowm.xchange.exceptions.ExchangeException in project XChange by knowm.
the class BleutradeTradeServiceRaw method sellLimit.
public String sellLimit(LimitOrder limitOrder) throws IOException {
try {
String pairString = BleutradeUtils.toPairString(limitOrder.getCurrencyPair());
BleutradePlaceOrderReturn response = bleutrade.sellLimit(apiKey, signatureCreator, exchange.getNonceFactory(), pairString, limitOrder.getOriginalAmount().toPlainString(), limitOrder.getLimitPrice().toPlainString());
if (!response.getSuccess()) {
throw new ExchangeException(response.getMessage());
}
return response.getResult().getOrderid();
} catch (BleutradeException e) {
throw new ExchangeException(e);
}
}
Aggregations