Search in sources :

Example 11 with StreamingExchange

use of info.bitrich.xchangestream.core.StreamingExchange in project XChange by knowm.

the class KrakenTickerExample method main.

public static void main(String[] args) throws InterruptedException {
    ExchangeSpecification exchangeSpecification = new ExchangeSpecification(KrakenStreamingExchange.class);
    StreamingExchange krakenExchange = StreamingExchangeFactory.INSTANCE.createExchange(exchangeSpecification);
    krakenExchange.connect().blockingAwait();
    Disposable tickerDis = krakenExchange.getStreamingMarketDataService().getTicker(CurrencyPair.BTC_USD).subscribe(s -> {
        LOG.info("Received {}", s);
    }, throwable -> {
        LOG.error("Fail to get ticker {}", throwable.getMessage(), throwable);
    });
    TimeUnit.SECONDS.sleep(45);
    tickerDis.dispose();
    krakenExchange.disconnect().subscribe(() -> LOG.info("Disconnected"));
}
Also used : Disposable(io.reactivex.disposables.Disposable) StreamingExchange(info.bitrich.xchangestream.core.StreamingExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification)

Example 12 with StreamingExchange

use of info.bitrich.xchangestream.core.StreamingExchange in project XChange by knowm.

the class HitbtcManualExample method main.

public static void main(String[] args) {
    StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange(HitbtcStreamingExchange.class);
    exchange.connect().blockingAwait();
    Disposable orderBookObserver = exchange.getStreamingMarketDataService().getOrderBook(CurrencyPair.BTC_USD).subscribe(orderBook -> {
        LOG.info("First ask: {}", orderBook.getAsks().get(0));
        LOG.info("First bid: {}", orderBook.getBids().get(0));
    }, throwable -> LOG.error("ERROR in getting order book: ", throwable));
    Disposable tradesObserver = exchange.getStreamingMarketDataService().getTrades(CurrencyPair.BTC_USD).subscribe(trade -> {
        LOG.info("TRADE: {}", trade);
    }, throwable -> LOG.error("ERROR in getting trade: ", throwable));
    Disposable tickerObserver = exchange.getStreamingMarketDataService().getTicker(CurrencyPair.ETH_BTC).subscribe(ticker -> {
        LOG.info("TICKER: {}", ticker);
    }, throwable -> LOG.error("ERROR in getting ticker: ", throwable));
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    orderBookObserver.dispose();
    tradesObserver.dispose();
    tickerObserver.dispose();
    exchange.disconnect().subscribe(() -> LOG.info("Disconnected"));
}
Also used : Disposable(io.reactivex.disposables.Disposable) StreamingExchange(info.bitrich.xchangestream.core.StreamingExchange)

Example 13 with StreamingExchange

use of info.bitrich.xchangestream.core.StreamingExchange in project quant by jessethouin.

the class CexIOLive method main.

/*
        String url = "wss://ws.cex.io/ws";
        String user = "up133530546";
        String key = "SGeoKNIsUqchpeXwolppGWeUEI";
        String secret = "Cvadx7qhFPr8q6roV3nmLFDyE";
 **/
public static void main(String[] args) {
    StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange(CexioStreamingExchange.class);
    exchange.connect().blockingAwait();
    Disposable subscription = exchange.getStreamingMarketDataService().getOrderBook(CurrencyPair.BTC_USD).subscribe(orderBook -> {
        LOG.info("Order book: {}", orderBook);
        List<LimitOrder> asks = orderBook.getAsks();
        asks.sort(Comparator.comparing(LimitOrder::getLimitPrice));
        LOG.info("asks: {}", asks);
    });
    COMPOSITE_DISPOSABLE.add(subscription);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) CexioStreamingExchange(info.bitrich.xchangestream.cexio.CexioStreamingExchange) StreamingExchange(info.bitrich.xchangestream.core.StreamingExchange) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Example 14 with StreamingExchange

use of info.bitrich.xchangestream.core.StreamingExchange in project XChange by knowm.

the class BitstampManualExample method main.

