2

I'm currently stuck with an issue I'm getting with the coinbase-pro-node npm package (https://github.com/coinbase/coinbase-pro-node). I'm connecting to the matches channel and listening for messages there but the connection with the Websocket breaks after a few hours without telling me much. I can't trace back the problem and it doesn't happen on the same intervals. Sometimes it breaks just minutes after I run the script. Thanks for the help.

The code:

const CoinbasePro = require('coinbase-pro');
var coinbaseWs = '';

function connect() {
    coinbaseWs = new CoinbasePro.WebsocketClient(
        ['BTC-USD'],
        'wss://ws-feed.pro.coinbase.com',
        {
            key: 'xxxx',
            secret: 'xxxx',
            passphrase: 'xxxx',
        },
        { channels: ['matches'] }
    );  

    coinbaseWs.on('message', async data => { 
        console.log(data)  
    });

    coinbaseWs.on('error', err => {
      console.error("Connection with Coinbase websocket failed with error: " + err);
      console.log("Error stack trace: " + err.stack);
    });

    coinbaseWs.on('close', () => {
      console.error("Connection with Coinbase websocket closed!");
    });
}

connect();

Error stack:

Error: read ECONNRESET
File "internal/stream_base_commons.js", line 167, in TLSWrap.onStreamRead
Marko Grbic
  • 91
  • 1
  • 1
  • 7

1 Answers1

1

it does break from time to time for no apparent reason. All you can do is listen for the heartbeat messages and use those to decide whether to re-initiate a new websocket feed. I raised a similar query directly with the coinbase pro/gdax customer support.

Rob Evans
  • 2,822
  • 1
  • 9
  • 15