Skip to content

Instantly share code, notes, and snippets.

@razaanstha
Created September 4, 2023 02:58
Show Gist options
  • Save razaanstha/adbe66a385819ac25349a46cc01eb8bf to your computer and use it in GitHub Desktop.
Save razaanstha/adbe66a385819ac25349a46cc01eb8bf to your computer and use it in GitHub Desktop.
NEPSE: Get Real Time Stock Price on Google Sheets
/**
* 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';
}
/**
* 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