bitfinexcom / bitfinex-api-node

BITFINEX NodeJS trading API - Bitcoin, Litecoin, and Ether exchange
https://www.bitfinex.com/
MIT License
462 stars 213 forks source link

Subscribing to Raw Books returns data for Books instead #145

Closed majid4466 closed 6 years ago

majid4466 commented 6 years ago

In the playground it is possible to subscribe to Raw Books feed, but trying the same in node returns data for Books. I.e. instead of something like [ 164, [ 5205599654, 7833.5, -0.00409589 ] ] it returns data like [ 90, [ 7868.5, 4, 18.073 ] ].

Here is my test case:

var WebSocket = require('ws');
var ws = new WebSocket('wss://api.bitfinex.com/ws/2');
ws.on('error', function(error){
  console.log('Bitfinex API connection encountered this error:', error);
});
ws.on('close', function(){
  console.log('Bitfinex API connection closed');
});
ws.on('open', function() {
  console.log('Bitfinex API connection opened');
  // Subscribe to Raw Books
  ws.send(JSON.stringify({
    "event":"subscribe",
    "channel":"book",
    "pair":"tBTCUSD",
    "perc":"R0"
  }));
});
ws.on('message', function(message) {
  try {
    msg = JSON.parse(message);      
    console.log(msg); // the message we get does not look like raw books. it is similar to books messages
  } catch (e) {
    console.error('[bfx ws2 error] received invalid json');
    console.error('[bfx ws2 error]', message);
    console.trace();
    return;
  }
});
majid4466 commented 6 years ago

My bad, sorry. I had a typo in my subscribe request (perc instead of prec). Correcting that, I get the expected feed.