我目前遇到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
答案 0 :(得分:1)
它确实会不定期地中断,没有明显的原因。您所能做的就是监听心跳消息,并使用这些消息来决定是否重新启动新的Websocket提要。我直接通过coinbase pro / gdax客户支持提出了类似的查询。