use of org.knowm.xchange.dragonex.dto.trade.DealHistory in project XChange by knowm.
the class DragonexTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
if (!(params instanceof TradeHistoryParamCurrencyPair)) {
throw new ExchangeException("You need to provide the currency pair.");
}
TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
CurrencyPair pair = pairParams.getCurrencyPair();
if (pair == null) {
throw new ExchangeException("You need to provide the currency pair.");
}
long symbolId = exchange.symbolId(pair);
Integer direction = null;
if (params instanceof TradeHistoryParamsSorted) {
TradeHistoryParamsSorted sort = (TradeHistoryParamsSorted) params;
direction = sort.getOrder() == Order.asc ? 1 : 2;
}
DealHistoryRequest req = new DealHistoryRequest(symbolId, direction, null, 1000);
DealHistory dealHistory = super.dealHistory(exchange.getOrCreateToken().token, req);
List<UserTrade> trades = dealHistory.getList().stream().map(d -> {
CurrencyPair currencyPair = exchange.pair(d.symbolId);
return new UserTrade.Builder().type(d.orderType == 1 ? OrderType.BID : OrderType.ASK).originalAmount(d.volume).currencyPair(currencyPair).price(d.price).timestamp(d.getTimestamp()).id(d.tradeId).orderId(d.orderId).feeAmount(d.charge).feeCurrency(currencyPair.counter).build();
}).collect(Collectors.toList());
return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
Aggregations