Yahoo finance webservice API
Asked Answered
N

4

33

I am trying to get realtime stock data from BSE and NSE using yahoo finance web-services. I was able to get some data using following URL

http://finance.yahoo.com/webservice/v1/symbols/COALINDIA.NS/quote?format=json

But it gives me very limited information.

{
  "list": {
    "meta": {
      "type": "resource-list",
      "start": 0,
      "count": 1
    },
    "resources": [
      {
        "resource": {
          "classname": "Quote",
          "fields": {
            "name": "COAL INDIA LTD",
            "price": "367.649994",
            "symbol": "COALINDIA.NS",
            "ts": "1418895539",
            "type": "equity",
            "utctime": "2014-12-18T09:38:59+0000",
            "volume": "2826975"
          }
        }
      }
    ]
  }
}

I need more information like yearly high, low, last traded price etc. and I couldn't find any documentation related to this from yahoo where it details how to get more information.

Is there documentation available related to these services? Or please suggest if there are any alternatives available.

Nun answered 18/12, 2014 at 9:57 Comment(1)
starting sometimes in 2017, none of the yahoo url worksDetrimental
H
27

I don't know where the definitive documentation might be but for your particular example try appending &view=detail to your URL.

http://finance.yahoo.com/webservice/v1/symbols/COALINDIA.NS/quote?format=json&view=detail

This will at least give you the year_high and year_low that you asked after.

Now, even though the following won't work for your COALINDIA.NS symbol (I suspect the exchange is not supported), it might be worth exploring the following two examples:

Example 1: As before, but for Apple and Yahoo symbols, with &view=detail appended:

http://finance.yahoo.com/webservice/v1/symbols/YHOO,AAPL/quote?format=json&view=detail

Example 2: And now using a completely different url, resulting in much more response data. One key caveat is this data is delayed by 15 minutes:

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20IN%20(%22YHOO%22,%22AAPL%22)&format=json&env=http://datatables.org/alltables.env

If you discover the major differences between those two options and what impact they might have then please do let us all know; I'd be interested in finding out more.

Helban answered 1/5, 2015 at 9:18 Comment(6)
This is very useful, thank you. I was looking for the detailed info but didn't know about &view=detail querystring, how did you come to know about this anyway?Zeralda
There is also this option http://download.finance.yahoo.com/d/quotes.csv?s=aapl,msft,ibm&f=sl1d1t1c1ohgv&e=.csv. I am too curious to know the difference among all these optionsZeralda
Your Example 2, for some reason, seems unusable. The numbers returned are different every time you refresh the page... even when the stock market is closed.Burgener
example 2 api is not good. The datasource is probably broken.Cereus
@Helban All the API's are down is there any other alternative or has yahoo changed the API?Succor
I haven't looked at this in the two years since I posted it but a quick search indicates that this api is indeed no longer available. See hereHelban
C
6

If you are fine with getting NSE qoutes, you can use this package for the purpose, it is extremely easy to setup.

http://nsetools.readthedocs.org/en/latest/index.html

Since it uses NSE website/services as data source, the quotes will not be delayed (max few seconds).

Ceruse answered 7/1, 2015 at 11:47 Comment(0)
D
4

Beware that these data are both delayed and inconsistent. You are not getting anything even remotely close to tick or real-time data.

From example 2, refresh a few times, and inspect the "LastTradeWithTime" key-value pair. I sometimes get different quotes from different times of day, for no apparent reason. They are sometimes delayed up to three hours.

You get what you pay for; in other words, this is not a free lunch.

Dupaix answered 31/3, 2016 at 1:43 Comment(0)
N
2

For those who are curious about the different options available in the Yahoo Finance URLs, I think these links might help. If it's not what you're looking for, sorry.

http://internetbandaid.com/2009/03/31/yahoo-stocks-api/

https://ilmusaham.wordpress.com/tag/stock-yahoo-data/

Note: the wordpress site contains information that was taken from a site called gummy-stuff.org which is listed in full at the bottom of the above site (I can only list 2 urls in this post so I had to do the round-about way). Oddly, I found this site on my own yesterday. Funny how stuff comes back around. If you visit this site you'll just see a statement from Yahoo that the info he had originally listed (you're looking at some of this site on the above wordpress site) was never intended to be for public consumption and is a violation of Yahoo's terms and conditions agreement as it can apparently be used for hacking purposes. I was curious to see what was on the original post so I searched for it on the WayBack Machine. BTW, the links to the spread sheets are still active in the archive.

Cheers. Thom

Nannie answered 3/5, 2016 at 9:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.