我目前遇到了使用coinbase-pro-node
npm 包(https://github.com/coinbase/coinbase-pro-node)遇到的问题。我正在连接到该matches
频道并在那里收听消息,但与 Websocket 的连接在几个小时后中断,而没有告诉我太多。我无法追溯问题,并且它不会在相同的时间间隔内发生。有时它会在我运行脚本几分钟后中断。谢谢您的帮助。
编码:
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: read ECONNRESET
File "internal/stream_base_commons.js", line 167, in TLSWrap.onStreamRead