[java] How can I get stock quotes using Google Finance API?

I'm looking for access to financial data from Google services.

I found this URL that gets the stock data for Microsoft.

What are all the possible parameters that Google allows for this kind of HTTP request? I'd like to see all the different information that I could get.

This question is related to java php javascript google-api google-finance

The answer is


In order to find chart data using the financial data API of Google, one must simply go to Google as if looking for a search term, type finance into the search engine, and a link to Google finance will appear. Once at the Google finance search engine, type the ticker name into the financial data API engine and the result will be displayed. However, it should be noted that all Google finance charts are delayed by 15 minutes, and at most can be used for a better understanding of the ticker's past history, rather than current price.

A solution to the delayed chart information is to obtain a real-time financial data API. An example of one would be the barchartondemand interface that has real-time quote information, along with other detailed features that make it simpler to find the exact chart you're looking for. With fully customizable features, and specific programming tools for the precise trading information you need, barchartondemand's tools outdo Google finance by a wide margin.


The Google stock quote API has gone away. However, Investor's Exchange offers an API that's very easy to use for quote data.


Here is an example that you can use. Havent got Google Finance yet, but Here is the Yahoo Example. You will need the HTMLAgilityPack , Which is awesome. Happy Symbol Hunting.

Call the procedure by using YahooStockRequest(string Symbols);

Where Symbols = a comma-delimited string of symbols, or just one symbol

public string YahooStockRequest(string Symbols,bool UseYahoo=true)
        {
            {
                string StockQuoteUrl = string.Empty;

                try
                {
                    // Use Yahoo finance service to download stock data from Yahoo
                    if (UseYahoo)
                    {
                        string YahooSymbolString = Symbols.Replace(",","+");
                        StockQuoteUrl = @"http://finance.yahoo.com/q?s=" + YahooSymbolString + "&ql=1";
                    }
                    else
                    {
                        //Going to Put Google Finance here when I Figure it out.
                    }

                    // Initialize a new WebRequest.
                    HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(StockQuoteUrl);
                    // Get the response from the Internet resource.
                    HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
                    // Read the body of the response from the server.

                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    string pageSource;
                    using (StreamReader sr = new StreamReader(webresp.GetResponseStream()))
                    {
                        pageSource = sr.ReadToEnd();
                    }
                    doc.LoadHtml(pageSource.ToString());
                    if (UseYahoo)
                    {
                        string Results=string.Empty;
                        //loop through each Symbol that you provided with a "," delimiter
                        foreach (string SplitSymbol in Symbols.Split(new char[] { ',' }))
                        {
                            Results+=SplitSymbol + " : " + doc.GetElementbyId("yfs_l10_" + SplitSymbol).InnerText + Environment.NewLine;
                        }
                        return (Results);
                    }
                    else
                    {
                        return (doc.GetElementbyId("ref_14135_l").InnerText);
                    }

                }
                catch (WebException Webex)
                {
                    return("SYSTEM ERROR DOWNLOADING SYMBOL: " + Webex.ToString());

                }

            }
        }

The simplest way as you have explained is this link this is for 'Dow Jones Industrial Average'

Link 2 is for 'NASDAQ-100'

and for all related to NASDAQ link 3

I think this should be it, else you want same in JSON notations the same as Microsoft

Please refer this old post I think this will help,

Update:

To know the details of volume and other details, I have created a vbscript that is using IE object to fetch details from the link, and alerts the content in the particular id(Create a .vbs file and run it..

Set IE = CreateObject("InternetExplorer.Application")
while IE.readyState = 4: WScript.Sleep 10: wend
IE.Navigate "https://www.google.com/finance?q=INDEXNASDAQ%3ANDX&sq=NASDAQ&sp=2&ei=B3UoUsiIH5DIlgPEsQE"
IE.visible = true
while IE.readyState = 4: WScript.Sleep 10: wend
dim ht
ht= IE.document.getElementById("market-data-div").innerText
msgBox ht
IE.quit

this will alert the values from page like this

3,124.54 0.00 (0.00%)
Sep 4 - Close
INDEXNASDAQ real-time data - Disclaimer
Range       -
52 week 2,494.38 - 3,149.24
Open        -
Vol.    0.00

I am sure this will help..


This is no longer an active API for google, you can try Xignite, although they charge: http://www.xignite.com


Try with this: http://finance.google.com/finance/info?client=ig&q=NASDAQ:GOOGL

It will return you all available details about the mentioned stock.

e.g. out put would look like below:

// [ {
"id": "694653"
,"t" : "GOOGL"
,"e" : "NASDAQ"
,"l" : "528.08"
,"l_fix" : "528.08"
,"l_cur" : "528.08"
,"s": "0"
,"ltt":"4:00PM EST"
,"lt" : "Dec 5, 4:00PM EST"
,"lt_dts" : "2014-12-05T16:00:14Z"
,"c" : "-14.50"
,"c_fix" : "-14.50"
,"cp" : "-2.67"
,"cp_fix" : "-2.67"
,"ccol" : "chr"
,"pcls_fix" : "542.58"
}
]

You can have your company stock symbol at the end of this URL to get its details:

http://finance.google.com/finance/info?client=ig&q=<YOUR COMPANY STOCK SYMBOL>


Building upon the shoulders of giants...here's a one-liner I wrote to zap all of Google's current stock data into local Bash shell variables:

stock=$1 

# Fetch from Google Finance API, put into local variables
eval $(curl -s "http://www.google.com/ig/api?stock=$stock"|sed 's/</\n</g' |sed '/data=/!d; s/ data=/=/g; s/\/>/; /g; s/</GF_/g' |tee /tmp/stockprice.tmp.log)

