Created
September 4, 2023 02:58
-
-
Save razaanstha/adbe66a385819ac25349a46cc01eb8bf to your computer and use it in GitHub Desktop.
NEPSE: Get Real Time Stock Price on Google Sheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the company name of a NEPSE stock. | |
* | |
* @param {string} stockSymbol - The stock symbol to retrieve the company name for. | |
* @return {string} The company name of the specified stock. | |
* @customfunction | |
*/ | |
function getCompanyName(stockSymbol) { | |
if (!stockSymbol) return '#SYMBOL_MISSING'; | |
const response = UrlFetchApp.fetch("https://nepse-test.vercel.app/api?symbol=" + stockSymbol); | |
const responseData = JSON.parse(response.getContentText()); | |
return responseData.company_name ?? '#ERR'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the last traded price (LTP) of a NEPSE stock. | |
* | |
* @param {string} stockSymbol - The stock symbol to retrieve the LTP for. | |
* @return {number} The LTP of the specified stock. | |
* @customfunction | |
*/ | |
function getLTP(stockSymbol) { | |
if (!stockSymbol) return '#SYMBOL_MISSING'; | |
const response = UrlFetchApp.fetch("https://nepse-test.vercel.app/api?symbol=" + stockSymbol); | |
const responseData = JSON.parse(response.getContentText()); | |
return parseFloat(responseData.ltp) ?? '#ERR'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment