Steef Gregor
Steef Gregor

Reputation: 544

websocket connection does not work

I seem to be in struggle with the websockets in R. I wanted to download the streaming data from the BitCoin exchange MtGox directly to R, but R cannot establish the connection.

The websocket specs are defined as:

url for more details: https://en.bitcoin.it/wiki/MtGox/API/Streaming

and my code is:

require(websockets)
con = websocket("https://socketio.mtgox.com/mtgox",port=443)

and I always end up with an error:

> con = websocket("https://socketio.mtgox.com/mtgox",port=443)
Error in websocket("https://socketio.mtgox.com/mtgox", port = 443) : 
Connection error

Does anyone have an idea what is wrong?

Many thanks.

Upvotes: 3

Views: 1416

Answers (1)

abazlinton
abazlinton

Reputation: 129

I've looked at the source code and manual here - https://github.com/rstudio/R-Websockets

The R Websocket library is out of date and not compliant with the WebSocket protocol as it stands.

So you'd need to fix the library or find an alternate one. Fixing the library isn't that hard depending on your ability. I managed to do it here -

https://github.com/zeenogee/R-Websockets

My one is (lazily) hard-coded to MtGox - use at own risk! You'd need to remove the current WebSocket library and install this one. Don't forget Your code is only doing the basic connection. There are a couple more steps to see actual data -

set_callback("receive", function(DATA,WS,HEADER) cat(rawToChar(DATA)), con)
service (con)

Upvotes: 2

Related Questions