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();
}
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);
}
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;
});
}
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();
});
}
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;
}
Aggregations