-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: 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. – lkavenagh Oct 31 '13 at 17:37
  • 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 Nov 2 '13 at 16:13
0

Not 100% sure, my project is still working. Only difference I might see is the way you subscribe to the channel, I use a channel ID instead of a type. Not sure if that might have something to do with it. I'm a sort of novice programmer, just gettin back into it after years of sitting idle. Let me know if that helps

  • I've tried that too. Hmm, I had thought it might be on Mt.Gox's side, but it doesn't look that way. – lkavenagh Oct 31 '13 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.