bitfinexcom / bitfinex-api-node

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

Subscribe ticker for a lot of symbols crashes #435

Open MauriPastorini opened 5 years ago

MauriPastorini commented 5 years ago

Hi, using websockets when I try to subscribe to a lot of symbols, the library crashes instantaneously. What can I do please?

Here is my code:

const timeBetweenRequest = 10 * 1000;

const BFX = require("bitfinex-api-node");
const options = {
  ws: {
    autoReconnect: true,
    seqAudit: true,
    packetWDDelay: timeBetweenRequest
  }
};
const bfx = new BFX(options);

const start = symbols => {
  const ws = bfx.ws(2, { transform: false });

  ws.on("open", () => {
    console.log("open");
    for (let x = 0; x < symbols.length; x++) {
      var element = symbols[x];
      ws.subscribeTicker(element);
    }
  });

  ws.onTicker({}, (ticker, info) => {
    console.log("Info: ", info);
    console.log("Ticker: ", ticker);
  });

  ws.open();
};

start(["Pair1", "Pair2", "Pair3", "...."])

Error:

events.js:188
      throw err;
      ^

Error: Unhandled "error" event. ([object Object])
    at WSv2.emit (events.js:186:19)
    at WSv2._handleErrorEvent (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\lib\transports\ws2.js:1045:10)
    at WSv2._handleEventMessage (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\lib\transports\ws2.js:994:19)
    at WSv2._onWSMessage (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\lib\transports\ws2.js:550:12)
    at emitOne (events.js:116:13)
    at WebSocket.emit (events.js:211:7)
    at Receiver._receiver.onmessage (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\node_modules\ws\lib\WebSocket.js:141:47)
    at Receiver.dataMessage (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\node_modules\ws\lib\Receiver.js:389:14)
    at Receiver.getData (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\node_modules\ws\lib\Receiver.js:330:12)
    at Receiver.startLoop (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\node_modules\ws\lib\Receiver.js:165:16)
    at Receiver.add (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\node_modules\ws\lib\Receiver.js:139:10)
    at TLSSocket._ultron.on (G:\Mis Documentos\Proyectos Freelance\Arbitrage\ArbitrageRepo\node_modules\bitfinex-api-node\node_modules\ws\lib\WebSocket.js:138:22)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at TLSSocket.Readable.push (_stream_readable.js:208:10)
    at TLSWrap.onread (net.js:594:20)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! arbitragerepo@1.0.0 start_bitfinex_job: `node jobs/bitfinex`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the arbitragerepo@1.0.0 start_bitfinex_job script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Mauri-Laptop\AppData\Roaming\npm-cache\_logs\2018-11-17T22_14_56_566Z-debug.log

Regards

f3rno commented 5 years ago

@MauriPastorini can you add an error listener to see what the error actually is? Code:

ws.on('error', (err) => console.log(`error: ${err.message}`))
fieldfoxWim commented 5 years ago

What version are you using? Because 18 days ago the models were changed breaking this module. Can you test if it works with v2.0.0?

references:

Cheers