Jarloo

Menu

Real-Time Google Stock API

Google Stock API

Using this API you can get the Google real-time price. (might not be market real-time but as soon as Google gets it you can get it)

This also includes After hour prices!

 

Stock API Details

This is a REST based API. Here is the basic syntax:

http://finance.google.com/finance/info?client=ig&q=NASDAQ%3A[STOCK TICKERS]

An example of this:

http://finance.google.com/finance/info?client=ig&q=NASDAQ%3AAAPL,GOOG

As you can see, it’s simple to provide multiple tickers: just add a comma between them. This example gets Apple and Google stock prices from NASDAQ.

Not sure how many tickers you can ask for. I’ve tried 16 and it’s worked but I’m sure if you ask for too many you will run into troubles.

 

Return Stock Data

The data is returned as a JSON array. Each element in the array looks like so:

{
"id": "22144"
,"t" : "AAPL"
,"e" : "NASDAQ"
,"l" : "108.00"
,"l_fix" : "108.00"
,"l_cur" : "108.00"
,"s": "2"
,"ltt":"4:00PM EDT"
,"lt" : "Aug 10, 4:00PM EDT"
,"lt_dts" : "2016-08-10T16:00:01Z"
,"c" : "-0.81"
,"c_fix" : "-0.81"
,"cp" : "-0.74"
,"cp_fix" : "-0.74"
,"ccol" : "chr"
,"pcls_fix" : "108.81"
,"el": "107.98"
,"el_fix": "107.98"
,"el_cur": "107.98"
,"elt" : "Aug 10, 5:16PM EDT"
,"ec" : "-0.02"
,"ec_fix" : "-0.02"
,"ecp" : "-0.02"
,"ecp_fix" : "-0.02"
,"eccol" : "chr"
,"div" : "0.57"
,"yld" : "2.11"
}

I haven’t decoded all of it, but there are some that I have:

t Ticker
e Exchange
l Last Price
ltt Last Trade Time
l Price
lt Last Trade Time Formatted
lt_dts Last Trade Date/Time
c Change
cp Change Percentage
el After Hours Last Price
elt After Hours Last Trade Time Formatted
div Dividend
yld Dividend Yield

 

 

C# Code to use the Google Stock API

NOTE: This uses Newtonsoft.Json, it’s free, you can get it from Nuget in Visual Studio by just right-clicking Resources and selecting Nuget and then selecting Newtonsoft.json.

This is a simple ConsoleApplication that grabs some tickers and displays the results to the console. I did a console app to make it as simple as possible to show how to get the data without complicating things with a UI implementation.

using System;
using System.Net;
using Newtonsoft.Json.Linq;

namespace Jarloo.GoogleApi2
{
    internal class Program
    {
        private static void Main()
        {
            const string tickers = "AAPL,GOOG,GOOGL,YHOO,TSLA,INTC,AMZN,BIDU,ORCL,MSFT,ORCL,ATVI,NVDA,GME,LNKD,NFLX";

            string json;

            using (var web = new WebClient())
            {
                var url = $"http://finance.google.com/finance/info?client=ig&q=NASDAQ%3A{tickers}";
                json = web.DownloadString(url);
            }

            //Google adds a comment before the json for some unknown reason, so we need to remove it
            json = json.Replace("//", "");

            var v = JArray.Parse(json);

            foreach (var i in v)
            {
                var ticker = i.SelectToken("t");
                var price = (decimal)i.SelectToken("l");
                
                Console.WriteLine($"{ticker} : {price}");
            }

            Console.WriteLine("Press any key to exit");
            Console.Read();
        }
    }
}

Be Careful

Remember this API is undocumented and can change or stop working at anytime without notice. Please don’t use it in a production application.

Don’t hit this api more than once a minute, or for 200 tickers, you will get your IP blocked.

 

Enjoy

That’s it! Easy to use, and it returns data very fast. Enjoy!

If you decode more of the return message, or find more exchanges, or simply have more information around this API please let me know in the comments below and I can update the article.

 

 

 

 

Categories:   Uncategorized

Tags:  , , , ,

Comments

  • Posted: August 10, 2016 17:08

    Un-registered user

    Do you know if the price is in realtime? Or delayed?
    • Posted: August 11, 2016 21:19

      Kelly Elias

      The prices are the same as on Google Finance. So delayed by a bit but seconds instead of minutes in my testing.
    • Posted: January 2, 2017 10:29

      Conor

      This is a 15-minute plus delayed pricing feed as Google's stock price API is already 15 minutes delayed
  • Posted: August 11, 2016 11:53

    Diego

    I'm not too familiar with C#. Can this be done using Java as well?
    • Posted: August 21, 2016 21:04

      Kelly Elias

      Yes. It's just a REST based API, which means it's easy to implement in any language.
  • Posted: August 19, 2016 05:03

    jim p

    Great post! I've started trying it out and the London Stock Exchange code is LSE. UK Mutual funds are MUTF_GB but one I tried (Liontrust Special Situations) returned zeros - https://finance.google.com/finance/info?client=ig&q=MUTF_GB:LION_SPEC_SITU_1J7D60E Don't know why this happens
    • Posted: August 30, 2016 09:32

      Ivan

      The same I tried for Moscow Exchange and it also didn't work.
    • Posted: August 30, 2016 09:34

      Ivan

      I tried another approach http://finance.google.com/finance/info?client=ig&q=MOEX:LSRG With such way it works well
      • Posted: August 31, 2016 02:56

        jim p

        Interesting! I tried your second approach and it gave me blanks: // [ { "id": "721973" ,"t" : "LSRG" ,"e" : "LON" ,"l" : "" ,"l_fix" : "" ,"l_cur" : "" ,"s": "" ,"ltt":"" ,"lt" : "" ,"lt_dts" : "" ,"c" : "" ,"c_fix" : "" ,"cp" : "" ,"cp_fix" : "" ,"ccol" : "" ,"pcls_fix" : "" } ] I wonder if some results are blocked in different countries.
  • Posted: October 16, 2016 10:19

    M

    Hello, I keep getting an error: the remote server returned an error (400) bad request using the exact code and package. What is the solution? Thanks
  • Posted: November 1, 2016 02:08

    Alex B

    Thanks very much for this. Do you know if you can also request stock data from a particular date? I guess being google is ok to use this on a normal website? :)
  • Posted: November 14, 2016 14:42

    Hasan

    Can I obtain historical quotes as well or only real-time?
  • Posted: December 2, 2016 20:50

    Dave

    I copy pasted the code and tried to run it. Google is no longer liking the request as you have it. I get {"The remote server returned an error: (400) Bad Request."}
  • Posted: December 20, 2016 07:17

    G. Dharmar

    I would like to know how to get the real-time stock report for different tickers dynamically, not by hard coding. I would like to use it Android using Retrofit2 Thanking You
  • Posted: January 2, 2017 10:28

    Conor

    This is very misleading as the Google stock price API is already 15 minutes delayed... and then this API is a few seconds further delayed. In general this is a "15-minutes+ stock price API."