Search in sources :

Example 1 with GeminiOrderbook

use of info.bitrich.xchangestream.gemini.dto.GeminiOrderbook 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()));
}
Also used : StreamingMarketDataService(info.bitrich.xchangestream.core.StreamingMarketDataService) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) GeminiOrderbook(info.bitrich.xchangestream.gemini.dto.GeminiOrderbook) Ticker(org.knowm.xchange.dto.marketdata.Ticker) GeminiTrade(org.knowm.xchange.gemini.v1.dto.marketdata.GeminiTrade) Date(java.util.Date) GeminiAdapters.adaptTrades(org.knowm.xchange.gemini.v1.GeminiAdapters.adaptTrades) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MoreObjects(com.google.common.base.MoreObjects) HashMap(java.util.HashMap) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) GeminiLimitOrder(info.bitrich.xchangestream.gemini.dto.GeminiLimitOrder) StreamingObjectMapperHelper(info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper) GeminiWebSocketTransaction(info.bitrich.xchangestream.gemini.dto.GeminiWebSocketTransaction) PublishSubject(io.reactivex.subjects.PublishSubject) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Observable(io.reactivex.Observable) Trade(org.knowm.xchange.dto.marketdata.Trade) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) GeminiOrderbook(info.bitrich.xchangestream.gemini.dto.GeminiOrderbook) GeminiWebSocketTransaction(info.bitrich.xchangestream.gemini.dto.GeminiWebSocketTransaction) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) JsonNode(com.fasterxml.jackson.databind.JsonNode) GeminiLimitOrder(info.bitrich.xchangestream.gemini.dto.GeminiLimitOrder) Date(java.util.Date)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MoreObjects (com.google.common.base.MoreObjects)1 StreamingMarketDataService (info.bitrich.xchangestream.core.StreamingMarketDataService)1 GeminiLimitOrder (info.bitrich.xchangestream.gemini.dto.GeminiLimitOrder)1 GeminiOrderbook (info.bitrich.xchangestream.gemini.dto.GeminiOrderbook)1 GeminiWebSocketTransaction (info.bitrich.xchangestream.gemini.dto.GeminiWebSocketTransaction)1 StreamingObjectMapperHelper (info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper)1 Observable (io.reactivex.Observable)1 PublishSubject (io.reactivex.subjects.PublishSubject)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)1 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)1 Ticker (org.knowm.xchange.dto.marketdata.Ticker)1 Trade (org.knowm.xchange.dto.marketdata.Trade)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)1 GeminiAdapters.adaptTrades (org.knowm.xchange.gemini.v1.GeminiAdapters.adaptTrades)1