Bitcoin Forum
November 13, 2024, 10:44:15 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: Bitfinex's streaming (websocket) api  (Read 5479 times)
bricky (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
March 05, 2015, 12:19:14 PM
 #1

Been messing around with the bitfinex streaming api on ws.bitfinex.com:3333 with a view to getting a realtime order book.

The server is obviously websocket-rails, and the bitfinex website itself provides a fairly complete client (in its application-XXX.js file).  When I subscribe to "ticker", I get "ticker.new" messages like this:

Code:
{"pair":"BTCUSD","buying":"270.15","selling":"270.36","last":"270.38","daily_change":"-9.82"}

These are great of course, but not sufficient to build up an order book.

There's also a "trade.btcusd" (and presumably other pairs) which gives:

Code:
{"pair":"BTCUSD","price":"270.97","amount":"0.27","side":0,"timestamp":"1425505661.56676188"}

for every trade (presumably).

I've tried all kinds of variations of order, book, orderbook, books (with various pairs added to the end), but I can't find what to subscribe to for a realtime order book.

(of course I'm only guessing that such a thing is there)
wilfried
Sr. Member
****
Offline Offline

Activity: 288
Merit: 250


ManualMiner


View Profile
March 22, 2015, 12:38:12 PM
 #2

wow, cool, finally after 1,5 years something moves with the websocket interface.
does it still work?
so they changed their site to use websocket -a guy here claims its using ajax polling
https://github.com/timmolter/XChange/issues/630

gtz
bricky (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
March 22, 2015, 02:33:08 PM
 #3

so they changed their site to use websocket -a guy here claims its using ajax polling

It uses ajax for the order book, but it uses websockets for the ticker and for tracking your own open orders (those pnotify messages for example are in response to websocket events).

I subscribed to the depth.pair channels also (with much hope!), but the orderbook it gives is incorrect.  It does appear to be related to the real order book, but I think (at a guess) it might be missing order replace and order cancel events.  (Curiously though, I think it might be leaking some hidden order data)

Anyway, I live in hope for the new api they're promising Smiley
wilfried
Sr. Member
****
Offline Offline

Activity: 288
Merit: 250


ManualMiner


View Profile
March 23, 2015, 08:27:37 AM
 #4

is there a schedule given from them for the new api?
wilfried
Sr. Member
****
Offline Offline

Activity: 288
Merit: 250


ManualMiner


View Profile
March 29, 2015, 09:55:45 AM
 #5

is it still working for you ?
i get "integer required" messages only.

heres a thread bout the channels:

https://github.com/timmolter/XChange/issues/630
bricky (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
March 30, 2015, 09:38:47 AM
 #6

Yup, it's still working (just checked depth.ltcbtc), but the order book it gives is still wrong. Sad



Edit: to clarify

I first take a snapshot of the order book via the regular api, then modify it as changes come through the websocket.
Most of the websocket events are correct - but it seems to be missing either the order change or cancel events, so over time an error builds up.  As it is it's unusable.

(although it's completely possible that I'm just doing something stupid and it's fully functional!)
czzarr
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
April 13, 2015, 01:24:47 PM
 #7

bricky, I get disconnected like after 10 seconds when I connect from nodejs. Do you have the same problem? Also how did you discover the channels that are available (like depth) ?
bricky (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
April 13, 2015, 01:38:36 PM
 #8

bricky, I get disconnected like after 10 seconds when I connect from nodejs. Do you have the same problem?

I wasn't getting disconnected, but the socket went silent (after maybe a minute?) if I didn't reply to pings - maybe that's what's happening to you?  The implementation is actually very straightforward - take a look at the application-*.js file on the bitfinex site to see how they do it.

(never did a websocket client myself in node, so I can't help you on that front I'm afraid)


Also how did you discover the channels that are available (like depth) ?

By looking through the client on the website (it uses the websocket for tickers and order tracking for example), some googling, and plain guesswork Smiley
Vieux
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
April 13, 2015, 02:40:15 PM
 #9

Did anyone gets a message on the depth.pair channel?

Quote
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"}

czzarr
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
April 14, 2015, 04:10:26 PM
 #10


I wasn't getting disconnected, but the socket went silent (after maybe a minute?) if I didn't reply to pings - maybe that's what's happening to you?  The implementation is actually very straightforward - take a look at the application-*.js file on the bitfinex site to see how they do it.

(never did a websocket client myself in node, so I can't help you on that front I'm afraid)

I thought it was that at first, but I keep getting the behavior you describe, even when I pong back. Are you authenticated?
bricky (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
April 14, 2015, 07:37:27 PM
Last edit: April 14, 2015, 08:50:23 PM by bricky
 #11


I wasn't getting disconnected, but the socket went silent (after maybe a minute?) if I didn't reply to pings - maybe that's what's happening to you?  The implementation is actually very straightforward - take a look at the application-*.js file on the bitfinex site to see how they do it.

(never did a websocket client myself in node, so I can't help you on that front I'm afraid)

I thought it was that at first, but I keep getting the behavior you describe, even when I pong back. Are you authenticated?

No, I'm not authenticated.  Maybe you're not sending back the connection_id in your pong?

(I had posted a bunch of code here, but I think there's no point, you're almost certainly missing the connection_id)

This is what the pong should look like:

Code:
["websocket_rails.pong", {"data":{"connection_id": "%s" }}]

where the %s is your connection_id (you'll get that in your first 'client_connected' message you get back)

Did anyone gets a message on the depth.pair channel?

Yes (read the thread!)   Wink
czzarr
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
April 15, 2015, 08:22:56 AM
 #12

ah cool it worked thanks! I had spied on the pongs of the bitfinex.com client and didn't see the connectionId being passed, weird.
bricky (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
April 15, 2015, 12:02:55 PM
 #13

ah cool it worked thanks! I had spied on the pongs of the bitfinex.com client and didn't see the connectionId being passed, weird.

Very welcome Smiley

If you can get a reliable book out of it please let me know how you do it!  Been messing around with it again over the last 24 hrs, and it is soooooo tantalizingly close!
czzarr
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
April 22, 2015, 09:29:07 AM
 #14

Have you found out a trades channel? I tried trade, trades, trade.btcusd and trades.btcusd to no avail.
bricky (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
April 22, 2015, 01:39:27 PM
 #15

Have you found out a trades channel? I tried trade, trades, trade.btcusd and trades.btcusd to no avail.

Yeah, it's working, tried it just now:


Code:
> ["websocket_rails.subscribe", {"data":{"channel": "trade.btcusd" }}]
< text: [["websocket_rails.channel_token",{"id":null,"channel":"trade.btcusd","user_id":null,"data":{"token":"fa1222b8-0e2f-4e8b-bcbb-165ea6d40d35"},"success":null,"result":null,"token":null,"server_token":null}]]
< text: [["websocket_rails.subscribe",{"id":null,"channel":null,"user_id":null,"data":null,"success":true,"result":null,"token":null,"server_token":null}]]
< text: [["trade.new",{"id":null,"channel":"trade.btcusd","user_id":null,"data":{"pair":"BTCUSD","price":"235.4","amount":"4.81834136","side":1,"timestamp":"1429709841.026109114"},"success":null,"result":null,"token":"fa1222b8-0e2f-4e8b-bcbb-165ea6d40d35","server_token":"MsoF3fiWaVg1YKThhtQ48g"}]]
< text: [["trade.new",{"id":null,"channel":"trade.btcusd","user_id":null,"data":{"pair":"BTCUSD","price":"235.4","amount":"0.18165864","side":1,"timestamp":"1429709841.114709611"},"success":null,"result":null,"token":"fa1222b8-0e2f-4e8b-bcbb-165ea6d40d35","server_token":"MsoF3fiWaVg1YKThhtQ48g"}]]
czzarr
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
April 22, 2015, 02:12:33 PM
 #16

right, I'm not sure what went wrong when I tried that. Anyway, thanks.
bricky (OP)
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
June 06, 2015, 04:03:49 PM
Last edit: June 06, 2015, 05:30:52 PM by bricky
 #17

Hi xspdr.

Your path for the websocket is wrong (that's what a 404 means).  It should be 'wss://ws.bitfinex.com:3333/websocket'.
You will almost certainly need to go through the js on the site to see how to connection works, this is very unlike okcoin, and there are several steps involved in getting this working.  I'd suggest actually that you wait for the "official" websocket api to be release (along with documentation) - it can't be very far away now.

Note: what I've said above still stands as far as I know - the orderbook this gives is still incomplete.  This is why no one uses it.

Please don't PM me your questions again.

thanks




Edit: and then he goes off and deletes his post so that my reply is pointless.  Thanks for that dude.
czzarr
Newbie
*
Offline Offline

Activity: 17
Merit: 0


View Profile
June 24, 2015, 08:56:50 AM
 #18

Hi bricky, do you still receive trade.new messages ? I don't...
wamatt
Member
**
Offline Offline

Activity: 85
Merit: 10


View Profile
September 14, 2015, 10:34:19 PM
 #19

Is bitfinex's websocket implementation working/live? I can connect successfully, but don't get any trade data streaming in...

Anyone had any success with this?
wamatt
Member
**
Offline Offline

Activity: 85
Merit: 10


View Profile
September 14, 2015, 10:54:53 PM
 #20

Using the subscribe as per bricky's post, I got some trades coming back. So thats good Smiley

However the reason it stops sending data is that it's expecting a response to the websocket_rails.ping event.

Code:
[["websocket_rails.ping",{"id":null,"channel":null,"user_id":null,"data":{},"success":null,"result":null,"token":null,"server_token":null}]]
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!