Doesn't work for GDAX (node)
See original GitHub issueThe module doesn’t manage to stay connected to the [GDAX] crypto data feed:
const WebSocket = require('ws');
const ReconnectingWebSocket = require('reconnecting-websocket');
const rws = new ReconnectingWebSocket('wss://ws-feed.gdax.com', [], {
constructor: WebSocket,
debug: true,
});
let lastPointTimestamp = new Date();
setInterval(() => {
if (Date.now() - lastPointTimestamp > 60 * 1000)
// No data in the past minute since we got called
console.warn('Got disconnected and did not reconnect');
}, 60 * 1000);
function handleData(data) {
lastPointTimestamp = Date.now();
console.log(data.price);
}
rws.on('open', () => {
rws.send(JSON.stringify({
type: 'subscribe',
product_ids: ['BTC-USD'],
channels: ['matches'],
}));
});
rws.on('message', data => handleData(JSON.parse(data)));
rws.on('error', err => {
console.error('ON ERROR -', err);
});
The log shows this:
ON ERROR - { Error: read ECONNRESET
at _errnoException (util.js:1003:13)
at TLSWrap.onread (net.js:620:25) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }
RWS: handleClose { shouldRetry: true }
RWS: retries count: 1
RWS: handleClose - reconnectDelay: 2043.1049894719274
RWS: connect
RWS: bypass properties
RWS: timeout
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
node.js - GDAX websocket freezing - Stack Overflow
js GDAX library. I have an implementation that works fairly well however the websocket is randomly freezing with no close event emitted.i have...
Read more >gdax - npm
Client for the GDAX API. Latest version: 0.9.0, last published: 4 years ago. Start using gdax in your project by running `npm i...
Read more >Gdax NPM | npm.io
The official Node.js library for Coinbase's Pro API. Features. Easy functionality to use in programmatic trading; A customizable, websocket-synced Order Book ...
Read more >DAX cluster components - Amazon DynamoDB
DAX spreads the load evenly across all the nodes in the cluster. (Another way to increase throughput is to use larger cache node...
Read more >FAQ on API - Coinbase Help
The primary data sources and servers for Coinbase are run in the Amazon US East ... We have three official client libraries: Node.js,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Happy to hear that!
ReconnectingWebsocket
uses the standard WebSocket APIyou can use
.addEventListener
or assign a function toonopen
:rws.onopen = () => console.log('open');
I have exactly the same issue with Twitch PubSub.
Edit: Looks like i’ve found the Culprit. In the connect function, a handler for ‘close’ is created which calls the
handleClose
function, which then tries to reconnect by callingconnect
after a delay. The issue is that theconnect
function has a timeout delay which does not try to reconnect upon timeout, thus it stalls. Lemme whip up a fix.