Search in sources :

Example 1 with BitfinexTrade

use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade in project XChange by knowm.

the class BitfinexAdapters method adaptTrades.

public static Trades adaptTrades(BitfinexTrade[] trades, CurrencyPair currencyPair) {
    List<Trade> tradesList = new ArrayList<>(trades.length);
    long lastTradeId = 0;
    for (BitfinexTrade trade : trades) {
        long tradeId = trade.getTradeId();
        if (tradeId > lastTradeId) {
            lastTradeId = tradeId;
        }
        tradesList.add(adaptTrade(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) UserTrades(org.knowm.xchange.dto.trade.UserTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) ArrayList(java.util.ArrayList) BitfinexTrade(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade)

Example 2 with BitfinexTrade

use of org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade in project XChange by knowm.

the class BitfinexAdapters method adaptTrade.

public static Trade adaptTrade(BitfinexTrade trade, CurrencyPair currencyPair) {
    OrderType orderType = trade.getType().equals("buy") ? OrderType.BID : OrderType.ASK;
    BigDecimal amount = trade.getAmount();
    BigDecimal price = trade.getPrice();
    Date date = // Bitfinex uses Unix timestamps
    DateUtils.fromMillisUtc(trade.getTimestamp() * 1000L);
    final String tradeId = String.valueOf(trade.getTradeId());
    return new Trade.Builder().type(orderType).originalAmount(amount).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