Search in sources :

Example 91 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class GeminiAdapters method adaptTrade.

public static Trade adaptTrade(GeminiTrade trade, CurrencyPair currencyPair) {
    OrderType orderType = trade.getType().equals("buy") ? OrderType.BID : OrderType.ASK;
    BigDecimal amount = trade.getAmount();
    BigDecimal price = trade.getPrice();
    Date date = // Gemini 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 : GeminiTrade(org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) OrderType(org.knowm.xchange.dto.Order.OrderType) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Example 92 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class PaymiumAdapters method adaptTrade.

public static Trades adaptTrade(PaymiumTrade[] PaymiumTrades, CurrencyPair currencyPair) {
    List<Trade> trades = new ArrayList<>();
    for (PaymiumTrade PaymiumTrade : PaymiumTrades) {
        Trade trade = new Trade.Builder().originalAmount(PaymiumTrade.getTraded_btc()).currencyPair(currencyPair).price(PaymiumTrade.getPrice()).timestamp(new Date(PaymiumTrade.getCreated_at_int())).id(PaymiumTrade.getUuid().toString()).build();
        trades.add(trade);
    }
    return new Trades(trades, Trades.TradeSortType.SortByTimestamp);
}
Also used : PaymiumTrade(org.knowm.xchange.paymium.dto.marketdata.PaymiumTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) Trades(org.knowm.xchange.dto.marketdata.Trades) PaymiumTrade(org.knowm.xchange.paymium.dto.marketdata.PaymiumTrade) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 93 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class BitmexStreamingMarketDataService method getTrades.

@Override
public Observable<Trade> getTrades(CurrencyPair currencyPair, Object... args) {
    String instrument = getBitmexSymbol(currencyPair);
    String channelName = String.format("trade:%s", instrument);
    return streamingService.subscribeBitmexChannel(channelName).flatMapIterable(s -> {
        BitmexTrade[] bitmexTrades = s.toBitmexTrades();
        List<Trade> trades = new ArrayList<>(bitmexTrades.length);
        for (BitmexTrade bitmexTrade : bitmexTrades) {
            trades.add(bitmexTrade.toTrade());
        }
        return trades;
    });
}
Also used : BitmexTrade(info.bitrich.xchangestream.bitmex.dto.BitmexTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) BitmexTrade(info.bitrich.xchangestream.bitmex.dto.BitmexTrade) ArrayList(java.util.ArrayList)

Example 94 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class BitfinexStreamingMarketDataService method getTrades.

@Override
public Observable<Trade> getTrades(CurrencyPair currencyPair, Object... args) {
    String channelName = "trades";
    final String tradeType = args.length > 0 ? args[0].toString() : "te";
    String pair = pairToSymbol(currencyPair);
    final ObjectMapper mapper = StreamingObjectMapperHelper.getObjectMapper();
    Observable<BitfinexWebSocketTradesTransaction> subscribedChannel = service.subscribeChannel(channelName, new Object[] { pair }).filter(s -> s.get(1).asText().equals(tradeType)).map(s -> {
        if (s.get(1).asText().equals("te") || s.get(1).asText().equals("tu")) {
            return mapper.treeToValue(s, BitfinexWebsocketUpdateTrade.class);
        } else
            return mapper.treeToValue(s, BitfinexWebSocketSnapshotTrades.class);
    });
    return subscribedChannel.flatMapIterable(s -> {
        Trades adaptedTrades = adaptTrades(s.toBitfinexTrades(), currencyPair);
        return adaptedTrades.getTrades();
    });
}
Also used : BitfinexWebSocketTickerTransaction(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketTickerTransaction) StreamingMarketDataService(info.bitrich.xchangestream.core.StreamingMarketDataService) BitfinexAdapters.adaptOrderBook(org.knowm.xchange.bitfinex.service.BitfinexAdapters.adaptOrderBook) BitfinexAdapters.adaptTicker(org.knowm.xchange.bitfinex.service.BitfinexAdapters.adaptTicker) BitfinexOrderbook(info.bitrich.xchangestream.bitfinex.dto.BitfinexOrderbook) Ticker(org.knowm.xchange.dto.marketdata.Ticker) BitfinexWebSocketOrderbookTransaction(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketOrderbookTransaction) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashMap(java.util.HashMap) BitfinexWebSocketSnapshotTrades(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketSnapshotTrades) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) Trades(org.knowm.xchange.dto.marketdata.Trades) StreamingObjectMapperHelper(info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper) BitfinexWebSocketTradesTransaction(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketTradesTransaction) BitfinexWebSocketSnapshotOrderbook(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketSnapshotOrderbook) Currency(org.knowm.xchange.currency.Currency) BitfinexWebSocketUpdateOrderbook(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketUpdateOrderbook) BitfinexWebsocketUpdateTrade(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebsocketUpdateTrade) Map(java.util.Map) Observable(io.reactivex.Observable) Trade(org.knowm.xchange.dto.marketdata.Trade) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) BitfinexAdapters.adaptTrades(org.knowm.xchange.bitfinex.service.BitfinexAdapters.adaptTrades) BitfinexWebSocketTradesTransaction(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketTradesTransaction) BitfinexWebSocketSnapshotTrades(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketSnapshotTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) BitfinexAdapters.adaptTrades(org.knowm.xchange.bitfinex.service.BitfinexAdapters.adaptTrades) BitfinexWebSocketSnapshotTrades(info.bitrich.xchangestream.bitfinex.dto.BitfinexWebSocketSnapshotTrades) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 95 with Trade

use of org.knowm.xchange.dto.marketdata.Trade in project XChange by knowm.

the class PoloniexWebSocketAdapter method convertPoloniexWebSocketTradeEventToTrade.

public static Trade convertPoloniexWebSocketTradeEventToTrade(PoloniexWebSocketTradeEvent poloniexTradeEvent, CurrencyPair currencyPair) {
    TradeEvent tradeEvent = poloniexTradeEvent.getTradeEvent();
    Date timestamp = new Date(tradeEvent.getTimestampSeconds() * 1000L);
    Trade trade = new Trade.Builder().type(tradeEvent.getType()).price(tradeEvent.getPrice()).originalAmount(tradeEvent.getSize()).currencyPair(currencyPair).id(tradeEvent.getTradeId()).timestamp(timestamp).build();
    return trade;
}
Also used : Trade(org.knowm.xchange.dto.marketdata.Trade) Date(java.util.Date)

Aggregations

Trade (org.knowm.xchange.dto.marketdata.Trade)95 Trades (org.knowm.xchange.dto.marketdata.Trades)58 UserTrade (org.knowm.xchange.dto.trade.UserTrade)49 ArrayList (java.util.ArrayList)42 Date (java.util.Date)38 BigDecimal (java.math.BigDecimal)30 UserTrades (org.knowm.xchange.dto.trade.UserTrades)29 OrderType (org.knowm.xchange.dto.Order.OrderType)25 Test (org.junit.Test)21 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 Exchange (org.knowm.xchange.Exchange)8 InputStream (java.io.InputStream)7 Order (org.knowm.xchange.dto.Order)7 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)7 Ticker (org.knowm.xchange.dto.marketdata.Ticker)7 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 StreamingObjectMapperHelper (info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper)5 Observable (io.reactivex.Observable)5