This project has now been merged into the XChange library. There will be no further releases and pull requests will not be accepted. Please use XChange from 5.0.0-SNAPSHOT
onwards, which is, for now, 100% compatible.
XChange-stream is a Java library providing a simple and consistent streaming API for interacting with Bitcoin and other crypto currency exchanges via WebSocket protocol.
It is build on top of the XChange library providing new interfaces for the exchanges' streaming APIs. Users can subscribe for live updates via reactive streams of RxJava library.
Xchange-stream is on Maven Central. You will need xchange-stream-core
dependency and xchange-XYZ
where XYZ is supported exchange (eg. xchange-bitstamp
). Add the following into your pom.xml
.
<dependency>
<groupId>info.bitrich.xchange-stream</groupId>
<artifactId>xchange-stream-core</artifactId>
<version>x.y.z</version>
</dependency>
<dependency>
<groupId>info.bitrich.xchange-stream</groupId>
<artifactId>xchange-XYZ</artifactId>
<version>x.y.z</version>
</dependency>
For snapshots version (built from develop branch), add the following repository to your pom.xml
file.
<repository>
<id>sonatype-oss-snapshot</id>
<snapshots/>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
XChange-stream follows major and minor version from XChange library. So version 4.2.x is based on latest 4.2. release of XChange.
Use the same library as XChange but instead of ExchangeFactory
use StreamingExchangeFactory
that creates StreamingExchange
instead of Exchange
. Then you can call getStreamingMarketDataService
to subscribe to trade data.
StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange(BitstampStreamingExchange.class.getName());
// Connect to the Exchange WebSocket API. Blocking wait for the connection.
exchange.connect().blockingAwait();
// Subscribe to live trades update.
exchange.getStreamingMarketDataService()
.getTrades(CurrencyPair.BTC_USD)
.subscribe(trade -> {
LOG.info("Incoming trade: {}", trade);
}, throwable -> {
LOG.error("Error in subscribing trades.", throwable);
});
// Subscribe order book data with the reference to the subscription.
Disposable subscription = exchange.getStreamingMarketDataService()
.getOrderBook(CurrencyPair.BTC_USD)
.subscribe(orderBook -> {
// Do something
});
// Unsubscribe from data order book.
subscription.dispose();
// Disconnect from exchange (non-blocking)
exchange.disconnect().subscribe(() -> LOG.info("Disconnected from the Exchange"));
More information about reactive streams can be found at RxJava wiki.
Listening for live updates of:
Exchange | order books | trades (public) | tickers | balances | trades (user) | open orders | notes |
---|---|---|---|---|---|---|---|
Bankera | :heavy_check_mark: | :heavy_check_mark: | :construction: | :question: | :question: | :question: | Ticker support could be implemented using the trades and order book streams, even though the exchange doesn't explicitly return a ticker stream. |
Binance | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
Bitfinex | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
Bitflyer | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :question: | :question: | :question: | |
BitMEX | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :construction: | :construction: | :construction: | We are short of maintainers able to review pull requests and provide support for Bitmex, so there is a backlog of pull requests and support is likely broken. Can you help? See #180 for reference if attempting to add private channel support. |
Bitstamp | :heavy_check_mark: | :heavy_check_mark: | :x: | :question: | :question: | :question: | |
CEX.IO | :heavy_check_mark: | :x: | :x: | :question: | :question: | :question: | New support, not widely tested |
Coinbase Pro | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
Coinmate | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
Gemini | :heavy_check_mark: | :heavy_check_mark: | :x: | :construction: | :construction: | :construction: | |
Kraken | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: | :heavy_check_mark: | :heavy_check_mark: | |
LGO | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | |
OKCoin | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :question: | :question: | :question: | |
OKEx | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :question: | :question: | :question: | See #180 for reference if attempting to add private channel support. |
Poloniex | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :question: | :question: | :question: |
If you missing a specific exchange implementation, feel free to propose a pull request or open an issue with some sweet BTC bounty.
This is an, not so complete, list of projects that use XChange-Stream, feel free to add your project below.
Copyright 2017 Zdenek Dolezal, Michal Oprendek
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.