32

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.

Tuan
  • 2,883
  • 4
  • 32
  • 54
Adi
  • 2,248
  • 1
  • 12
  • 22

4 Answers4

26

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.

zacjordaan
  • 3,521
  • 2
  • 16
  • 16
  • 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? – Bibaswann Bandyopadhyay Mar 18 '16 at 12:12
  • 1
    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 options – Bibaswann Bandyopadhyay Mar 18 '16 at 12:22
  • 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. – William T. May 05 '16 at 02:53
  • example 2 api is not good. The datasource is probably broken. – João Nunes May 23 '16 at 20:20
  • 1
    @zacjordaan All the API's are down is there any other alternative or has yahoo changed the API? – Vignesh S Aug 06 '17 at 05:55
  • 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 [here](https://stackoverflow.com/questions/38355075/has-yahoo-finance-web-service-disappeared-api-changed-down-temporarily) – zacjordaan Aug 07 '17 at 07:25
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).

Vivek Jha
  • 1,282
  • 2
  • 14
  • 23
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.

kmiklas
  • 11,204
  • 17
  • 55
  • 84
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

Thom
  • 21
  • 1