Jarloo

Menu

Get Stock Data from Google Finance and YQL

Want data from Google Finance? You can get it the easiest from.. (wait for it)… Yahoo!

Yes I’m serious, you would think Google would make this easier, but since they don’t here is a great way to get some data courtesy of YQL.

YQL can be accessed via REST, and it allows people like you and I to make our own web-scrapes! Very powerful tech. There are quite a few out there including one to get Google Finance information which is what I’m sure your looking for.

Getting the Google Finance Stock Data

Regardless of the programming language your using you can use YQL since it’s REST based. (did I mention how much I love REST?)

Here is a quick example of the YQL call to get Apple and Google stock data. (AAPL and GOOG)

select * from google.igoogle.stock where stock in ('AAPL','GOOG');

The REST URL for the above YQL looks like so:

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20google.igoogle.stock%20where%20stock%20in%20('AAPL'%2C'GOOG')%3B&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

The Stock Information as a Result

So when you call the Google Finance YQL function (REST API) you get data like so:

<?xml version="1.0" encoding="UTF-8"?>
<query xmlns:yahoo="http://www.yahooapis.com/v1/base.rng"
    yahoo:count="2" yahoo:created="2012-03-06T04:16:21Z" yahoo:lang="en-US">
    <diagnostics>
        <publiclyCallable>true</publiclyCallable>
        <url execution-start-time="20" execution-stop-time="23"
            execution-time="3" proxy="DEFAULT"><![CDATA[http://www.datatables.org/google/google.igoogle.stock.xml]]></url>
        <url execution-start-time="25" execution-stop-time="112"
            execution-time="87" proxy="DEFAULT"><![CDATA[http://www.google.com/ig/api?stock=GOOG]]></url>
        <url execution-start-time="25" execution-stop-time="163"
            execution-time="138" proxy="DEFAULT"><![CDATA[http://www.google.com/ig/api?stock=AAPL]]></url>
        <user-time>164</user-time>
        <service-time>228</service-time>
        <build-version>25587</build-version>
    </diagnostics> 
    <results>
        <xml_api_reply version="1">
            <finance mobile_row="0" mobile_zipped="1" module_id="0"
                row="0" section="0" tab_id="0">
                <symbol data="AAPL"/>
                <pretty_symbol data="AAPL"/>
                <symbol_lookup_url data="/finance?client=ig&amp;q=AAPL"/>
                <company data="Apple Inc."/>
                <exchange data="Nasdaq"/>
                <exchange_timezone data="ET"/>
                <exchange_utc_offset data="+05:00"/>
                <exchange_closing data="960"/>
                <divisor data="2"/>
                <currency data="USD"/>
                <last data="533.16"/>
                <high data="547.48"/>
                <low data="526.00"/>
                <volume data="28897169"/>
                <avg_volume data="19174"/>
                <market_cap data="497102.36"/>
                <open data="545.42"/>
                <y_close data="545.18"/>
                <change data="-12.02"/>
                <perc_change data="-2.20"/>
                <delay data="0"/>
                <trade_timestamp data="7 hours ago"/>
                <trade_date_utc data="20120305"/>
                <trade_time_utc data="210001"/>
                <current_date_utc data="20120306"/>
                <current_time_utc data="041621"/>
                <symbol_url data="/finance?client=ig&amp;q=AAPL"/>
                <chart_url data="/finance/chart?q=NASDAQ:AAPL&amp;tlf=12"/>
                <disclaimer_url data="/help/stock_disclaimer.html"/>
                <ecn_url data=""/>
                <isld_last data="532.20"/>
                <isld_trade_date_utc data="20120306"/>
                <isld_trade_time_utc data="005926"/>
                <brut_last data=""/>
                <brut_trade_date_utc data=""/>
                <brut_trade_time_utc data=""/>
                <daylight_savings data="false"/>
            </finance>
        </xml_api_reply>
        <xml_api_reply version="1">
            <finance mobile_row="0" mobile_zipped="1" module_id="0"
                row="0" section="0" tab_id="0">
                <symbol data="GOOG"/>
                <pretty_symbol data="GOOG"/>
                <symbol_lookup_url data="/finance?client=ig&amp;q=GOOG"/>
                <company data="Google Inc"/>
                <exchange data="Nasdaq"/>
                <exchange_timezone data="ET"/>
                <exchange_utc_offset data="+05:00"/>
                <exchange_closing data="960"/>
                <divisor data="2"/>
                <currency data="USD"/>
                <last data="614.25"/>
                <high data="622.49"/>
                <low data="611.38"/>
                <volume data="1593250"/>
                <avg_volume data="2817"/>
                <market_cap data="199714.99"/>
                <open data="620.43"/>
                <y_close data="621.25"/>
                <change data="-7.00"/>
                <perc_change data="-1.13"/>
                <delay data="0"/>
                <trade_timestamp data="7 hours ago"/>
                <trade_date_utc data="20120305"/>
                <trade_time_utc data="210005"/>
                <current_date_utc data="20120306"/>
                <current_time_utc data="041621"/>
                <symbol_url data="/finance?client=ig&amp;q=GOOG"/>
                <chart_url data="/finance/chart?q=NASDAQ:GOOG&amp;tlf=12"/>
                <disclaimer_url data="/help/stock_disclaimer.html"/>
                <ecn_url data=""/>
                <isld_last data=""/>
                <isld_trade_date_utc data=""/>
                <isld_trade_time_utc data=""/>
                <brut_last data=""/>
                <brut_trade_date_utc data=""/>
                <brut_trade_time_utc data=""/>
                <daylight_savings data="false"/>
            </finance>
        </xml_api_reply>
    </results>
</query>

You can see the two distinct stocks, as they are defined by the finance XML header. You can also see the information this YQL call returns ie: high, low, close, open, last, change etc…

If you want more info on how to parse the Google Finance API data in C# take a look at the Yahoo Finance version I’ve posted Reading the Yahoo Finance API in C#

Categories:   Code, Finance

Tags:  , , , , , , ,

Comments

  • Posted: July 4, 2012 06:20

    bhaveek patel

    I am a bit cautious on google finance data, google seems to be shutting down its finance api. So all of the apps that i build will no longer work once they close their api. Can i get yahoo api which will do the same job that google api used to do.??
  • Posted: November 22, 2012 16:22

    Abdelrahaman Aly

    Hey what if I want historical data from the google engine?
  • Posted: May 2, 2013 16:33

    SPECULARI (@thespeculari)

    How from Yahoo Finance get ticker name by current news (headline)? I know how get news by ticker name (symbol lookup) by how do the opposite? Thank you!