Search in sources :

Example 1 with BitfinexPublicTrade

use of org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade in project XChange by knowm.

the class BitfinexAdapters method adaptPublicTrades.

public static Trades adaptPublicTrades(BitfinexPublicTrade[] trades, CurrencyPair currencyPair) {
    List<Trade> tradesList = new ArrayList<>(trades.length);
    long lastTradeId = 0;
    for (BitfinexPublicTrade trade : trades) {
        long tradeId = trade.getTradeId();
        if (tradeId > lastTradeId) {
            lastTradeId = tradeId;
        }
        tradesList.add(adaptPublicTrade(trade, currencyPair));
    }
    return new Trades(tradesList, lastTradeId, TradeSortType.SortByID);
}
Also used : BitfinexTrade(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade) BitfinexPublicTrade(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) BitfinexPublicTrade(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList)

Example 2 with BitfinexPublicTrade

use of org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade in project XChange by knowm.

the class BitfinexAdapters method adaptPublicTrade.

public static Trade adaptPublicTrade(BitfinexPublicTrade trade, CurrencyPair currencyPair) {
    OrderType orderType = trade.getType();
    BigDecimal amount = trade.getAmount();
    BigDecimal price = trade.getPrice();
    Date date = DateUtils.fromMillisUtc(trade.getTimestamp());
    final String tradeId = String.valueOf(trade.getTradeId());
    return new Trade.Builder().type(orderType).originalAmount(amount == null ? null : amount.abs()).currencyPair(currencyPair).price(price).timestamp(date).id(tradeId).build();
}
Also used : BitfinexTrade(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade) BitfinexPublicTrade(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Aggregations

BitfinexTrade (org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade)2 BitfinexPublicTrade (org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade)2 Trade (org.knowm.xchange.dto.marketdata.Trade)2 UserTrade (org.knowm.xchange.dto.trade.UserTrade)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 BitfinexOrderType (org.knowm.xchange.bitfinex.v1.BitfinexOrderType)1 OrderType (org.knowm.xchange.dto.Order.OrderType)1 Trades (org.knowm.xchange.dto.marketdata.Trades)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1