Bitcoin Forum
June 25, 2024, 10:37:49 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: MtGox socket.io troubles  (Read 1317 times)
cyril1976 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 31, 2012, 12:23:55 AM
 #1

I am trying to collect market updates from MtGox via their websocket interface. My script follows the example in https://github.com/dlanod/node-mtgox-websocket-client with some simplifications, but it fails after working for a few hours.

The error message is usually 'Error: Stream closed unexpectedly.' coming from socket.io, but sometimes the script simply stops receiving the data without giving any error. The latter is much worse than the former, because without an error diagnostics I cannot even reconnect to the websocket.

Has anyone experienced anything similar? If you did, how did you deal with that? Any information will be highly appreciated.

Cheers,

Cyril
___

Just in case, here is the code:

Code:
var io = require('socket.io-client');
var MTGOX_SOCKET_URL = 'https://socketio.mtgox.com/mtgox';
var socket = io.connect(MTGOX_SOCKET_URL);


process.on('exit', function() {
  console.log('Exiting process.');
});

socket.on('message', function(message) {
  if(message.op == 'private' && message.private == 'depth')
      renderDepthMessage(message);
 
  if(message.op == 'private' && message.private == 'trade')
      renderTradeMessage(message);
 
});

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

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

var renderTradeMessage = function(message, lastPrice) {
  console.log(getTradeFormat(message.trade, lastPrice));
};

var renderDepthMessage = function(message) {
  console.log(getDepthFormat(message.depth));
};

var getDepthFormat = function(depth) {
  return depth.now + ' ' + depth.type + ' ' + depth.total_volume_int + ' ' + depth.price_int;
};

var getTradeFormat = function(trade) {
  return trade.tid + ' ' + trade.trade_type + ' ' + trade.amount_int + ' ' + trade.price_int;
}

RyNinDaCleM
Legendary
*
Offline Offline

Activity: 2408
Merit: 1009


Legen -wait for it- dary


View Profile
December 31, 2012, 01:42:55 AM
 #2

I'm not real familiar with socket.io, but I do know that Gox' socket.io is atrocious (have you ever watched GoxLive?) many services try not to use their web socket. So it may not be your code.  Have you come across slush' Sierrachart bridge? If this is the effect you're after, it's already built.

Edit: By the looks of your code, it seems you're building something like BTCcharts.com (Depth and real-time price movements)?

slavko
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
December 31, 2012, 01:50:28 AM
 #3

everybody knows, that gox socket is not work ever ... you do better http polling Tongue
cyril1976 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 31, 2012, 02:47:42 PM
 #4

Have you come across slush' Sierrachart bridge? If this is the effect you're after, it's already built.

Edit: By the looks of your code, it seems you're building something like BTCcharts.com (Depth and real-time price movements)?

Thanks for the pointers, I'll check both Sierrachart and BTCcharts and see if I can use them. Indeed, I want to have real-time prices (up to a certain depth, say BTC 200) to implement market making in bitcoins.
cyril1976 (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
December 31, 2012, 02:50:55 PM
 #5

everybody knows, that gox socket is not work ever ... you do better http polling Tongue

Well, I was a member of the empty set of those who do not know that :-) Thanks for letting me know.
RyNinDaCleM
Legendary
*
Offline Offline

Activity: 2408
Merit: 1009


Legen -wait for it- dary


View Profile
December 31, 2012, 10:21:46 PM
Last edit: January 01, 2013, 02:56:57 AM by RyNinDaCleM
 #6

Have you come across slush' Sierrachart bridge? If this is the effect you're after, it's already built.

Edit: By the looks of your code, it seems you're building something like BTCcharts.com (Depth and real-time price movements)?

Thanks for the pointers, I'll check both Sierrachart and BTCcharts and see if I can use them. Indeed, I want to have real-time prices (up to a certain depth, say BTC 200) to implement market making in bitcoins.


Check here first: http://mtgoxlive.com/orders?dark;volumeon
BTCcharts is very similar in appearance, but has much more in the way of features. But there is a very low fee so just visiting the site yields nothing.

Here is slush' feed: https://bitcointalk.org/index.php?topic=6019.0

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!