Subscribe for market depth updates using Mt.Gox streaming API

2

I want to subscribe to market depth updates using the streaming API https://en.bitcoin.it/wiki/MtGox/API/Streaming. I want to receive only depth updates for a particular symbol (EUR for example) or for all symbols. So I connect to wss://websocket.mtgox.com and send the command

{
     "type": "depth",
     "op": "mtgox.subscribe" 
}

I'm expecting to receive depth updates for all symbols. But it sends me updates only for BTCUSD. Though the same subscribe command with parameter "type" = "trades" sends trades for all symbols (not only BTCUSD). That's a little confusing.

The currency parameter is mentioned in API documentation: websocket.mtgox.com:80/mtgox?Currency=EUR, but after connecting to this websocket I receive ticker updates as well. But I don't need ticker updates.

The question is how can I receive only market depth updates for particular symbol? (or all of symbols)

sergeyz

Posted 2013-07-17T10:16:34.653

Reputation: 121

Answers

1

Heres how I do it in node.js

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

var MTGOX = function(){
    var self = this;
    var socket = io.connect('https://socketio.mtgox.com/mtgox');   

    socket.on('message', function(data){

        var message = data;

        if( message.private == "depth"){
            self.emit('depth', data.depth);    
        } else if( message.private == "ticker" ){
            self.emit('ticker', data.ticker);
        } else if( message.private == "trade" ){
            self.emit('trade', data.trade);
        }

    });
};

MTGOX.prototype.__proto__ = events.EventEmitter.prototype;

and then I just listen to the depth event. Also I found this project helpful when I was first figuring this out.

Loourr

Posted 2013-07-17T10:16:34.653

Reputation: 3 022

0

In Java, you can use the XChange library which provides this and other data through a unified API for a range of exchanges.

Gary Rowe

Posted 2013-07-17T10:16:34.653

Reputation: 7 175