Search in sources :

Example 1 with BitsoTransaction

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);
}
Also used : Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) BitsoTransaction(org.knowm.xchange.bitso.dto.marketdata.BitsoTransaction) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 BitsoTransaction (org.knowm.xchange.bitso.dto.marketdata.BitsoTransaction)1 Order (org.knowm.xchange.dto.Order)1 Trade (org.knowm.xchange.dto.marketdata.Trade)1 Trades (org.knowm.xchange.dto.marketdata.Trades)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 UserTrade (org.knowm.xchange.dto.trade.UserTrade)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1