Automate NSE Stock Prices in Google Sheets with Ease!
Vikranth U
Posted on June 14, 2024
"The stock market is filled with individuals who know the price of everything, but the value of nothing." — Philip Fisher
Have you ever wished for a seamless way to track real-time stock prices and financial data for NSE stocks directly in Google Sheets? Well, we did too! This led us on a journey to create a powerful Google Sheets script that fetches real-time stock prices, market cap, P/E ratio, and much more, using the GOOGLEFINANCE function. Here’s our story and how you can use it to make your financial tracking a breeze.
The Idea
It all started with a simple desire: to keep an eye on our favorite NSE stocks without jumping between multiple websites. We wanted everything in one place, preferably in Google Sheets, where we could easily manipulate and analyze the data. The idea was straightforward: automate the fetching of real-time stock data into Google Sheets, and that's exactly what we set out to achieve.
The Journey
Our journey began with exploring the capabilities of the GOOGLEFINANCE
function in Google Sheets. We discovered that while GOOGLEFINANCE
supports various attributes like price, volume, and P/E ratio, it required us to manually enter each stock symbol and formula. This was tedious and time-consuming. We needed a way to automate this process.
The Solution
We decided to create a Google Apps Script that would:
- Fetch real-time stock prices and financial data for NSE stocks.
-
Automatically append
NSE:
to stock symbols to ensure accurate results. - Clear previous data to keep the sheet tidy.
- Populate a predefined list of stock symbols for easy setup.
How to Use Our Script
We’ve made it incredibly easy for you to get started with our script. Follow these simple steps:
- Open your Google Sheets document.
- Go to
Extensions
>Apps Script
. -
Copy and paste the code from our
Code.js
file into the Apps Script editor. -
Save the script by clicking the disk icon or pressing
Ctrl + S
. - Close the Apps Script editor and refresh your Google Sheets document.
-
Enter stock symbols (without
NSE:
) starting from cell A3. -
Click on
Stock Prices
>Update Prices
to fetch and display stock data.
Features
Our script fetches a wealth of data, including:
- Real-time price
- Percentage change
- Volume
- High and low prices
- Open price
- Market capitalization
- Average daily trading volume
- P/E ratio
- Earnings per share
- 52-week high and low
- Previous day's closing price
- Number of outstanding shares
- Trade time
- Data delay
Visual Guide
Here’s a snapshot of what your Google Sheets setup will look like:
Description:
- The left side shows the stock symbols entered in column A.
- The top menu shows the
Stock Prices
menu with theUpdate Prices
option.
Pre-configured Sheet
To make things even simpler, we’ve prepared a pre-configured Google Sheet with the script already set up. You can view and make a copy of it here. The App Script is included, so you don't need to worry about setting up the code.
Video Tutorial
For those who prefer a visual guide, we’ve got you covered! Check out our detailed video tutorial on how to use the script here.
Going Beyond
We didn’t stop at fetching data. We also created an additional script, Populate.js
, to automatically populate a list of stock symbols. This script can be incredibly handy if you want to start with a predefined list of stocks.
Steps to Use Populate.js
- Open your Google Sheets document.
- Go to
Extensions
>Apps Script
. -
Copy and paste the code from our
Populate.js
file into the Apps Script editor. -
Save the script by clicking the disk icon or pressing
Ctrl + S
. - Close the Apps Script editor and refresh your Google Sheets document.
-
Run the
populateStocks
function to automatically populate your list of NSE stocks starting from cell A3.
The Joy of Automation
This project was a joy to work on. The idea of automating something as tedious as manually entering stock data brought a smile to our faces. We hope it brings the same joy and convenience to you.
Check out the Github repo here - Vikranth3140/NSE-Stock-Prices-Automation
Feel free to explore, tweak, and expand on our scripts. Automation can make financial tracking not just easier but also a lot more fun!
Conclusion
We hope our journey and this script inspire you to automate and simplify your own tasks. Happy tracking, and may your investments flourish!
Thank you for joining us on this journey. If you have any questions or feedback, we’d love to hear from you. Happy automating and investing!
Posted on June 14, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.