Bitcoin Forum
November 07, 2024, 03:48:59 PM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: How to connect to MtGox streaming API through websocket?  (Read 678 times)
alikim (OP)
Member
**
Offline Offline

Activity: 80
Merit: 11


View Profile
September 16, 2013, 01:27:45 PM
Last edit: September 16, 2013, 05:09:37 PM by alikim
 #1

I'm trying to connect to it in my C++ app.

If I send a handshake to

http://socketio.mtgox.com:80/mtgox, it doesn't answer
http://websocket.mtgox.com:80/mtgox, it sends 400 Bad request

I Googled this one:

http://socketio.mtgox.com:80/socket.io/1/websocket, this one connects, switches to websocket protocol, then sends me two messages saying "1::" and "2::".

What do I do on my side?

I tried to send {"channel":"24e67e0d-1cad-4cc0-9e7a-f8523ef460fe","op":"subscribe"} - nothing happens...


What's the right URL to connect and what do I send to subscribe to a channel?


Alternatively, can anyone please post a simple .js code that successfully connects to MtGox from a HTML page?

Without node.js or socket.io, just a built in HTML5 Websocket class.

I have this script:

Code:
<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 only prints ERROR: undefined and disconnects.


Thank you!
alikim (OP)
Member
**
Offline Offline

Activity: 80
Merit: 11


View Profile
September 17, 2013, 05:07:31 PM
 #2

I don't believe nobody here knows how to connect to MtGox via websockets.

Please tell me how you do it...
Pages: [1]
  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!