From 41e052670c7c5dbd106ce2da52671a6258a386f4 Mon Sep 17 00:00:00 2001 From: Chandan Kumar Date: Tue, 7 Dec 2021 23:16:16 +0530 Subject: [PATCH] #29 Add api to get quotes for multiple companies at once --- README.md | 4 ++++ app.js | 7 +++++++ nse/index.js | 14 ++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 7d336fe..34f1f64 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,10 @@ http://localhost:3000/nse/get_quotes
Format: JSON
http://localhost:3000/nse/get_quote_info?companyName=TCS
+- Get the quotation data of the symbols (companyNames) from NSE - JSON
+Format: JSON
+http://localhost:3000/nse/get_multiple_quote_info?companyNames=TCS,WIPRO,AND_MORE
+ - Get the top 10 gainers of NSE
Format: JSON
http://localhost:3000/nse/get_gainers
diff --git a/app.js b/app.js index f344849..a87cb17 100644 --- a/app.js +++ b/app.js @@ -50,6 +50,13 @@ app.get("/nse/get_quote_info", (req, res, next) => { }); }); +// Get the quotation data of the symbols (companyNames) from NSE - JSON +// Example: http://localhost:3000/nse/get_multiple_quote_info?companyNames=TCS,WIPRO +app.get("/nse/get_multiple_quote_info", (req, res, next) => { + const companyNames = req.query.companyNames.split(","); + NSEAPI.getMultipleQuoteInfo(companyNames).then(r => res.json(r)); +}); + // Get the top 10 gainers of NSE - JSON // Example: http://localhost:3000/nse/get_gainers app.get("/nse/get_gainers", (req, res, next) => { diff --git a/nse/index.js b/nse/index.js index 11bcb45..c891e43 100644 --- a/nse/index.js +++ b/nse/index.js @@ -53,6 +53,19 @@ function getQuoteInfo(symbol) { return NSEAPI.getQuoteInfo(symbol); } +/** + * Get info for multiple company at once + * @param symbols {[string]} symbols of companies + * + * @returns {object} + */ +function getMultipleQuoteInfo(symbols) { + return Promise.all(symbols.map(async (symbol) => { + const res = await NSEAPI.getQuoteInfo(symbol) + return res.data; + })) +} + /** * Get List of Gainers @@ -161,6 +174,7 @@ var nse = { getSectorsList: getSectorsList, getQuotes: getQuotes, getQuoteInfo: getQuoteInfo, + getMultipleQuoteInfo: getMultipleQuoteInfo, getGainers: getGainers, getLosers: getLosers, getInclineDecline: getInclineDecline,