use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class DsxAdapters method adaptTrades.
public static Trades adaptTrades(List<? extends DsxTrade> allDsxTrades, CurrencyPair currencyPair, DsxTradesSortBy sortBy) {
List<Trade> trades = new ArrayList<>(allDsxTrades.size());
long lastTradeId = 0;
for (int i = 0; i < allDsxTrades.size(); i++) {
DsxTrade dsxTrade = allDsxTrades.get(i);
Date timestamp = dsxTrade.getTimestamp();
BigDecimal price = dsxTrade.getPrice();
BigDecimal amount = dsxTrade.getQuantity();
String tid = dsxTrade.getId();
long longTradeId = tid == null ? 0 : Long.parseLong(tid);
if (longTradeId > lastTradeId) {
lastTradeId = longTradeId;
}
OrderType orderType = adaptSide(dsxTrade.getSide());
Trade trade = new Trade.Builder().type(orderType).originalAmount(amount).currencyPair(currencyPair).price(price).timestamp(timestamp).id(tid).build();
trades.add(trade);
}
return new Trades(trades, lastTradeId, sortBy.sortType);
}
use of org.knowm.xchange.dto.marketdata.Trade 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.marketdata.Trade in project XChange by knowm.
the class CoinmateAdapters method adaptTrades.
public static Trades adaptTrades(CoinmateTransactions coinmateTransactions) {
List<Trade> trades = new ArrayList<>(coinmateTransactions.getData().size());
for (CoinmateTransactionsEntry coinmateEntry : coinmateTransactions.getData()) {
Trade trade = adaptTrade(coinmateEntry);
trades.add(trade);
}
// TODO correct sort order?
return new Trades(trades, Trades.TradeSortType.SortByID);
}
use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class GeminiAdaptersTest method testAdaptTradeHistory.
@Test
public void testAdaptTradeHistory() {
GeminiTradeResponse[] responses = initTradeResponses();
Trades trades = GeminiAdapters.adaptTradeHistory(responses, SYMBOL);
assertEquals(trades.getTrades().size(), responses.length);
for (int i = 0; i < responses.length; i++) {
Trade trade = trades.getTrades().get(i);
long expectedTimestampMillis = responses[i].getTimestamp().multiply(new BigDecimal(1000L)).longValue();
Order.OrderType expectedOrderType = responses[i].getType().equalsIgnoreCase("buy") ? OrderType.BID : OrderType.ASK;
assertEquals(responses[i].getPrice(), trade.getPrice());
assertEquals(responses[i].getAmount(), trade.getOriginalAmount());
assertEquals(GeminiAdapters.adaptCurrencyPair(SYMBOL), trade.getCurrencyPair());
assertEquals(expectedTimestampMillis, trade.getTimestamp().getTime());
assertEquals(expectedOrderType, trade.getType());
assertEquals(responses[i].getTradeId(), trade.getId());
}
}
use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.
the class HitbtcAdapters method adaptTrades.
public static Trades adaptTrades(List<? extends HitbtcTrade> allHitbtcTrades, CurrencyPair currencyPair) {
List<Trade> trades = new ArrayList<>(allHitbtcTrades.size());
long lastTradeId = 0;
for (int i = 0; i < allHitbtcTrades.size(); i++) {
HitbtcTrade hitbtcTrade = allHitbtcTrades.get(i);
Date timestamp = hitbtcTrade.getTimestamp();
BigDecimal price = hitbtcTrade.getPrice();
BigDecimal amount = hitbtcTrade.getQuantity();
String tid = hitbtcTrade.getId();
long longTradeId = tid == null ? 0 : Long.parseLong(tid);
if (longTradeId > lastTradeId) {
lastTradeId = longTradeId;
}
OrderType orderType = adaptSide(hitbtcTrade.getSide());
Trade trade = new Trade.Builder().type(orderType).originalAmount(amount).currencyPair(currencyPair).price(price).timestamp(timestamp).id(tid).build();
trades.add(trade);
}
return new Trades(trades, lastTradeId, Trades.TradeSortType.SortByTimestamp);
}
Aggregations