public static void main(String[] args) {
    ExchangeSpecification defaultExchangeSpecification = new ExchangeSpecification(BitstampStreamingExchange.class);
    defaultExchangeSpecification.setExchangeSpecificParametersItem(ConnectableService.BEFORE_CONNECTION_HANDLER, (Runnable) BitstampManualExample::rateLimit);
    StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange(defaultExchangeSpecification);
    exchange.connect().blockingAwait();
    Disposable orderBookDisposable = ((BitstampStreamingMarketDataService) exchange.getStreamingMarketDataService()).getFullOrderBook(CurrencyPair.BTC_USD).subscribe(orderBook -> {
        LOG.info("First ask: {}", orderBook.getAsks().get(0));
        LOG.info("First bid: {}", orderBook.getBids().get(0));
    });
    Disposable tradesDisposable = exchange.getStreamingMarketDataService().getTrades(CurrencyPair.BTC_USD).subscribe(trade -> {
        LOG.info("Trade {}", trade);
    });
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    orderBookDisposable.dispose();
    tradesDisposable.dispose();
    exchange.disconnect().subscribe(() -> LOG.info("Disconnected from the Exchange"));
    rateLimiter.shutdown();
}
Also used : Disposable(io.reactivex.disposables.Disposable) BitstampStreamingExchange(info.bitrich.xchangestream.bitstamp.v2.BitstampStreamingExchange) StreamingExchange(info.bitrich.xchangestream.core.StreamingExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification)

Example 15 with StreamingExchange

use of info.bitrich.xchangestream.core.StreamingExchange in project XChange by knowm.

the class BTCMarketsManualExample method main.

public static void main(String[] args) {
    ExchangeSpecification defaultExchangeSpecification = new ExchangeSpecification(BTCMarketsStreamingExchange.class);
    StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange(defaultExchangeSpecification);
    exchange.connect().blockingAwait();
    Disposable btcOrderBookDisposable = exchange.getStreamingMarketDataService().getOrderBook(CurrencyPair.BTC_AUD).forEach(orderBook -> {
        logger.info("First btc ask: {}", orderBook.getAsks().get(0));
        logger.info("First btc bid: {}", orderBook.getBids().get(0));
    });
    Disposable ethOrderBookDisposable = exchange.getStreamingMarketDataService().getOrderBook(CurrencyPair.ETH_AUD).forEach(orderBook -> {
        logger.info("First eth ask: {}", orderBook.getAsks().get(0));
        logger.info("First eth bid: {}", orderBook.getBids().get(0));
    });
    Disposable btcTickerDisposable = exchange.getStreamingMarketDataService().getTicker(CurrencyPair.BTC_AUD).forEach(ticker -> {
        logger.info("BTC: First  ask: {}", ticker.getAsk());
        logger.info("BTC: First bid: {}", ticker.getBid());
        logger.info("BTC: last price: {}", ticker.getLast());
        logger.info("BTC: 24h volume  {}", ticker.getVolume());
        logger.info("BTC: timestamp {}", ticker.getVolume());
    });
    try {
        Thread.sleep(30000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    btcOrderBookDisposable.dispose();
    ethOrderBookDisposable.dispose();
    btcTickerDisposable.dispose();
    exchange.disconnect().subscribe(() -> logger.info("Disconnected from the Exchange"));
}
Also used : Disposable(io.reactivex.disposables.Disposable) StreamingExchange(info.bitrich.xchangestream.core.StreamingExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification)

Aggregations

StreamingExchange (info.bitrich.xchangestream.core.StreamingExchange)28 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)16 Disposable (io.reactivex.disposables.Disposable)14 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)7 Test (org.junit.Test)6 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)3 ProductSubscription (info.bitrich.xchangestream.core.ProductSubscription)2 StreamingExchangeFactory (info.bitrich.xchangestream.core.StreamingExchangeFactory)2 StreamingMarketDataService (info.bitrich.xchangestream.core.StreamingMarketDataService)2 StreamingTradeService (info.bitrich.xchangestream.core.StreamingTradeService)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 BigDecimal (java.math.BigDecimal)2 Currency (org.knowm.xchange.currency.Currency)2 USE_REALTIME_BOOK_TICKER (info.bitrich.xchangestream.binance.BinanceStreamingExchange.USE_REALTIME_BOOK_TICKER)1 BitstampStreamingExchange (info.bitrich.xchangestream.bitstamp.v2.BitstampStreamingExchange)1 CexioStreamingExchange (info.bitrich.xchangestream.cexio.CexioStreamingExchange)1 CoinbaseProStreamingExchange (info.bitrich.xchangestream.coinbasepro.CoinbaseProStreamingExchange)1 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)1