google-sheetsstockstockquotes

How do I retrieve the information about the price of a stock during the after hours, or the pre-market?


How do I retrieve the information about the price of a stock during the after hours, or the pre-market? For example, I can use the formula =googlefinance("TSLA","price") which will retrieve the price of the stock during regular hours. However, it will not show the price during after hours and premarket hours. Thank you


Solution

  • I have derived the script and made it work using sole sheet formulas. The pre/after market values are fetched from this link:

    Pre market:

    =regexextract(importxml(A1&"TSLA", "/"), "Pre Market Last([^']+)'")
    

    After market:

    =regexextract(importxml(A1&"TSLA", "/"), "After Market Last([^']+)'")
    

    Output:

    output

    Note:

    =regexextract(importxml("https://app.quotemedia.com/quotetools/jsVarsQuotes.go?webmasterId=101264&symbol=TSLA", "/"), "Pre Market Last([^']+)'")
    

    and

    =regexextract(importxml("https://app.quotemedia.com/quotetools/jsVarsQuotes.go?webmasterId=101264&symbol=TSLA", "/"), "After Market Last([^']+)'")