<p>try using socket.io-client </p>

<pre><code>var io = require('socket.io-client');
</code></pre>

<p>then its as simple as </p>

<pre><code>var socket = io.connect( 'https://socketio.mtgox.com/mtgox' );
</code></pre>

<p>and then to subscribe to a specific channel </p>

<pre><code>var message = {
  "op": "subscribe",
  "channel": "24e67e0d-1cad-4cc0-9e7a-f8523ef460fe" // this is the market depth channel
};

socket.send(JSON.stringify(message));

socket.on('message', function(message) { console.log(message); });
</code></pre>

<p>should give you the results your looking for</p>

<p>I think your main problem is that your not using the channel id's in your connection message. Here is the <a href="https://en.bitcoin.it/wiki/MtGox/API/Streaming#Incoming_Data" rel="nofollow">Mtgox web sockets api</a> which has a list of all the different channel id's. And heres a <a href="https://github.com/arthurpham/node-mtgox-socketio-client" rel="nofollow">project</a> which implements them generically. </p>

<p>Hope this helps </p>

CC BY-SA 3.0
2013-04-21T17:12:35.757Z
2013-04-21T17:12:35.757Z
Loourr
<p>Here's a bit of node.js code:</p>



<pre><code>var WebSocket = require('ws');
var ws = new WebSocket('ws://websocket.mtgox.com:80/mtgox?Currency=USD');
ws.on('open', function() {
    console.log('Connection opened');
    ws.send(JSON.stringify({ "op": "mtgox.subscribe", "type": "depth.BTCUSD" }));
});
ws.on('message', function(message) { console.log(message); });
</code></pre>

<p>When this client sends <code>{"op": "mtgox.subscribe", "type": "depth.BTCUSD" }</code> the API returns <code>{"message":"Unknown mtgox message type","op":"remark","success":false}</code>.</p>

<p>What am I doing wrong?</p>

<api><javascript>
Websocket API: Uknown mtgox message type
Steve
# Websocket API: Uknown mtgox message type

(Asked by: username_0 on 2013-04-21)

Here's a bit of node.js code:

```
var WebSocket = require('ws');
var ws = new WebSocket('ws://websocket.mtgox.com:80/mtgox?Currency=USD');
ws.on('open', function() {
    console.log('Connection opened');
    ws.send(JSON.stringify({ "op": "mtgox.subscribe", "type": "depth.BTCUSD" }));
});
ws.on('message', function(message) { console.log(message); });

```

When this client sends `{"op": "mtgox.subscribe", "type": "depth.BTCUSD" }` the API returns `{"message":"Unknown mtgox message type","op":"remark","success":false}`.

What am I doing wrong?

**Tags:** api, javascript


---

## 1 answers

### Answer by username_1 on 2013-04-21. Score: 1 | Accepted answer

try using socket.io-client

```
var io = require('socket.io-client');

```

then its as simple as

```
var socket = io.connect( 'https://socketio.mtgox.com/mtgox' );

```

and then to subscribe to a specific channel

```
var message = {
  "op": "subscribe",
  "channel": "24e67e0d-1cad-4cc0-9e7a-f8523ef460fe" // this is the market depth channel
};

socket.send(JSON.stringify(message));

socket.on('message', function(message) { console.log(message); });

```

should give you the results your looking for

I think your main problem is that your not using the channel id's in your connection message. Here is the [Mtgox web sockets api](https://en.bitcoin.it/wiki/MtGox/API/Streaming#Incoming_Data) which has a list of all the different channel id's. And heres a [project](https://github.com/arthurpham/node-mtgox-socketio-client) which implements them generically.

Hope this helps


---