echo "$stock,$(date +%Y-%m-%d),$GF_open,$GF_high,$GF_low,$GF_last,$GF_volume"

Then you will have variables like $GF_last $GF_open $GF_volume etc. readily available. Run env or see inside /tmp/stockprice.tmp.log

http://www.google.com/ig/api?stock=TVIX&output=csv by itself returns:

<?xml version="1.0"?>
<xml_api_reply version="1">
<finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<symbol data="TVIX"/>
<pretty_symbol data="TVIX"/>
<symbol_lookup_url data="/finance?client=ig&amp;q=TVIX"/>
<company data="VelocityShares Daily 2x VIX Short Term ETN"/>
<exchange data="AMEX"/>
<exchange_timezone data="ET"/>
<exchange_utc_offset data="+05:00"/>
<exchange_closing data="960"/>
<divisor data="2"/>
<currency data="USD"/>
<last data="57.45"/>
<high data="59.70"/>
<low data="56.85"/>

etc.

So for stock="FBM" /tmp/stockprice.tmp.log (and your environment) will contain:

GF_symbol="FBM"; 
GF_pretty_symbol="FBM"; 
GF_symbol_lookup_url="/finance?client=ig&amp;q=FBM"; 
GF_company="Focus Morningstar Basic Materials Index ETF"; 
GF_exchange="NYSEARCA"; 
GF_exchange_timezone=""; 
GF_exchange_utc_offset=""; 
GF_exchange_closing=""; 
GF_divisor="2"; 
GF_currency="USD"; 
GF_last="22.82"; 
GF_high="22.82"; 
GF_low="22.82"; 
GF_volume="100"; 
GF_avg_volume=""; 
GF_market_cap="4.56"; 
GF_open="22.82"; 
GF_y_close="22.80"; 
GF_change="+0.02"; 
GF_perc_change="0.09"; 
GF_delay="0"; 
GF_trade_timestamp="8 hours ago"; 
GF_trade_date_utc="20120228"; 
GF_trade_time_utc="184541"; 
GF_current_date_utc="20120229"; 
GF_current_time_utc="033534"; 
GF_symbol_url="/finance?client=ig&amp;q=FBM"; 
GF_chart_url="/finance/chart?q=NYSEARCA:FBM&amp;tlf=12"; 
GF_disclaimer_url="/help/stock_disclaimer.html"; 
GF_ecn_url=""; 
GF_isld_last=""; 
GF_isld_trade_date_utc=""; 
GF_isld_trade_time_utc=""; 
GF_brut_last=""; 
GF_brut_trade_date_utc=""; 
GF_brut_trade_time_utc=""; 
GF_daylight_savings="false"; 

The problem with Yahoo and Google data is that it violates terms of service if you're using it for commercial use. When your site/app is still small it's not biggie, but as soon as you grow a little you start getting cease and desists from the exchanges. A licensed solution example is FinancialContent: http://www.financialcontent.com/json.php or Xignite


Perhaps of interest, the Google Finance API documentaton includes a section detailing how to access different parameters via JavaScript.

I suppose the JavaScript API might be a wrapper to the JSON request you mention above... perhaps you could check which HTTP requests are being sent.


I found this site helpful.

http://benjisimon.blogspot.com/2009/01/truly-simple-stock-api.html

It links to an API yahoo seems to offer that is very simple and useful.

For instance:

http://finance.yahoo.com/d/quotes.csv?s=GOOG+AAPL&f=snl1

Full details here:

http://www.gummy-stuff.org/Yahoo-data.htm


Edit: the api call has been removed by google. so it is no longer functioning.

Agree with Pareshkumar's answer. Now there is a python wrapper googlefinance for the url call.

Install googlefinance

$pip install googlefinance

It is easy to get current stock price:

>>> from googlefinance import getQuotes
>>> import json
>>> print json.dumps(getQuotes('AAPL'), indent=2)
[
  {
    "Index": "NASDAQ", 
    "LastTradeWithCurrency": "129.09", 
    "LastTradeDateTime": "2015-03-02T16:04:29Z", 
    "LastTradePrice": "129.09", 
    "Yield": "1.46", 
    "LastTradeTime": "4:04PM EST", 
    "LastTradeDateTimeLong": "Mar 2, 4:04PM EST", 
    "Dividend": "0.47", 
    "StockSymbol": "AAPL", 
    "ID": "22144"
  }
]

Google finance is a source that provides real-time stock data. There are also other APIs from yahoo, such as yahoo-finance, but they are delayed by 15min for NYSE and NASDAQ stocks.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to javascript

need to add a class to an element How to make a variable accessible outside a function? Hide Signs that Meteor.js was Used How to create a showdown.js markdown extension Please help me convert this script to a simple image slider Highlight Anchor Links when user manually scrolls? Summing radio input values How to execute an action before close metro app WinJS javascript, for loop defines a dynamic variable name Getting all files in directory with ajax

Examples related to google-api

Google API authentication: Not valid origin for the client Using Postman to access OAuth 2.0 Google APIs How can I validate google reCAPTCHA v2 using javascript/jQuery? This IP, site or mobile application is not authorized to use this API key Is there a Google Keep API? OAuth2 and Google API: access token expiration time? invalid_grant trying to get oAuth token from google Alternative to google finance api How do I access (read, write) Google Sheets spreadsheets with Python? How to refresh token with Google API client?

Examples related to google-finance

Download all stock symbol list of a market How to make google spreadsheet refresh itself every 1 minute? How to use GOOGLEFINANCE(("CURRENCY:EURAUD")) function Download history stock prices automatically from yahoo finance in python Alternative to google finance api How can I get stock quotes using Google Finance API?