use of info.bitrich.xchangestream.gemini.dto.GeminiWebSocketTransaction in project XChange by knowm.
the class GeminiStreamingMarketDataService method getOrderBook.
@Override
public Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... args) {
int maxDepth = (int) MoreObjects.firstNonNull(args.length > 0 ? args[0] : null, 1);
Observable<GeminiOrderbook> subscribedOrderbookSnapshot = service.subscribeChannel(currencyPair, maxDepth, maxDepth).filter(s -> filterEventsByReason(s, "change", "initial") || filterEventsByReason(s, "change", "place") || filterEventsByReason(s, "change", "cancel") || filterEventsByReason(s, "change", "trade")).filter(// filter out updates that arrive before initial book
s -> orderbooks.get(currencyPair) != null || filterEventsByReason(s, "change", "initial")).map((JsonNode s) -> {
if (filterEventsByReason(s, "change", "initial")) {
GeminiWebSocketTransaction transaction = mapper.treeToValue(s, GeminiWebSocketTransaction.class);
GeminiOrderbook orderbook = transaction.toGeminiOrderbook(currencyPair);
orderbooks.put(currencyPair, orderbook);
return orderbook;
}
if (filterEventsByReason(s, "change", "place") || filterEventsByReason(s, "change", "cancel") || filterEventsByReason(s, "change", "trade")) {
GeminiWebSocketTransaction transaction = mapper.treeToValue(s, GeminiWebSocketTransaction.class);
GeminiLimitOrder[] levels = transaction.toGeminiLimitOrdersUpdate();
GeminiOrderbook orderbook = orderbooks.get(currencyPair);
orderbook.updateLevels(levels);
return orderbook;
}
throw new NotYetImplementedForExchangeException(" Unknown message type, even after filtering: " + s.toString());
});
return subscribedOrderbookSnapshot.map(geminiOrderbook -> GeminiAdaptersX.toOrderbook(geminiOrderbook, maxDepth, new Date()));
}
use of info.bitrich.xchangestream.gemini.dto.GeminiWebSocketTransaction in project XChange by knowm.
the class GeminiStreamingService method getRawWebSocketTransactions.
public Observable<GeminiWebSocketTransaction> getRawWebSocketTransactions(CurrencyPair currencyPair, boolean filterChannelName) {
String channelName = currencyPair.base.toString() + currencyPair.counter.toString();
final ObjectMapper mapper = StreamingObjectMapperHelper.getObjectMapper();
return subscribeChannel(channelName).map(s -> mapper.readValue(s.toString(), GeminiWebSocketTransaction.class)).filter(t -> channelName.equals(t.getSymbol())).filter(t -> !StringUtil.isNullOrEmpty(t.getType()));
}
Aggregations