Last active
March 12, 2021 09:49
-
-
Save wnds/61a090d8c58ae38db06522427d42b94b to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* 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