Skip to content

Commit

Permalink
Merge pull request #38 from cksharma11/issue-29
Browse files Browse the repository at this point in the history
#29 Add api to get quotes for multiple companies at once
  • Loading branch information
maanavshah authored Dec 14, 2021
2 parents 5bfc8e1 + 41e0526 commit 048b6c1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ http://localhost:3000/nse/get_quotes<br/>
Format: JSON<br/>
http://localhost:3000/nse/get_quote_info?companyName=TCS<br/>

- Get the quotation data of the symbols (companyNames) from NSE - JSON<br/>
Format: JSON<br/>
http://localhost:3000/nse/get_multiple_quote_info?companyNames=TCS,WIPRO,AND_MORE<br/>

- Get the top 10 gainers of NSE<br/>
Format: JSON<br/>
http://localhost:3000/nse/get_gainers<br/>
Expand Down
7 changes: 7 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
14 changes: 14 additions & 0 deletions nse/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -161,6 +174,7 @@ var nse = {
getSectorsList: getSectorsList,
getQuotes: getQuotes,
getQuoteInfo: getQuoteInfo,
getMultipleQuoteInfo: getMultipleQuoteInfo,
getGainers: getGainers,
getLosers: getLosers,
getInclineDecline: getInclineDecline,
Expand Down

0 comments on commit 048b6c1

Please sign in to comment.