简体   繁体   English

如何通过WebSocket从MtGox获取数据?

[英]How to get data from MtGox through websockets?

I'm trying to connect to it in my C++ app. 我正在尝试在我的C ++应用程序中连接到它。

If I send a handshake to 如果我发送握手给

socketio.mtgox.com:80/mtgox, it doesn't answer socketio.mtgox.com:80/mtgox,它没有回答

websocket.mtgox.com:80/mtgox, it sends 400 Bad request websocket.mtgox.com:80/mtgox,它会发送400错误请求

I Googled this one: 我用谷歌搜索了一个:

socketio.mtgox.com:80/socket.io/1/websocket, this one connects, switches to websocket protocol, then sends me two messages saying "1::" and "2::". socketio.mtgox.com:80/socket.io/1/websocket,这一个连接,切换到websocket协议,然后向我发送两条消息,分别是“ 1 ::”和“ 2 ::”。

In Wireshark everything looks fine. 在Wireshark中,一切看起来都很好。

What do I do on my side? 我该怎么办?

I tried to send {"channel":"24e67e0d-1cad-4cc0-9e7a-f8523ef460fe","op":"subscribe"} - nothing happens... 我尝试发送{“ channel”:“ 24e67e0d-1cad-4cc0-9e7a-f8523ef460fe”,“ op”:“ subscribe”}-没有任何反应...

What's the right URL to connect and what do I send to subscribe to a channel? 什么是连接的正确URL,我发送什么以订阅频道?

Alternatively, can anyone please post a simple .js code that successfully connects to MtGox from a HTML page? 另外,任何人都可以发布一个简单的.js代码来成功地从HTML页面连接到MtGox吗?

Without node.js or socket.io, just a built in HTML5 Websocket class, so I could just have a test working connection sending requests from my computer to make sure it's not a network problem or anything else not related to my program. 没有node.js或socket.io,只有内置的HTML5 Websocket类,因此我只能进行测试工作,以从计算机发送请求,以确保这不是网络问题或与程序无关的任何其他问题。

I have this script: 我有这个脚本:

<script language="javascript" type="text/javascript">

  var output;

  function init()
  {
    output = document.getElementById("output");
    testWebSocket();
  }

  function testWebSocket()
  {
    var websocket = new WebSocket('wss://socketio.mtgox.com:443/mtgox');
    websocket.onopen = function(evt) { onOpen(evt) };
    websocket.onclose = function(evt) { onClose(evt) };
    websocket.onmessage = function(evt) { onMessage(evt) };
    websocket.onerror = function(evt) { onError(evt) };
  }

  function onOpen(evt)
  {
    writeToScreen("CONNECTED");
    //doSend("WebSocket rocks");
  }

  function onClose(evt)
  {
    writeToScreen("DISCONNECTED");
  }

  function onMessage(evt)
  {
    writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');
  }

  function onError(evt)
  {
    writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
  }

  function doSend(message)
  {
    writeToScreen("SENT: " + message); 
    websocket.send(message);
  }

  function writeToScreen(message)
  {
    var pre = document.createElement("p");
    pre.style.wordWrap = "break-word";
    pre.innerHTML = message;
    output.appendChild(pre);
  }

  window.addEventListener("load", init, false);

</script>

but it prints ERROR: undefined and disconnects. 但它会显示错误:未定义并断开连接。

Thank you! 谢谢!

this url works for me: 这个网址对我有用:

'wss://websocket.mtgox.com:443/mtgox?Currency=GBP'

you can change the currency to desired, I think you can also use a comma separated list as values 您可以将货币更改为所需的货币,我想您也可以使用逗号分隔的列表作为值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM