-3
Although it was working previously (like a day ago), I now am not receiving any messages through the MtGox streaming API (socket.io). Code is below, am I doing anything obviously wrong? The connection message is printing out so I assume it's connected OK.
var conn = io.connect('https://socketio.mtgox.com/mtgox');
conn.on('connect', function(data) {
console.log("Connected to Mt.Gox");
conn.send({
"op": "mtgox.subscribe",
"type": "depth"
});
conn.send({
"op": "mtgox.subscribe",
"type": "trade"
});
});
conn.on('message', function(data) {
if ('private' === data.op) {
if ('trade' === data.private && 'USD' === data.trade.price_currency) {
console.log("Last trade price: " + data.trade.price);
}
if ('depth' === data.private) {
if ('ask' === data.depth.type_str) {
console.log("Ask depth added: " + data.depth.price);
} else {
console.log("Bid depth added: " + data.depth.price);
}
}
}
});
Link to jsfiddle: http://jsfiddle.net/lkavenagh/jYKjU/17/
console.log wasn't working for some reason so used alert instead. I get the connection alert but no alerts for messages.
Just discovered that if I leave it running for something like 30-45 minutes, it starts receiving messages. Will try to find out why there is such a delay... – lkavenagh – 2013-11-02T16:13:31.510