use of org.knowm.xchange.dto.trade.UserTrade 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);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class DVChainAdapters method adaptTradeHistory.
public static UserTrades adaptTradeHistory(List<DVChainTrade> trades) {
List<UserTrade> pastTrades = new ArrayList<>(trades.size());
for (DVChainTrade trade : trades) {
Order.OrderType orderType = trade.getSide().equalsIgnoreCase("buy") ? Order.OrderType.BID : Order.OrderType.ASK;
Date timestamp = Date.from(trade.getCreatedAt());
CurrencyPair currencyPair = new CurrencyPair(trade.getAsset(), "USD");
final BigDecimal fee = null;
pastTrades.add(new UserTrade.Builder().type(orderType).originalAmount(trade.getQuantity()).currencyPair(currencyPair).price(trade.getPrice()).timestamp(timestamp).id(trade.getId()).orderId(trade.getId()).feeAmount(fee).feeCurrency(Currency.USD).build());
}
return new UserTrades(pastTrades, Trades.TradeSortType.SortByTimestamp);
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class IdexTradeService method getTradeHistory.
@Override
public UserTrades getTradeHistory(TradeHistoryParams tradeHistoryParams) {
CurrencyPair currencyPairTmp = null;
if (tradeHistoryParams instanceof TradeHistoryParamCurrencyPair) {
currencyPairTmp = ((TradeHistoryParamCurrencyPair) tradeHistoryParams).getCurrencyPair();
}
final CurrencyPair currencyPair = currencyPairTmp;
UserTrades ret = null;
try {
List<UserTrade> userTrades = returnTradeHistoryApi.tradeHistory((TradeHistoryReq) tradeHistoryParams).stream().map(tradeHistoryItem -> new UserTrade.Builder().originalAmount(IdexExchange.Companion.safeParse(tradeHistoryItem.getAmount())).price(IdexExchange.Companion.safeParse(tradeHistoryItem.getPrice())).currencyPair(currencyPair).timestamp(new Date(tradeHistoryItem.getTimestamp().longValue() * 1000)).id((tradeHistoryItem.getTransactionHash())).type(tradeHistoryItem.getType() == IdexBuySell.BUY ? Order.OrderType.BID : Order.OrderType.ASK).build()).sorted(Comparator.comparing(Trade::getTimestamp)).collect(Collectors.toList());
return new UserTrades(userTrades, Trades.TradeSortType.SortByTimestamp);
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class IndependentReserveTradeServiceIntegration method testGetTradeHistory.
@Test
public void testGetTradeHistory() throws Exception {
Assume.assumeNotNull(exchange.getExchangeSpecification().getApiKey());
UserTrades userTrades = tradeService.getTradeHistory(tradeService.createTradeHistoryParams());
if (userTrades.getUserTrades().size() > 0) {
UserTrade userTrade = userTrades.getUserTrades().get(0);
String orderId = userTrade.getOrderId();
Collection<Order> orders = tradeService.getOrder(orderId);
}
}
use of org.knowm.xchange.dto.trade.UserTrade in project XChange by knowm.
the class HuobiAdapters method adaptTradeHistory.
public static UserTrades adaptTradeHistory(HuobiOrder[] openOrders) {
OpenOrders orders = adaptOpenOrders(openOrders);
List<UserTrade> trades = new ArrayList<>();
for (LimitOrder order : orders.getOpenOrders()) {
trades.add(adaptTrade(order));
}
return new UserTrades(trades, TradeSortType.SortByTimestamp);
}
Aggregations