Problem is link being not accessible to nodejs get client.
Could be some headers issue or something.
Problem is with 'https://www.nseindia.com/api/reportASM?csv=true' link. This link works on nseindia website https://www.nseindia.com/reports/asm
I have written the code below
import pkg1 from 'needle'; const { get } = pkg1;
import Papa from 'papaparse';
function fetchASMDataValues() {
return new Promise((resolve, reject) => {
let values = [];
get(`https://www.nseindia.com/api/reportASM?csv=true`)
.pipe( Papa.parse(Papa.NODE_STREAM_INPUT, { header: false }) )
.on("data", (dt) => {
console.log(`processing ${ dt }`);
if( dt[1].trim() != "" ) {
let asmval = dt[4].trim().split(" ");
asmval = asmval[0].startsWith("LT") ? "LT - " : "ST - " + asmval[2];
values.push([ dt[1].trim(), asmval ]);
}
}).on("end", () => {
console.log(`${ values.length } symbols ASM Data Values accumulated`);
resolve(values);
}).on("error", (err) => {
console.log(`error in parsing ASM Data nse sheet.\n${ err }`);
reject(err);
});
});
}
This function never resolves. It also doesn't log anything as the file doesn't load. Code works with other csv files. Please help with this issue.