Thursday, June 13, 2013

Google App Script to get Stock Price in your inbox Every hour

Google App Script is a nice platform to automate the task that you do using different Google products and services such as Gmail, Drive, Calendar, Spreadsheets etc

In our last post we learn how we can start writing Google App Script. We develop a script which will read the email message count from our Gmail inbox. In this post let us create a script which will pull the stock price of shares from Google finance and send it to us through email.

To start with we need to go to http://script.google.com, and create a blank project. We can write the below script code which pulls the share prices of some of the stocks such as Reliance Industries, Maruti Suzuki and Coal India. All we have to do is to pass the Stock symbol of the share to FinanceApp.getStockInfo() function. You can get the stock symbol of any share on Google finance or on moneycontrol.com or on any website which provide the stock price and its details. The share prices are then email to the user email address.

function myFunction() {
  
  var info = FinanceApp.getStockInfo("500325")
  var strMsg='Share Price of ' + info.name + ' is : ' + info.price + ' || '
  
  info = FinanceApp.getStockInfo("MARUTI")
  strMsg=strMsg + 'Share Price of ' + info.name + ' is : ' + info.price + ' || '
  
  info = FinanceApp.getStockInfo("COALINDIA")
  strMsg=strMsg + 'Share Price of ' + info.name + ' is : ' + info.price + ' || '  
  
  
  var sentEmailTo="singhvikash.blogspot.com@gmail.com"
  GmailApp.sendEmail(sentEmailTo, "Portfolio Status" , strMsg) 
  
 
}

Now let us create a trigger which is kind of a scheduler where you setup how and in what frequency this script will be executed. For this we need to go to Resources->Current project’s triggers

This will show the triggers that are setup on this current project/script. If there are no triggers setup, we need to click on add one now.

It will show the current project triggers page. We need to select our function name. To setup this script to run every one hour, we need to select Hour timer and Every Hour. To save the settings we nee to click on Save.

That is all we have to do. Now, every hour you will get the stock prices in your email.

This is very useful where you do not have access to internet or do not have access to see the stock prices. You can use any valid email address to send the stock prices. The script will send the stock prices every hour.

This is very useful where you do not have access to internet or do not have access to see the stock prices. You can use any valid email address to send the stock prices. The script will send the stock prices every hour.

Popular Posts

Real Time Web Analytics