I am accessing an API that streams (RFC2616 for HTTP/1.1) the response. The stream never ends, but from time to time it throughs an error requiring the program to restart the request. I can't figure out how in NodeJS to restart the request without restarting the program. I've tried loops to check if an error occurred, but I end up creating a blocking code that stops the request methods. The code below works until an error occurs.
const request = require('request');
const options = {
method: 'GET',
url: 'https://api.tradestation.com/v3/marketdata/stream/quotes/IWM',
headers: {Authorization: 'Bearer ' + api.token,},
};
request(options)
.on('data', function (data) {
console.log(data.toString());
//Process data here
})
.on('error', function (err) {
console.error(err);
});
If it helps, the documentation to the API for streaming is here, and the API call is here.
On a side note, I tried using Axios but it doesn't seem to like endless streams (tried onDownloadProgress).