-2

I am using Yahoo Api and Web Services..

For example:

http://query.yahooapis.com/v1/public/yql?q=select symbol,DaysLow,DaysHigh,PreviousClose from yahoo.finance.quotes where symbol in ("INDUSINDB.NS,YESBANK.NS,CANBK.NS,AXISBANK.NS,SBIN.NS,KOTAKBANK.NS,HDFCBANK.NS,BANKBAROD.NS,UNIONBANK.NS,BANKINDIA.NS,ICICIBANK.NS,PNB.NS")&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

http://query.yahooapis.com/v1/public/yql?q=select symbol,DaysLow,DaysHigh,PreviousClose from yahoo.finance.quotes where symbol in ("ACC.NS,AMBUJACEM.NS,ASIANPAIN.NS,AXISBANK.NS,BAJAJAUTO.NS,BANKBAROD.NS,BHARTIART.NS,BHEL.NS,BPCL.NS,CAIRN.NS,CIPLA.NS,COALINDIA.NS,DLF.NS,DRREDDY.NS,GAIL.NS,GRASIM.NS,HCLTECH.NS,HDFC.NS,HDFCBANK.NS,HEROHONDA.NS,HINDALCO.NS,HINDUNILV.NS,ICICIBANK.NS,IDFC.NS,INFY.NS,ITC.NS,JINDALSTE.NS,JPASSOCIA.NS,KOTAKBANK.NS,LT.NS,M%26M.NS,MARUTI.NS,NTPC.NS,ONGC.NS,PNB.NS,POWERGRID.NS,RANBAXY.NS,RELIANCE.NS,RELINFRA.NS,SAIL.NS,SBIN.NS,SESAGOA.NS,SIEMENS.NS,STER.NS,SUNPHARMA.NS,TATAMOTOR.NS,TATAPOWER.NS,TATASTEEL.NS,TCS.NS,WIPRO.NS")&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

These Webservices returns me the Xml. But some times it does not return any results.

It shows

This XML file does not appear to have any style information associated with it. The document tree is shown below.

Can any one please help me on this

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Surya
  • 439
  • 3
  • 9
  • 31

2 Answers2

2

First: This XML file does not appear to have any style information associated with it. ... does not prevent the file to display the results. It seems like there is a lot of traffic and the query takes too long.

YQL Datatables are just csv conversions. Thus you can directly query the csv behind. Moreover when there is a lot of traffic, YQL datatables are often down whereas csv files are almost up-to-date.

You can do the same (CSV instead of XML) with the following query:

http://download.finance.yahoo.com/d/quotes.csv?f=smp&s=INDUSINDB.NS,YESBANK.NS,CANBK.NS,AXISBANK.NS,SBIN.NS,KOTAKBANK.NS,HDFCBANK.NS,BANKBAROD.NS,UNIONBANK.NS,BANKINDIA.NS,ICICIBANK.NS,PNB.NS

CSV Files are more reliable (direct source of informations instead of conversion) and faster.

Romain
  • 6,322
  • 3
  • 35
  • 40
  • Thanks a ton :) Can you please provide me the guidelines to prase an CSV file in ajax calls....I have no clue how to work with the CSV files... – Surya Aug 28 '12 at 12:21
  • 1
    to parse the csv file just do `$handle = fopen($file, "r");` with `$file` the url of the query. Then `$stocks=array(); while($data = fgetcsv($handle, 4096, ',')){ $stocks[$i]['symbol']=$data[0]; $stocks[$i]['name']=$data[1]; $i++; ...//others variables } fclose($handle);` You can then use your array `$stocks` with all your informations. – Romain Aug 30 '12 at 10:21
0

The snippet you have provided returns N/A for all fields. In general, Yahoo APIs seem to have serious limitations for bourses outside the West. I have experimented with YQL as well as the REST apis and am unable to access data for Indian stocks.

Try substituting RIL.BO for most of the examples here: http://www.gummy-stuff.org/Yahoo-data.htm

Works well for GOOG and YHOO and AAPL. For Indian stocks like RIL.BO, all I get is N/As. Your query repeatedly returns:

INDUSINDB.NS    N/A - N/A   N/A
YESBANK.NS      N/A - N/A   N/A
CANBK.NS        N/A - N/A   N/A
AXISBANK.NS     N/A - N/A   N/A
SBIN.NS         N/A - N/A   N/A
KOTAKBANK.NS    N/A - N/A   N/A
HDFCBANK.NS     N/A - N/A   N/A
BANKBAROD.NS    N/A - N/A   N/A
UNIONBANK.NS    N/A - N/A   N/A
BANKINDIA.NS    N/A - N/A   N/A
ICICIBANK.NS    N/A - N/A   N/A
PNB.NS          N/A - N/A   N/A

Pity! Yahoo! doesn't appear serious about their APIs or this could be so useful. Documentation is not helpful either.

Sun Bee
  • 1,595
  • 15
  • 22