knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.87k stars 1.94k forks source link

Add Support for Bitfinex's WebSocket Feeds #630

Closed evdubs closed 9 years ago

evdubs commented 10 years ago

Here are two emails I have from Raphael of Bitfinex regarding the trade and order book feeds for both liquidity swaps and currency pairs:

Liquidity swaps

So you can connect to our websocket by connecting to wss://ws.bitfinex.com:3333 To subscribe to channel you have to send the following message format: ["websocket_rails.subscribe", {"data":{"channel": "" }}]

To get access to the last swaps match, you have to subscribe to the channel swap.currency For example, for USD swaps, you subscribe to swap.usd, with the following message: ["websocket_rails.subscribe", {"data":{"channel": "swap.usd" }}]

On those channel you will receive "swap.new" events, with a message detailing the swap rate, the period, the timestamp, the amount of the new swap open. Example of message: {"currency"=>"USD", "rate"=>"0.00116", "amount"=>"157.19701514", "period"=>2, "side"=>2, "timestamp"=>"1407157560.841075061"}

Similarly, you can subscribe to the channels swapdepth.currency to get notification of orderbook depth change. You will get events called "depth.change", with messages like this: {"currency"=>"USD", "rate"=>"0.00117808219178082192", "period"=>2, "type"=>"offer", "total_amount"=>"50.0", "change"=>"50.0", "timestamp"=>"1407157376.464844678"}

(total amount is the total amount of depth at this rate and period, while "change" is the difference after the current change.

Currency pairs

The trades are on "trade." channels, while the change of depth are on "depth." channels.

For trade.pair channels, you will receive trade.new events: Example: {"pair"=>"BTCUSD", "price"=>"519.0", "amount"=>"0.1", "side"=>0, "timestamp"=>"1408728031.842133865"}

For depth.pair channels you will receive depth.change events, like this: {"pair"=>"BTCUSD", "price"=>"624.24", "type"=>"ask", "change"=>"0.02", "timestamp"=>"1406031564.387416988"}

evdubs commented 10 years ago

I intend to work on this for currency pairs.

jheusser commented 10 years ago

@evdubs do you know, are the websockets also available for normal exchange data on Bitfinex?

evdubs commented 10 years ago

@jheusser If you mean anything other than currency pairs and swaps, the answer is no. There is no streaming for account information, nor trade confirmations or status updates.

evdubs commented 10 years ago

I meant to say that nothing else is available as far as I know. I only asked for the currency pair feeds and the swap feeds.

STRML commented 10 years ago

I haven't been able to get any of those to work, but I get a very verbose ticker with:

["websocket_rails.subscribe", {"data":{"channel": "ticker" }}]

erlendd commented 9 years ago

I am correct in saying that none of the above websocket stuff works any longer? Has the address of the websocket server changed?

STRML commented 9 years ago

It doesn't look like they intend to offer this as an actual public feed. Their site, last time I checked, just did Ajax polling.

timmolter commented 9 years ago

No streaming API as I can see.

evdubs commented 9 years ago

The streaming API does indeed work. I have gotten it to work with tyrus-standalone-client for WebSockets over HTTPS, which is not supported with the published (and XChange dependency) Java-Websocket project. One thing that has made it clunky to use is that Bitfinex and RapidSSL have both updated their certificates since at least the RapidSSL certificate was included with a Java 7 JRE. To get it working, you need to manually add the certificates to a Java keystore. From there, all of the above documentation from Raphael is consistent with the functionality of the WebSocket service. Another thing that makes it clunky is that the currency pair feed doesn't include a "total_amount" field. This can make synchronizing between the order book REST GET and order book update feed somewhat cumbersome. It is also apparently still in beta, so it may be changed without notice.

brobits commented 8 years ago

http://docs.bitfinex.com/#ssl-websocket-connection