use of org.knowm.xchange.bitso.dto.marketdata.BitsoTransaction in project XChange by knowm.
the class BitsoAdapters method adaptTrades.
/**
* Adapts a Transaction[] to a Trades Object
*
* @param transactions The Bitso transactions
* @param currencyPair (e.g. BTC/MXN)
* @return The XChange Trades
*/
public static Trades adaptTrades(BitsoTransaction[] transactions, CurrencyPair currencyPair) {
List<Trade> trades = new ArrayList<>();
long lastTradeId = 0;
for (BitsoTransaction tx : transactions) {
Order.OrderType type;
switch(tx.getSide()) {
case "buy":
type = Order.OrderType.ASK;
break;
case "sell":
type = Order.OrderType.BID;
break;
default:
type = null;
}
final long tradeId = tx.getTid();
if (tradeId > lastTradeId) {
lastTradeId = tradeId;
}
trades.add(new Trade.Builder().type(type).originalAmount(tx.getAmount()).currencyPair(currencyPair).price(tx.getPrice()).timestamp(DateUtils.fromMillisUtc(tx.getDate() * 1000L)).id(String.valueOf(tradeId)).build());
}
return new Trades(trades, lastTradeId, TradeSortType.SortByID);
}
Aggregations