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