Skip to content

Instantly share code, notes, and snippets.

@wnds
Last active March 12, 2021 09:49
Show Gist options
  • Save wnds/61a090d8c58ae38db06522427d42b94b to your computer and use it in GitHub Desktop.
Save wnds/61a090d8c58ae38db06522427d42b94b to your computer and use it in GitHub Desktop.
/**
* Gets LTP from ICICI Direct.
*
* @param {string} symbol Symbol for this Last Traded Price is required
* @return {string} ltp Current LTP from ICICI Direct
* @customfunction
*/
function ILTP(symbol) {
var url = 'https://secure.icicidirect.com/IDirectTrading/Trading/trading_stock_quote.aspx?Symbol=' + symbol
console.log('URL :' + url);
var response = UrlFetchApp.fetch(url);
console.log(response.getAllHeaders());
var html = response.getContentText();
var ltpRegex = new RegExp(/(LAST TRADE PRICE)([\stdh<>\/]+)([\salign="]+[right|left|center]+[">\s]+)(NA|[0-9,]+.[0-9]+)[\stdh<>\/]+/gm)
var ltp = ltpRegex.exec(html);
console.log(ltp)
return ltp[4];
}
function _debug_iltp() {
console.log(ILTP('ICINEX'))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment