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

Sorry, comments are closed for this item.