How to Use Google Finance API to Get Real-Time Stock Data

If you have years of experience in quantitative trading, you’re probably familiar with the Google Finance API. It was once a very popular tool in the financial trading industry. Compared to other stock data APIs, Google Finance API had several advantages. Not only did it provide real-time stock market API data, but it also allowed users to create and manage their own portfolios. Users could monitor the market performance of their investment portfolios and track the movement of each asset using Google Finance API.

During the infamous "Flash Crash" of 2010 in the U.S. stock market, many data services experienced interruptions due to the extreme market volatility. However, the Google Finance API continued to provide consistent and stable data, earning its reputation in the industry.

 

Unfortunately, on October 20, 2012, Google announced the discontinuation of this service. It was later integrated into Google Sheets, where users could only query stock and forex data through built-in formulas, rather than using code as before. If you're a lightweight user, the built-in method in Google Sheets might still meet some of your needs. Below are some basic tutorials on using the Google Finance API:

Retrieve historical market data

Formula: GOOGLEFINANCE(ticker, [attribute], [start_date], [end_date|num_days], [interval]) The GOOGLEFINANCE at the beginning is the command to call the formula, and the parameters are input within the parentheses:

•  ticker: The stock code. For more accurate results, it’s recommended to include the exchange name before the code, such as NASDAQ:GOOG for Google’s stock.

•  attribute: The default is price; this is optional.

•  start_date: The starting date.

•  end_date: The ending date.

•  interval: The time interval.

As a demonstration, let's query Google’s historical stock prices using the formula: =GOOGLEFINANCE("NASDAQ:GOOG", "price", DATE(2023,1,1), DATE(2023,12,31), "DAILY")

You can see that the sheet returns the closing prices for each trading day from January 1, 2023, to December 31, 2023.


Querying Stock P/E Ratio 

Formula: GOOGLEFINANCE(ticker, "pe") 

This formula is simpler, with only two parameters: ticker (the stock code mentioned above) and “pe” (which does not need to be changed). The following formula queries Amazon's P/E ratio: =GOOGLEFINANCE("NASDAQ:AMZN", "pe")


Querying Earnings Per Share (EPS) 

Formula: =GOOGLEFINANCE(ticker, "eps") This formula is also straightforward, similar to the P/E ratio formula. Here’s a demonstration of how to query Apple’s EPS: =GOOGLEFINANCE("NASDAQ:AAPL", "eps")

 

Limitations of Google Finance API

Google Finance API can only be accessed through formulas in Google Sheets, which may not be helpful for programs that require deep customization. Moreover, Google’s official documentation explicitly states that the data is not real-time; there is a 20-minute delay in market data. If you require more precise data, you might need to look for alternative solutions.

For real-time and stable data on Hong Kong stocks, U.S. stocks, and A-shares, you can consider procuring a third-party market data source that offers real-time trading quote APIs.

Request Method: Get (You can simply open it in your browser to view the returned data)

Data Format: Standard JSON format

Data Timeliness: Real-time updates

API Documentation: [Click to View]

Token Registration: [Click to View]


留言

此網誌的熱門文章

Check out these must-have financial data APIs you need to know about!

Financial Data Service Platforms: Real-Time Market Quotes | Hong Kong Stock Data Sources | U.S. Stock Data Sources

Share 4 Real-Time Financial Data APIs