Search in sources :

Example 1 with HitbtcOrderBook

use of org.knowm.xchange.hitbtc.v2.dto.HitbtcOrderBook in project XChange by knowm.

the class HitbtcMarketDataDemo method raw.

private static void raw(HitbtcMarketDataServiceRaw marketDataService) throws IOException {
    HitbtcTicker ticker = marketDataService.getHitbtcTicker(CurrencyPair.BTC_USD);
    System.out.println("BTC/USD Ticker: " + ticker.toString());
    Map<String, HitbtcTicker> tickers = marketDataService.getHitbtcTickers();
    System.out.println("All Tickers: " + tickers.toString());
    // Get the latest order book data for BTC/USD
    HitbtcOrderBook orderBook = marketDataService.getHitbtcOrderBook(CurrencyPair.BTC_USD);
    System.out.println("Current Order Book size for BTC/USD: " + (orderBook.getAsks().length + orderBook.getBids().length));
    System.out.println(orderBook);
}
Also used : HitbtcOrderBook(org.knowm.xchange.hitbtc.v2.dto.HitbtcOrderBook) HitbtcTicker(org.knowm.xchange.hitbtc.v2.dto.HitbtcTicker)

Example 2 with HitbtcOrderBook

use of org.knowm.xchange.hitbtc.v2.dto.HitbtcOrderBook in project XChange by knowm.

the class HitbtcStreamingMarketDataService method getOrderBook.

@Override
public Observable<OrderBook> getOrderBook(CurrencyPair currencyPair, Object... args) {
    String pair = currencyPair.base.toString() + currencyPair.counter.toString();
    String channelName = getChannelName("orderbook", pair);
    final ObjectMapper mapper = StreamingObjectMapperHelper.getObjectMapper();
    Observable<JsonNode> jsonNodeObservable = service.subscribeChannel(channelName);
    return jsonNodeObservable.map(s -> mapper.readValue(s.toString(), HitbtcWebSocketOrderBookTransaction.class)).map(s -> {
        HitbtcWebSocketOrderBook hitbtcOrderBook = s.toHitbtcOrderBook(orderbooks.getOrDefault(currencyPair, null));
        orderbooks.put(currencyPair, hitbtcOrderBook);
        return HitbtcAdapters.adaptOrderBook(hitbtcOrderBook.toHitbtcOrderBook(), currencyPair);
    });
}
Also used : StreamingMarketDataService(info.bitrich.xchangestream.core.StreamingMarketDataService) HitbtcWebSocketTradesTransaction(info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketTradesTransaction) HitbtcAdapters(org.knowm.xchange.hitbtc.v2.HitbtcAdapters) Arrays(java.util.Arrays) Ticker(org.knowm.xchange.dto.marketdata.Ticker) HitbtcWebSocketOrderBookTransaction(info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketOrderBookTransaction) HitbtcWebSocketTradeParams(info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketTradeParams) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashMap(java.util.HashMap) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) Trades(org.knowm.xchange.dto.marketdata.Trades) StreamingObjectMapperHelper(info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper) HitbtcWebSocketTickerTransaction(info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketTickerTransaction) Objects(java.util.Objects) 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) HitbtcWebSocketOrderBook(info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketOrderBook) JsonNode(com.fasterxml.jackson.databind.JsonNode) HitbtcWebSocketOrderBook(info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketOrderBook) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StreamingMarketDataService (info.bitrich.xchangestream.core.StreamingMarketDataService)1 HitbtcWebSocketOrderBook (info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketOrderBook)1 HitbtcWebSocketOrderBookTransaction (info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketOrderBookTransaction)1 HitbtcWebSocketTickerTransaction (info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketTickerTransaction)1 HitbtcWebSocketTradeParams (info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketTradeParams)1 HitbtcWebSocketTradesTransaction (info.bitrich.xchangestream.hitbtc.dto.HitbtcWebSocketTradesTransaction)1 StreamingObjectMapperHelper (info.bitrich.xchangestream.service.netty.StreamingObjectMapperHelper)1 Observable (io.reactivex.Observable)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)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 Trades (org.knowm.xchange.dto.marketdata.Trades)1 HitbtcAdapters (org.knowm.xchange.hitbtc.v2.HitbtcAdapters)1