Tracking investments with Google Spreadsheet

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,757
Reaction score
533
For those using google spreadsheet that who want almost real time quote. Here is the google apps script that will scrape quote from Yahoo ecn e.g. http://finance.yahoo.com/q/ecn;?s=YHOO.

Just go to Tool > Script Editor and cust & paste.
Code:
function getYahooRTprice(symbol) {
  var rtPriceStr=UrlFetchApp.fetch('http://finance.yahoo.com/q/ecn?s=' + symbol).getContentText();
  rtPriceStr=rtPriceStr.replace(/\n/g,"");
  var strlength=rtPriceStr.length;
  var loc = rtPriceStr.search("time_rtq_ticker");
  loc=rtPriceStr.indexOf(">",loc);
  var loc2=rtPriceStr.indexOf("<",loc);
  while (loc2-loc<=1 && loc2 < strlength) {
    loc=rtPriceStr.indexOf(">",loc2);
    loc2=rtPriceStr.indexOf("<",loc);
  }
  return rtPriceStr.substr(loc+1,loc2-loc-1)*1;
}
 

Some-one

Great Supremacy Member
Joined
Jan 1, 2000
Messages
52,831
Reaction score
3,805
For those using google spreadsheet that who want almost real time quote. Here is the google apps script that will scrape quote from Yahoo ecn e.g. http://finance.yahoo.com/q/ecn;?s=YHOO.

Just go to Tool > Script Editor and cust & paste.
Code:
function getYahooRTprice(symbol) {
  var rtPriceStr=UrlFetchApp.fetch('http://finance.yahoo.com/q/ecn?s=' + symbol).getContentText();
  rtPriceStr=rtPriceStr.replace(/\n/g,"");
  var strlength=rtPriceStr.length;
  var loc = rtPriceStr.search("time_rtq_ticker");
  loc=rtPriceStr.indexOf(">",loc);
  var loc2=rtPriceStr.indexOf("<",loc);
  while (loc2-loc<=1 && loc2 < strlength) {
    loc=rtPriceStr.indexOf(">",loc2);
    loc2=rtPriceStr.indexOf("<",loc);
  }
  return rtPriceStr.substr(loc+1,loc2-loc-1)*1;
}
Seems like it is not accurate for bonds

For example, the last closing price of BIOZ.SI is 1.008 but when I use the function, it returns me 1.010. Are there some rounding off in use?

ok. Just found out that the source is wrong and the function takes in the wrong value. Looks like the importdata is more accurate.

</span>SES </span><span class="wl_sign"></span></div></div><div class="yfi_rt_quote_summary_rt_top sigfig_promo_1"><div> <span class="time_rtq_ticker"><span id="yfs_l10_bioz.si">1.01</span></span> <span class="down_r time_rtq_content"><span id="yfs_c10_bioz.si">

http://finance.yahoo.com/q/ecn?s=BIOZ.SI
 
Last edited:

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,757
Reaction score
533
It depends on your needs. If you like frequent update during trading hours, then this is closer to real time. :o For EOD, then use importdata.
 

dkhchan

Member
Joined
Dec 28, 2003
Messages
180
Reaction score
0
another way of getting real time quotes. get it directly from google finance:

=ImportXML("https://www.google.com/finance?q=SGX:Z74", "//span[@class='pr']")

change "SGX:Z74" accordingly ;)
 

keithwb

Master Member
Joined
Mar 28, 2008
Messages
2,543
Reaction score
0
removed post as code posted are not efficient and not longer using.
 
Last edited:

chuanz

Supremacy Member
Joined
Nov 18, 2007
Messages
5,016
Reaction score
18
Pls note there's a trigger time consumed daily limit. If you set the trigger too frequent and say Yahoo site does a timeout, you're screwed for the day as far as the "auto update" is concerned.

Just sharing some learning from my personal GS experiences.
 

godbowen

Junior Member
Joined
Apr 20, 2010
Messages
79
Reaction score
0
Google sheet on YahooFinance stock price API is not working.
Anyone has this issue?
 

dotreddot

Junior Member
Joined
Mar 22, 2016
Messages
78
Reaction score
10
Can consider to have a separate on-line copy in Google Finance? ...
Create you portfolio there ... When spreadsheet down still can see on-line?

mine down too kan sianz

cannot see the value of my positions

heng is bull not bear day
 

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,757
Reaction score
533
In a big corporation like google, this is a sign of de-emphasizing. The job on maintaining has been assigned to some obscure department where nobody gives a sheet. It's time to move on.:o
 

peterchan75

Supremacy Member
Joined
Apr 26, 2003
Messages
6,757
Reaction score
533
end up now switch to manual keying in the stock prices
sianz

maybe everyday market close key in once

GG

Using Excel macro and pull from Yahoo Finance or SGX if you are tracking stock price. This is better then manual data entry.
 

thegodfather

Senior Member
Joined
Apr 3, 2007
Messages
1,970
Reaction score
55
I think there is an issue w Google sheets my importdata functions all not working. Laggy too. And I thought I was the only one
 

Average

Banned
Joined
Apr 14, 2012
Messages
28,980
Reaction score
279
Browser din crash but the particular tab will be damn lag, like 3min lag. Cam still use other tabs normally.
 
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top