3

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:

  • Host: websocket.mtgox.com or socketio.mtgox.com
  • Port: 80 or 443 ( ssl )
  • Namespace: /mtgox (Including beginning slash)

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.

4

1 回答 1

2

我在这里查看了源代码和手册 - h​​ttps://github.com/rstudio/R-Websockets

R Websocket 库已过时,不符合现有的 WebSocket 协议。

因此,您需要修复库或找到替代库。根据您的能力,修复库并不难。我设法在这里做到了-

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

我的一个(懒惰地)硬编码到 MtGox - 使用风险自负!您需要删除当前的 WebSocket 库并安装它。不要忘记你的代码只是做基本的连接。还有几个步骤可以查看实际数据 -

set_callback("receive", function(DATA,WS,HEADER) cat(rawToChar(DATA)), con)
service (con)
于 2013-05-20T15:25:59.203 回答