Skip to content

Instantly share code, notes, and snippets.

@anon767
Created January 13, 2019 11:06
Show Gist options
  • Save anon767/c148699a9187a645976cf0d06745c921 to your computer and use it in GitHub Desktop.
Save anon767/c148699a9187a645976cf0d06745c921 to your computer and use it in GitHub Desktop.
retrieve simple and easy stock exchange information for nodejs
const url = "https://query1.finance.yahoo.com/v8/finance/chart/";
const parameter = "?region=US&lang=en-US&includePrePost=false&interval=1m&range=max&corsDomain=finance.yahoo.com&.tsrc=finance"
async function downloadPage(url) {
return new Promise((resolve, reject) => {
request(url, (error, response, body) => {
if (error) reject(error);
if (response.statusCode != 200) {
reject('Invalid status code <' + response.statusCode + '>');
}
resolve(body);
});
});
}
async function getStockInfo(stocksymbol) {
try {
let scrapeurl = url + stocksymbol + parameter;
let body = await downloadPage(scrapeurl);
let jsonbody = JSON.parse(body);
return jsonbody.chart.result[0].indicators.quote[0].high[jsonbody.chart.result[0].indicators.quote[0].high.length - 1];
}
catch (e) {
send("debug: error occured: " + e.toString() + " by fetching " + firma);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment