Using the Yahoo Finance API for CSV
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 | i: 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.
Download Code
Here is a quick example of how you can use the free Yahoo Finance API in your C# code.
Application Entry Point (main)
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
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 Exchange 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 |
Posted: February 26, 2012 10:37
sebastian
Posted: March 5, 2012 21:19
admin
Posted: March 23, 2012 22:49
lalas
Posted: March 24, 2012 05:48
admin
Posted: March 24, 2012 10:18
lalas
Posted: June 26, 2012 06:43
Uri G
Posted: September 15, 2015 08:48
jean charles
Posted: September 21, 2015 11:10
Dave S.
Posted: August 13, 2016 07:24
Jim N.
Posted: July 10, 2012 10:47
Tom Peirce
Posted: June 12, 2013 09:28
Kelly Elias
Posted: July 17, 2012 11:17
Hugh Brown
Posted: July 20, 2012 20:02
kevin
Posted: September 27, 2012 05:04
DARSH
Posted: September 27, 2012 07:24
admin
Posted: October 22, 2012 12:49
Thomas
Posted: October 22, 2012 13:17
admin
Posted: November 6, 2012 19:46
Sam
Posted: November 7, 2012 07:48
admin
Posted: November 6, 2012 19:49
Sam
Posted: November 12, 2012 09:02
KEVIN PARK
Posted: September 15, 2015 08:50
jean charles
Posted: January 26, 2013 23:32
graemeb
Posted: February 3, 2013 20:01
Charles
Posted: February 12, 2013 08:31
Sylvain
Posted: February 12, 2013 17:35
Yared
Posted: February 12, 2013 18:10
Kelly Elias
Posted: February 13, 2013 08:26
Yared
Posted: February 18, 2013 17:10
Joe
Posted: February 20, 2013 10:11
sajjad
Posted: March 8, 2013 07:48
Fabvon
Posted: March 8, 2013 08:36
Kelly Elias
Posted: April 5, 2013 01:40
rajkumar
Posted: April 25, 2013 04:51
ehsan
Posted: April 25, 2013 07:48
Kelly Elias
Posted: May 2, 2013 04:07
Alijohn
Posted: May 2, 2013 09:39
Kelly Elias
Posted: May 4, 2013 16:27
JefB
Posted: December 7, 2015 07:15
Pop
Posted: May 6, 2013 14:41
Ed
Posted: May 24, 2013 23:18
Anthony Wilson
Posted: June 2, 2013 09:48
joku
Posted: June 6, 2013 06:12
Shivaji
Posted: June 18, 2013 09:47
David
Posted: July 11, 2013 06:40
sandro giangrandi
Posted: July 24, 2013 04:00
Shahid Maqsood
Posted: August 21, 2013 08:01
Bill
Posted: August 30, 2013 11:58
Jonathan
Posted: September 5, 2013 11:04
Jarrod Elmes
Posted: September 24, 2013 06:26
Jarrod Elmes
Posted: October 2, 2013 05:47
Ray Johnson
Posted: October 2, 2013 07:44
Kelly Elias
Posted: October 2, 2013 08:12
Ray Johnson
Posted: October 3, 2013 01:04
Ray Johnson
Posted: October 3, 2013 10:04
Jarrod Elmes
Posted: October 3, 2013 12:03
Ray Johnson
Posted: October 4, 2013 04:20
Daia Alexandru
Posted: October 4, 2013 08:11
Jarrod Elmes
Posted: October 7, 2013 02:45
ERROSELL
Posted: October 7, 2013 07:03
sandro giangrandi
Posted: October 7, 2013 07:22
Jarrod Elmes
Posted: October 7, 2013 07:23
Jarrod Elmes
Posted: October 11, 2013 11:51
Maciek
Posted: October 14, 2013 17:45
Jarrod Elmes
Posted: October 15, 2013 06:58
Maciek
Posted: October 20, 2013 11:55
Carissa
Posted: October 23, 2013 14:43
Jarrod Elmes
Posted: October 23, 2013 18:03
Mark
Posted: October 24, 2013 02:22
Ray J.
Posted: October 24, 2013 16:23
Jarrod Elmes
Posted: October 25, 2013 00:57
Ray J
Posted: October 25, 2013 05:58
Jarrod Elmes
Posted: November 1, 2013 07:29
Alex
Posted: November 25, 2013 06:00
balaji
Posted: November 25, 2013 08:22
Marek
Posted: December 25, 2013 21:52
Jean
Posted: December 29, 2013 14:35
Kelly Elias
Posted: December 30, 2013 01:10
Jean
Posted: December 30, 2013 08:58
Kelly Elias
Posted: December 30, 2013 15:27
Saurabh
Posted: December 30, 2013 21:01
hari
Posted: December 31, 2013 00:19
Kelly Elias
Posted: January 27, 2014 04:15
sneha
Posted: February 9, 2014 13:06
sandro giangrandi
Posted: January 27, 2014 04:16
sneha
Posted: January 28, 2014 06:50
Hari
Posted: February 7, 2014 04:07
Pavel
Posted: February 9, 2014 15:05
Jarrod
Posted: February 21, 2014 13:43
Doc
Posted: February 21, 2014 15:21
Kelly Elias
Posted: March 3, 2014 14:58
Alex
Posted: March 13, 2014 09:00
Gato
Posted: March 13, 2014 09:46
Gato
Posted: April 7, 2014 04:22
kii
Posted: April 9, 2014 16:21
nuttijay
Posted: April 11, 2014 06:19
Chandra Munukutla
Posted: April 14, 2014 16:29
Kathleen
Posted: April 25, 2014 14:45
Vinnie Russo
Posted: May 1, 2014 08:25
Pete
Posted: May 7, 2014 23:28
Jerry
Posted: May 18, 2014 20:40
Roger dailey
Posted: May 20, 2014 07:15
Jakob
Posted: May 25, 2014 06:18
Roger dailey
Posted: May 26, 2014 08:25
Roger dailey
Posted: June 11, 2014 22:21
Dudz Artiaga
Posted: June 13, 2014 20:41
ab
Posted: June 24, 2014 15:20
xzone0
Posted: July 23, 2014 22:23
Deepak
Posted: March 30, 2016 01:06
Pravin Patel
Posted: September 4, 2014 19:23
Kimahri
Posted: September 6, 2014 08:39
Senthil
Posted: September 11, 2014 09:42
Chidambaram
Posted: September 18, 2014 18:24
Kelly Elias
Posted: October 15, 2014 04:05
DJunqueira
Posted: October 21, 2014 06:24
Bhaskar Rabha
Posted: October 29, 2014 13:18
Ray
Posted: October 31, 2014 09:14
Bans
Posted: November 15, 2014 06:20
Hugh
Posted: November 17, 2014 17:37
Nick
Posted: November 21, 2014 09:17
Jake
Posted: November 21, 2014 09:30
Dave S.
Posted: November 21, 2014 09:42
Dave S.
Posted: November 21, 2014 10:19
Dave S.
Posted: November 21, 2014 10:32
Jake
Posted: December 10, 2014 18:13
Glenn
Posted: December 15, 2014 11:33
Nick
Posted: December 24, 2014 13:18
GERRY
Posted: March 26, 2015 14:52
Dave S.
Posted: March 26, 2015 14:57
Gerry
Posted: January 5, 2015 08:44
Brian
Posted: March 26, 2015 13:00
Gerry
Posted: January 7, 2015 08:34
Chris
Posted: January 21, 2015 14:19
Gary
Posted: February 17, 2015 23:34
Daniel
Posted: February 23, 2015 14:07
Peter Watling
Posted: February 28, 2015 19:32
Tom
Posted: March 16, 2015 11:07
John
Posted: March 30, 2015 12:32
Tim
Posted: March 30, 2015 23:10
Dave S.
Posted: March 31, 2015 13:49
Dave S.
Posted: April 1, 2015 14:12
Petr V.
Posted: April 16, 2015 04:44
Captain Jim
Posted: April 27, 2015 11:38
Liam
Posted: April 29, 2015 22:41
CHO
Posted: April 30, 2015 00:22
Dave S.
Posted: April 30, 2015 00:33
Christian
Posted: May 1, 2015 11:28
Dave S.
Posted: May 3, 2015 00:54
Andre Gotlieb
Posted: May 3, 2015 01:53
Andre Gotlieb
Posted: May 5, 2015 22:27
Kelly Elias
Posted: July 25, 2015 15:18
Jon Koehmstedt
Posted: July 26, 2015 22:08
Dave S.
Posted: May 20, 2015 02:55
john constable
Posted: July 6, 2015 07:26
Aaeda
Posted: July 9, 2015 22:44
Dave S.
Posted: June 11, 2015 05:10
Abner Zayd
Posted: August 27, 2015 09:44
Joaquin Garcia
Posted: November 15, 2015 08:09
Ray
Posted: December 6, 2015 14:30
Jean
Posted: December 6, 2015 15:45
Dave S.
Posted: December 10, 2015 23:09
Jean
Posted: December 20, 2015 11:19
Doug
Posted: January 27, 2016 13:56
Ricky
Posted: January 27, 2016 18:17
Dave S.
Posted: January 29, 2016 13:14
Ricky Singh
Posted: February 2, 2016 08:57
Victor M Garcia Sanabria
Posted: February 6, 2016 07:37
Rajbir Singh
Posted: February 15, 2016 21:22
Kelly Elias
Posted: February 19, 2016 16:46
NN
Posted: February 29, 2016 11:24
Max
Posted: February 29, 2016 22:38
Dave
Posted: March 1, 2016 13:16
Max
Posted: March 1, 2016 15:42
Dave
Posted: March 1, 2016 15:48
Dave
Posted: April 4, 2016 03:49
quangnd
Posted: April 7, 2016 01:48
AlexC
Posted: April 22, 2016 03:15
Xman
Posted: April 25, 2016 01:56
David
Posted: May 5, 2016 08:48
cielo
Posted: May 5, 2016 14:17
Dave
Posted: May 10, 2016 14:06
Fredrik Roaldset
Posted: May 12, 2016 15:58
TomG
Posted: May 13, 2016 15:06
JLP
Posted: May 29, 2016 07:25
Henrik
Posted: June 8, 2016 09:11
Kelly Elias
Posted: June 3, 2016 09:15
Bondi_Dan
Posted: June 3, 2016 09:26
Bondi_Dan
Posted: June 3, 2016 10:18
Bondi_Dan
Posted: June 8, 2016 09:23
Dave
Posted: June 7, 2016 10:09
Katherine
Posted: August 5, 2016 01:36
Koen
Posted: June 18, 2016 06:13
Hubert
Posted: June 21, 2016 19:33
Kelly Elias
Posted: June 21, 2016 16:35
paul gureghian
Posted: June 21, 2016 19:32
Kelly Elias
Posted: July 7, 2016 16:30
Steve Liu
Posted: July 10, 2016 18:08
Jalal
Posted: July 19, 2016 21:55
dw85745
Posted: July 22, 2016 07:34
Ray
Posted: July 22, 2016 08:43
Dave S.
Posted: August 10, 2016 18:32
Kelly Elias
Posted: July 28, 2016 04:22
john constable
Posted: August 11, 2016 07:14
Fauzul
Posted: August 11, 2016 21:17
Kelly Elias
Posted: August 30, 2016 12:27
Andy Fisher