How the Free Yahoo Finance API Works
Yahoo finance provides a great and simple way to download free stock quotes. This service returns stock data in a CSV. (comma delimited format, you can just open it in Excel if you like)
The service Yahoo finance provides for free stock quotes is REST based. (love REST based stuff) So all you need to do is assemble the URL you want and it will give you the data your looking for.
The API lets you specify multiple symbols to download with a maximum of 200 per call. (You can make multiple calls, but if you call too fast it will lock your IP so be warned)
How to call the free Yahoo Finance API
The base url your going to call is http://finance.yahoo.com/d/quotes.csv
Then you add a ?s= and the stock symbols your interested in such as APPL, GOOG and MSFT like so
http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT
Then you specify the info you want. There is a large list of stuff you can specify, just look at the list below for more info.
http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT&f=nab
This will get the name of the stock, the ask price and bid price (the “nab” = name,ask and bid)
Financial Data you can Download
Pricing | Dividends |
a: Ask | y: Dividend Yield |
b: Bid | d: Dividend per Share |
b2: Ask (Realtime) | r1: Dividend Pay Date |
b3: Bid (Realtime) | q: Ex-Dividend Date |
p: Previous Close | |
o: Open | |
Date | |
c1: Change | d1: Last Trade Date |
c: Change & Percent Change | d2: Trade Date |
c6: Change (Realtime) | t1: Last Trade Time |
k2: Change Percent (Realtime) | |
p2: Change in Percent | |
Averages | |
c8: After Hours Change (Realtime) | m5: Change From 200 Day Moving Average |
c3: Commission | m6: Percent Change From 200 Day Moving Average |
g: Day’s Low | m7: Change From 50 Day Moving Average |
h: Day’s High | m8: Percent Change From 50 Day Moving Average |
k1: Last Trade (Realtime) With Time | m3: 50 Day Moving Average |
l: Last Trade (With Time) | m4: 200 Day Moving Average |
l1: Last Trade (Price Only) | |
t8: 1 yr Target Price | |
Misc | |
w1: Day’s Value Change | g1: Holdings Gain Percent |
w4: Day’s Value Change (Realtime) | g3: Annualized Gain |
p1: Price Paid | g4: Holdings Gain |
m: Day’s Range | g5: Holdings Gain Percent (Realtime) |
m2: Day’s Range (Realtime) | g6: Holdings Gain (Realtime) |
52 Week Pricing | Symbol Info |
k: 52 Week High | v: More Info |
j: 52 week Low | j1: Market Capitalization |
j5: Change From 52 Week Low | j3: Market Cap (Realtime) |
k4: Change From 52 week High | f6: Float Shares |
j6: Percent Change From 52 week Low | n: Name |
k5: Percent Change From 52 week High | n4: Notes |
w: 52 week Range | s: Symbol |
s1: Shares Owned | |
x: Stock Exchange | |
j2: Shares Outstanding | |
Volume | |
v: Volume | |
a5: Ask Size | |
b6: Bid Size | Misc |
k3: Last Trade Size | t7: Ticker Trend |
a2: Average Daily Volume | t6: Trade Links |
i5: Order Book (Realtime) | |
Ratios | l2: High Limit |
e: Earnings per Share | l3: Low Limit |
e7: EPS Estimate Current Year | v1: Holdings Value |
e8: EPS Estimate Next Year | v7: Holdings Value (Realtime) |
e9: EPS Estimate Next Quarter | s6 Revenue |
b4: Book Value | |
j4: EBITDA | |
p5: Price / Sales | |
p6: Price / Book | |
r: P/E Ratio | |
r2: P/E Ratio (Realtime) | |
r5: PEG Ratio | |
r6: Price / EPS Estimate Current Year | |
r7: Price / EPS Estimate Next Year | |
s7: Short Ratio |
Getting Stock Data in C#
Since this is a REST based finance API, to get the data using C# is easy. You can simply use a WebClient.DownloadString(myurl) to get the data. Once you get the data, it’s also easy to parse being a simple CSV format.
Here is a quick example of how you can use the free Yahoo Finance API in your C# code.
Application Entry Point (main)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
using
System;
using
System.Collections.Generic;
using
System.Net;
using
jarloo;
namespace
Jarloo
{
internal
class
Program
{
private
static
void
Main(
string
[] args)
{
string
csvData;
using
(WebClient web =
new
WebClient())
{
csvData = web.DownloadString(
"http://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT&f=snbaopl1"
);
}
List<Price> prices = YahooFinance.Parse(csvData);
foreach
(Price price
in
prices)
{
Console.WriteLine(
string
.Format(
"{0} ({1}) Bid:{2} Offer:{3} Last:{4} Open: {5} PreviousClose:{6}"
,price.Name,price.Symbol,price.Bid,price.Ask,price.Last,price.Open,price.PreviousClose));
}
Console.Read();
}
}
}
|
Parsing Class and State Bag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
using
System;
using
System.Collections.Generic;
namespace
jarloo
{
public
static
class
YahooFinance
{
public
static
List<Price> Parse(
string
csvData)
{
List<Price> prices =
new
List<Price>();
string
[] rows = csvData.Replace(
"\r"
,
""
).Split(
'\n'
);
foreach
(
string
row
in
rows)
{
if
(
string
.IsNullOrEmpty(row))
continue
;
string
[] cols = row.Split(
','
);
Price p =
new
Price();
p.Symbol = cols[0];
p.Name = cols[1];
p.Bid = Convert.ToDecimal(cols[2]);
p.Ask = Convert.ToDecimal(cols[3]);
p.Open = Convert.ToDecimal(cols[4]);
p.PreviousClose = Convert.ToDecimal(cols[5]);
p.Last = Convert.ToDecimal(cols[6]);
prices.Add(p);
}
return
prices;
}
}
public
class
Price
{
public
string
Symbol {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
decimal
Bid {
get
;
set
; }
public
decimal
Ask {
get
;
set
; }
public
decimal
Open {
get
;
set
; }
public
decimal
PreviousClose {
get
;
set
; }
public
decimal
Last {
get
;
set
; }
}
}
|
Exchanges and Yahoo
Had lots of people asking how to get stuff from Non-US exchanges. Being a good Canadian myself I’ve been looking into it, and here is the master Yahoo Exhcange List for all your data scraping goodness!
Country | Exchange | Suffix | Delay | Data Provider |
United States of America | American Stock Exchange | N/A | 15 min | Direct from Exchange |
United States of America | BATS Exchange | N/A | Real-time | Direct from Exchange |
United States of America | Chicago Board of Trade | .CBT | 10 min | Interactive Data Real-Time Services |
United States of America | Chicago Mercantile Exchange | .CME | 10 min | Interactive Data Real-Time Services |
United States of America | Dow Jones Indexes | N/A | Real-time | Interactive Data Real-Time Services |
United States of America | NASDAQ Stock Exchange | N/A | 15 min | Direct from Exchange |
United States of America | New York Board of Trade | .NYB | 30 min | Interactive Data Real-Time Services |
United States of America | New York Commodities Exchange | .CMX | 30 min | Interactive Data Real-Time Services |
United States of America | New York Mercantile Exchange | .NYM | 30 min | Interactive Data Real-Time Services |
United States of America | New York Stock Exchange | N/A | 15 min | Direct from Exchange |
United States of America | OTC Bulletin Board Market | .OB | 20 min | Direct from Exchange |
United States of America | Pink Sheets | .PK | 15 min | Direct from Exchange |
United States of America | S & P Indices | N/A | Real-time | Interactive Data Real-Time Services |
Argentina | Buenos Aires Stock Exchange | .BA | 30 min | Interactive Data Real-Time Services |
Austria | Vienna Stock Exchange | .VI | 15 min | Telekurs |
Australia | Australian Stock Exchange | .AX | 20 min | Interactive Data Real-Time Services |
Belgium | Brussels Stocks | .BR | 15 min | |
Brazil | BOVESPA – Sao Paolo Stock Exchange | .SA | 15 min | Interactive Data Real-Time Services |
Canada | Toronto Stock Exchange | .TO | 15 min | Interactive Data Real-Time Services |
Canada | TSX Venture Exchange | .V | 15 min | Interactive Data Real-Time Services |
Chile | Santiago Stock Exchange | .SN | 15 min | Interactive Data Real-Time Services |
China | Shanghai Stock Exchange | .SS | 30 min | Interactive Data Real-Time Services |
China | Shenzhen Stock Exchange | .SZ | 30 min | Interactive Data Real-Time Services |
Denmark | Copenhagen Stock Exchange | .CO | 15 min | Telekurs |
France | Euronext | .NX | 15 min | Telekurs |
France | Paris Stock Exchange | .PA | 15 min | Telekurs |
Germany | Berlin Stock Exchange | .BE | 15 min | Telekurs |
Germany | Bremen Stock Exchange | .BM | 15 min | Telekurs |
Germany | Dusseldorf Stock Exchange | .DU | 15 min | Telekurs |
Germany | Frankfurt Stock Exchange | .F | 15 min | Telekurs |
Germany | Hamburg Stock Exchange | .HM | 15 min | Telekurs |
Germany | Hanover Stock Exchange | .HA | 15 min | Telekurs |
Germany | Munich Stock Exchange | .MU | 15 min | Telekurs |
Germany | Stuttgart Stock Exchange | .SG | 15 min | Telekurs |
Germany | XETRA Stock Exchange | .DE | 15 min | Telekurs |
Hong Kong | Hong Kong Stock Exchange | .HK | 15 min | Interactive Data Real-Time Services |
India | Bombay Stock Exchange | .BO | 15 min | Interactive Data Real-Time Services |
India | National Stock Exchange of India | .NS | 15 min | National Stock Exchange of India |
Indonesia | Jakarta Stock Exchange | .JK | 10 min | Interactive Data Real-Time Services |
Israel | Tel Aviv Stock Exchange | .TA | 20 min | Telekurs |
Italy | Milan Stock Exchange | .MI | 20 min | Telekurs |
Japan | Nikkei Indices | N/A | 30 min | Interactive Data Real-Time Services |
Mexico | Mexico Stock Exchange | .MX | 20 min | Telekurs |
Netherlands | Amsterdam Stock Exchange | .AS | 15 min | Telekurs |
New Zealand | New Zealand Stock Exchange | .NZ | 20 min | Interactive Data Real-Time Services |
Norway | Oslo Stock Exchange | .OL | 15 min | Telekurs |
Portugal | Lisbon Stocks | .LS | 15 min | |
Singapore | Singapore Stock Exchange | .SI | 20 min | Interactive Data Real-Time Services |
South Korea | Korea Stock Exchange | .KS | 20 min | Interactive Data Real-Time Services |
South Korea | KOSDAQ | .KQ | 20 min | Interactive Data Real-Time Services |
Spain | Barcelona Stock Exchange | .BC | 15 min | Telekurs |
Spain | Bilbao Stock Exchange | .BI | 15 min | Telekurs |
Spain | Madrid Fixed Income Market | .MF | 15 min | Telekurs |
Spain | Madrid SE C.A.T.S. | .MC | 15 min | Telekurs |
Spain | Madrid Stock Exchange | .MA | 15 min | Telekurs |
Sweden | Stockholm Stock Exchange | .ST | 15 min | Telekurs |
Switzerland | Swiss Exchange | .SW | 30 min | Telekurs |
Taiwan | Taiwan OTC Exchange | .TWO | 20 min | Interactive Data Real-Time Services |
Taiwan | Taiwan Stock Exchange | .TW | 20 min | Interactive Data Real-Time Services |
United Kingdom | FTSE Indices | N/A | 15 min | Telekurs |
United Kingdom | London Stock Exchange | .L | 20 min | Telekurs |
103 Comments
Join the conversation and post a comment.
Great article! One thing I come to think off is how to use this to compare different stocks and how they are valued to each other. I was thinking about getting a list of stocks with it short names. Do u know where to find such lists?
Keep up the good work :)
BR
Sebastian
EODData has a good list of stock tickers if that is what you looking for. You need to sign up but it’s free and then you can download the lists. http://www.eoddata.com/download.aspx
BATS Also has a great list you can use, I have a quick article on how to get that data herehttp://www.jarloo.com/download-stock-symbols/
Would it possible to make the source code for this project available for download? If i do a simple copy and paste, i would be get an error for using Jarloo.
Sorry if that is a trivial request, but i am kinda new to C# and i would like to use your website to help me learn.
Thank you
@LALAS I posted the Visual Studio project, you can download from the big green button above.
Cheers.. :)
Is there anyway to retrieve the stocks Beta (risk) in a specific date?
Thanks!
Is there any way to specify a certain stock market? Some stocks codes overlap with another on a different exchange, (e.g TSCO is Tesco in UK and a tractor company in US, and this always returns the US one.)
Thanks.
TSCO.L is the ticker Yahoo uses for Tesco in London. In general, you’ll have to look up the suffixes for the exchanges.
Hi,
May I know how to retrieve stock option detail quotes ?
Thanks.
Kevin
Hi, I would like to know whether this method is actually using yahoo finance api or Yahoo Query Language ? I’m a bit confused. Could you please give some clarification regarding the same?
This uses an API and does NOT use YQL. The API has been around for years and works quite well.
Can monthly and weekly prices be downloaded through this api? If so how is it done?
As far as I am aware only dailies are available.
How do you get these information, can you share with us where is the Yahoo official documentation so we can always access the latest info from Yahoo? nevertheless this is still the best website in showing how to access Yahoo finance API. Thank.
I really like to retrieve the stock info via csv compare to YQL. Not so sure how to use YQL, but why I can’t find any documentation from Yahoo in how to use csv?
As far as I am aware there is no official documentation. This information I’ve gathered from others and trial and error by working with the API.
Yahoo,
I’m using
http://finance.yahoo.com/d/quotes.csv?s=DJI&f=sl1d1t1c1ohgv&e=.csv
to try to get the Dow jones and I’m not getting the data as I was in the past. Any ideas?
Kevin
The Yahoo data described above appears to be current day downloads – am i wrong?
I was looking for a way to download 5 years of daily data, so that i can then make 5 year charts. Please advise.
thanks
Here’s some more tags:
s6 – Revenue
j2 – Shares Outstanding
I want simulate Real time to create a demo of a Trading game.
Do you know about how many call my IP is locked ?
Do you have a solution to simulate real time for a demo (realtime or dealayed data), there isn’t real streaming quotes for free since the dead of opentick :(
thanks
Any idea how to get the information from the Yahoo Finance Analysts Estimates table? Here is an example:
http://finance.yahoo.com/q/ae?s=HTZ+Analyst+Estimates
Thanks!!
As far as I am aware there is no API but you can always scrape the data. Just use WebClient.DownloadString() to get the page and then use something the the HTML Agility Pack or even Regex to parse the data.
Thanks Kelly! Will do.
Just wanted to bring it to your attention that symbol “v” is used for both “Volume” & “More Info”.
Thanks for this post, it’s very helpful.
Anyway symbol to download BETA for a stock?
Hi Kelly! I have an Excel Macro to import around 15 stocks automatically, but when moving the XLS to Google Drive, they don’t support VBA, only Javascript (which I don’t know).
Any way to import Yahoo Finance data to Google Drive?
I don’t have much experience with using Google drive, but if you use Google Spreadsheets you can get Google Finance data directly into your sheet, and Google will keep it up to date. Use the formula: GoogleFinance(symbol, attribute)
More info: https://support.google.com/drive/bin/answer.py?hl=en&answer=155178
The Yahoo API that I’m currently referring so as to get the stock rates returns ZERO or ‘N/A’ for Canara Bank (CODE : CANARABANK.BO) but I can see the correct value for this stock on your sitehttp://in.finance.yahoo.com… May I know why I cannot see the correct value while using the API that you provide. I think there is a problem with the API. Please do reply as soon as possible. Awaiting your response….
Plz any one help me. I want to get Full compny name like for SODA the Full name is SodaStream International Ltd. I am waiating plz.
http://finance.yahoo.com/d/quotes.csv?s=SODA&f=snbaopl1
That should give you what you want. The last parameter “f” sets the fields to show. The table on this page shows each of them (that I know about anyway) and you can see that “n” is the flag you want to display the full name.
Is there a way to get commodities from yahoo finance with csv ?
Not that I’m aware of.
I am getting the stock price using the formula:
=WEBSERVICE(“http://finance.yahoo.com/d/quotes.csv?s=”&C2&”&f=l1″)
(“C2″ is the cell with the stock symbol)
However, I cannot figure out how to convert the result into a numeric so that I can use it in a formula. (Excel 2013 360) on Windows 8)
Any suggestions?
You can get commodity futures if you know the future, exchange, and month codes-
I don’t know how to get spot prices yet.
Gold=GC, Month=June, Year=13, exchange=CMX (metals)
% curl -s ‘http://download.finance.yahoo.com/d/quotes.csv?s=GCM13.CMX&f=snl1′
“GCM13.CMX”,”Gold Jun 13″,1469.60
Month Codes – (“F”,”G”,”H”,”J”,”K”,”M”,”N”,”Q”,”U”,”V”,”X”,”Z”)
Energy exchange is NYM
You can look up the future codes on the exchange web site.
Good Luck!
OK so when I use the API to generate a CSV it cuts the company name off after 17 characters…. Is there a workaround to this????
Ex. MSFT comes through as Microsoft Corpora instead of Microsoft Corporation
anyone can halp me couz i have one project about yahoo financ?
Following update of the code can be helpful in my opinion. Please check if it helps.
public static List Parse(string csvData)
{
List prices = new List();
string[] rows = csvData.Replace(“\r”, “”).Split(‘\n’);
foreach (string row in rows)
{
if (string.IsNullOrEmpty(row)) continue;
string rgPattern = “[\\*\\?\"'|]“;
Regex objRegEx = new Regex(rgPattern.ToString(), RegexOptions.None);
string nrow = objRegEx.Replace(row, string.Empty);
string[] cols = nrow.Split(‘,’);
Price p = new Price();
p.Symbol = cols[0];
p.Name = cols[1];
p.Bid = Convert.ToDecimal(cols[2]);
p.Ask = Convert.ToDecimal(cols[3]);
p.Open = Convert.ToDecimal(cols[4]);
p.PreviousClose = Convert.ToDecimal(cols[5]);
p.Last = Convert.ToDecimal(cols[6]);
prices.Add(p);
}
return prices;
}
I just updated the article with the Yahoo Exchange codes for every exchange, so you can use those to tell the difference.
Hello Kelly,
Do you know how the d2 flag is utilized? Can it work to retrieve a stock’s price at close on a given date? For example, can it pull the closing price for stock X on 06/14/2013? If so how, if not, then what is the d2 flag for?
Thanks!
hallo kelly, here sandro, from Italy.
I am in the test phase of both API, for downloading historic data and daily data.
the project is to download, once, the historic data of a stock, and on a daily basis the daily quotes, put them togheter and make them accessible to Tradestation.
everything ok, except tha date, that have different format in historic and daily data.
can you please give me some advice on how to get them readable without problems by TS?
the best would be to maintain the format of the date in the historical download, and adapt the dayly one.
any suggestion?
thank in advance.
sandro
Kelly,
Is there a way to fetch “Revenue Estimates” data from http://finance.yahoo.com/q/ae?s=IBM+Analyst+Estimates ?
Thanks,
Shahid
The Yahoo finance quotes are great — but the m4 function brings in a value for a moving average based on 200 calendar days. If you use the technical indicators dropdown box and show the 200 day MA on a stock chart, it proves a value based on 200 trading days (not 200 calendar days). What is the function in need to use to bring into my spreadsheet the 200 trading days information?
Thanks for the help!
Is there a tag to retrieve the Growth Estimates for next 5 years. This is under Analyst Estimates component of the stock quote.
http://finance.yahoo.com/q/ae?s=MSFT+Analyst+Estimates
Thanks
Has anybody noticed a problem with ask/bid prices. I’m sure my app was showing them all a week ago and now it seems very few (90% of them are now N/A). This is unfortunate as of course my spreads are all 0 now as well. I tried the other variants but they give same result of N/A. (I think I’ve at least worked out AIM stocks don’t seem to have them recorded).
Any of you gurus knowledge on this front would be much appreciated.
Here’s a few examples of stocks with issue: LAD.L ABB.L MONY.L DIA.L PRV.L
Test link showing they are N/A: http://finance.yahoo.com/d/quotes.csv?s=DIA.L&f=nsab
Thankyou…
Ah, All the Ask/Bids are populated now, so the issue must have been resolved. My query (above) is now redundant and can be ignored. Thanks…
Hi,
When downloading data of multiple stocks in a row, so using multiple lines like this:
http://finance.yahoo.com/d/quotes.csv?s=AAPL&f=nsab
http://finance.yahoo.com/d/quotes.csv?s=CAT&f=nsab
… etc.
What is the minimum time to leave between each line? Has anybody experienced his IP being locked by Yahoo because of too frequent calls?
I want to download data of hundreds of stocks once or twice a day, but I’m afraid that Yahoo will lock me out.
And IF I am locked out, is that only temporarily?
Thanks already for any input.
Kind regards
Ray
There is definitely a daily limit although I am unsure exactly what it is. Keep in mind you can ask for multiple stocks per request instead of doing 1 request per stock.
Thanks, Kelly.
If I run into trouble I will try the multiple stock download.
The Yahoo YQL interface has some well-described limits:
http://developer.yahoo.com/yql/guide/usage_info_limits.html
These seem very reasonable. But for the API interface as Kelly described above, I can not find any published limits. From what I read on some (older) forums, these limits seem to vary in time. Yahoo probably changes them on the fly as server loads vary.
I am writing some software to download stock data for multiple stocks, so I can start experimenting in a few days.
PS. Kelly, I forgot to say thanks for publishing this useful information. So thank you! :-)
Hi Ray, I have written a Share monitoring app (for Windows) using interface above and haven’t yet experienced any blocking of data since I started around 8 months ago. I download quite a lot of Share data and also historical chart data. Yahoo have been good to me so far fingers crossed.
Jarrod, that’s reassuring to hear. Thanks!!
Hy , i was wondering how cand i retrieve historical data between a start date and an end date ? Tnks
From URL – http://ichart.finance.yahoo.com
a = From Month
b = From Day
c = From Year
d = To Month
e = To Day
f = To Year
Eg: 6 months data for Taylor Wimpey:
http://ichart.finance.yahoo.com/table.csv?s=TW.L&a=03&b=07&c=2013&d=09&e=04&f=2013
I have a problem in order to obtain data from exchange .MC (Madrid)
For example:
http://finance.yahoo.com/d/quotes.csv?s=SAN.MC&f=sp
p: Previous Close
s: Symbol
Ii returns a file (.csv) with this line: “SAN.MC, N/A” where SAN.MC is the symbol and N/A is Previous Close.
This problem is the same with other symbols from exchange with suffix .MC
In this link
http://finance.yahoo.com/q?s=SAN.MC
it exists Previous Close !!!!!
Why does this exchange .MC not work when download csv file?
I understand that ALL stock quotes from the spanish exchange are not available.
my feeling is that spanish quotes are available on payment, so Yahoo cannot make them available free of charge.
if you get the historical prices, no problem at all.
I am not sure to have solved your problem, but it is the same problem I faced some time ago.
Sandro
I guess you tried with no prefix? eg: SAN
It seems to work there but not much info is returned.
Sorry, I meant suffix :-)
Is it possible to get detailed options quotas from yahoo to a CSV? Has anyone tried it? If so could you give me some directions?
Maciek
Hi Maciek.
I was going to let someone else answer you as I was unsure about your question.
What do you mean by ‘detailed options quotas ‘?
Can you give an example?
Thank you very much for your response! I’m extremely sorry for this form… I’m working on CRR valuation and variations. I’d like to use all US options, and after expiration date check effectiveness of my valuation. In order to do so I need to set up a database with options quotas over time, underlying assets, and risk free interest. As I would like to make it as fast as possible daily importing all quotas is necessary, and parsing each site would be too long. Due to universities’ limits I cannot access pay-per download data. Importing selected options (name, strike, price, vol) to a CSV would be perfect. Do you maybe know how to modify parameters in this code to access options quotas?
Hi,
Is there a way to retrieve the earning date? I don’t see the earning date on the API list.
Thanks.
Hi, just for those asking about limits before…
I’ve just discovered yahoo will only allow data for 200 stocks max in any 1 call (sorry if already mentioned). If you have more, you can do it in chunks of 200 at a time.
PS. Ray, I just re-read your post where you said you had hundreds of stocks and were getting them 1 at a time.
If I were you I wouldn’t call API once for each stock as I guess you may have a greater chance of getting on yahoo’s nerves. Instead call the API once with a number of stocks e.g.:
http://finance.yahoo.com/d/quotes.csv?s=AAPL+CAT+GOOG+BLAH+BLAH2+ETC&f=nsab
Apart from that it would speed up your code immensly, as you’ll only be making 1 internet request.
Rgds…
When I download stock dividend data, there appear to be some errors as the dividend data does not match the Yahoo Finance page for the stock or current dividend information. Can someone explain?
My posts are not published here anymore .. Why ..?
Kind regards
Ray
Hi Mark, can you give an example stock symbol. I have looked at a few shares and the yahoo finance page seems to match. If we had an example we could maybe look into your issue better.
Carissa, do you really mean ‘earning date’. There isn’t a earning date to my understanding, only earnings per share, dividend, dividend yield, divi/exdivi dates as described above in the API?
Maciek, you blew my mind and I don’t understand your query, sorry. I’m sure there are people on here tho that totally get what you mean and can help you.
Rgds…
Carissa,
You can get the next earnings date from FinViz:
http://finviz.com/quote.ashx?t=aapl
Parsing the page code, you should be able to extract the earnings date (and much more).
For example, in the page code, look for:
>Earnings
Right after it, you find the next earnings date.
Kind regards
Ray
Sorry Carissa, I was dead wrong re your question (thanks Ray for correcting me).
Interestingly, I just saw on this site the info you may be after (could be wrong again tho lol) using the YQL API.
http://www.jarloo.com/get-near-real-time-stock-data-from-yahoo-finance/
Rgds…
If I just want to display the latest price and change, and use historical info to create a chart for the company website, is this OK under Yahoo’s TOS?
Thanks, Alex
Whenever i try to fetch .csv file for NSE or BSE stock list i’m NOT getting (retrieving any values- displayed as “N/A”), or most of the times i’m getting ‘Missing Format Variable.’
Do i need to pass any arguments for NSE or BSE stocks . apart from NS or BO – example Infy.BO Thanks, BS
How to download quotes indices of the LSE?
Two other stock exchanges you can add to your nice final table! Thanks ;)
Belgium Brussels Stocks .BR
Portugal Lisbon Stocks .LS
Great, I’ve added them to the list. Thanks!
Happy to help ;)
In the table you added “.LS” instead of “.BR” for Brussel stocks.
Copy and paste is both a blessing and curse. It’s fixed, thanks again for pointing that out.
Nice article, How do I get data for a certain exchange only? For example, I need a csv with all data for the BATS exchange. Is there a way to specify this?
Thanks.
Can you please let us know if there a way to get Beta information for a stock?
While Yahoo provides Beta on there site I haven’t seen a way to easily get it.
How can i get gold rates from yahoo finance?
How can i get gold price data from yahoo finance?
Excellent article. Very informative, especially the part on non-US exchanges.
The links in “Stuff you might like” are also great
Thanks a lot Kelly !!
Hi, am i the only one for whom the api is not working? I keep getting 404 errors for links likehttp://finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT
http://download.finance.yahoo.com/d/quotes.csv?s=AAPL+GOOG+MSFT
can you try?
it should work.
ciao
Sandro
Pavel, In your example, you haven’t specified what data you want returned ie. the format.
Try appending &f=nab to the end of your query which would in this example give the name,ask and bid price, as described at start of the article.
Is there anyway to get enterprise value into excel using this?
I’ve done similar projects to send data to excel in many large companies. The best way to do it is using An RTD server. Google excel rtd server and you should find plenty of examples.
I’ve searched a bit for how to find out the currency, here it is:
c4 = currency
Alex
Hello,
I’m very impressed by this code, thanks a lot :)
I’ve 2 questions :
1) how can I get the figures of a market ? eg CAC40, whose symbol is PX1.
When I use the code below, I get no results :(
csvData = web.DownloadString(“http://finance.yahoo.com/d/quotes.csv?s=PX1+&f=snhg”);
2) is it possible to get the ISIN code ? I can get the symbol but not the ISIN so far
Thanks for reading this =)
My bad, I wasn’t using the good symbol for CAC40.. It was in fact ^FCHI !
But question 2 is still standing : how can I get the ISIN code?
Greate article! I’ve learned a lot.
Do you know how to get history of earnings or EPS?
a question on the chart api…
i am getting data like
symbol : timestamp : vol : high : low : open : close
dbk.de;2014-04-09 09:00:50+02;81.400;32,2150;32,2150;32,2150;32,2150
dbk.de;2014-04-09 09:01:15+02;4.600;32,2500;32,2500;32,2500;32,2500
dbk.de;2014-04-09 09:02:37+02;34.300;32,2100;32,2550;32,2550;32,2100
dbk.de;2014-04-09 09:03:11+02;2.900;32,2200;32,2200;32,2200;32,2200
dbk.de;2014-04-09 09:04:41+02;18.900;32,2200;32,2250;32,2200;32,2250
dbk.de;2014-04-09 09:05:40+02;14.500;32,2400;32,2700;32,2400;32,2700
dbk.de;2014-04-09 09:06:24+02;6.600;32,2300;32,2350;32,2350;32,2300
dbk.de;2014-04-09 09:07:57+02;12.300;32,1350;32,2000;32,2000;32,1350
dbk.de;2014-04-09 09:08:14+02;500;32,1200;32,1200;32,1200;32,1200
it is parsed from xml… but i realized, that the volumes have no plus or minus or something similar which i would expect…
nor in the returned xml
So hwo would I calculate the volume… a simple minus wouldnt work, see second data row…
Using the info provided here and a little bit of ruby scripting (with text-table gem installed), here is something folks can use to get a neat table for each of the stock of their interest.
https://github.com/csmunuku/myscripts/blob/master/ruby/stocks_csv_table.rb
Anyone else having problems with exchanges? I have been getting crude oil prices using
http://finance.yahoo.com/d/quotes.csv?s=CLK14.NYM&f=nab+l1
Was working great – now all of a sudden, I just get N/A and zeroes…
Every time I go to download a spreadsheet in .csv form, the Microsoft Office default appears. I want to use Microsoft Works instead. How do I change the default from Office to Works?
Anybody know how to download historic, or at least last 4 qtrs of EPS via Yahoo URL? Thanks!
Great info for stocks data. How about options data? I want to download a CSV of the option chain.
When using s1 shares owned I’m getting additional columns. Not sure what going on here all others work fine.
Roger
I found that you can get the full company name (not cut off after 17 or so characters) through the Yahoo! Finance charting API:http://chartapi.finance.yahoo.com/instrument/1.0/msft/chartdata;type=quote;range=1d/csv/
Slightly different format, but dead easy to parse.
When I run f6 = float shares only I get 3 columns when I expect only one. What am I doing wrong?
Question:
Would it be possible to remove the comma’s in Shares Outstanding, Float Shares and Last Trade Size? Other numerical fields are this way, like average daily volume for example.
Regards
roger
Hi – I am wondering it I can get qoutes from Philippine Stock Exchange Index (PSEI). I can get just the summary here http://finance.yahoo.com/q?s=PSEI.PS. I was hoping to see stock qoute from a particluar company like ‘BDO’,’BPI’ and so on..
Do you know how can I get it?
Thanks!
Just tried to get ex-dividend date for a stock. Using the following URL
http://download.finance.yahoo.com/d/quotes.csv?s=avgo&f=sqr1
I get “AVGO”,”Mar 18″,”Jun 30″
but the ex-dividend date is wrong; it should be 6/17/2014, I believe.
Is yahoo wrong, or is “q” the wrong code for latest ex-dividend date?
Concerning poster Kathleen
April 14, 2014 at 4:29 pm
I am having the same problem with stock futures, etc no longer displaying properly.
Thanks for this great post! This is exactly what I was looking for since ages…..
I am just wondering why this won’t work for India Exchanges like BSE and NSE even when I use .BO and .NS as suffix. It just throws csv with N/A values.
e.g.
finance.yahoo.com/d/quotes.csv?s=RELIANCE.NS&f=nab returns
RELIANCE.NS N/A N/A
Highly appreciate your response.
Thanks again for this great Post!!!!!