39

For quite some time I've been using the following REST API to query Yahoo finance for current prices. It is documented in several Stack Overflow posts, e.g. Yahoo finance webservice and elsewhere in .

http://finance.yahoo.com/webservice/v1/symbols/$SYMBOLS/quote?format=json

where $SYMBOLS is a comma-delimited list of stock or index symbols.

Yesterday the query stopped working, returning only a "Moved Temporarily. Redirecting to ..." message.

Is this web service now closed? Has it been replaced by YQL or another API? Queries for a table of historic prices to "ichart" still work. E.g.,

http://ichart.finance.yahoo.com/table.csv?d=2&e=3&f=2016&g=d&a=0&b=1&c=2011&ignore=.csv&s=$SYMBOL

Thanks.

Community
  • 1
  • 1
K Markey
  • 595
  • 1
  • 6
  • 10
  • Robyn Tippins (Community Manager, YDN): "It appears some have reverse engineered an API that they use to pull Finance data, but they are breaking our Terms of Service (no redistribution of Finance data) in doing this so I would encourage you to avoid using these webservices." Official APIs are: https://developer.yahoo.com/finance/ "There's no problem with your downloading the data, assuming you stay below rate limits, you just can't redistribute it". – Christophe Roussy Nov 29 '16 at 14:16
  • Check this other [API source data](https://stackoverflow.com/questions/44030983/yahoo-finance-url-not-working/44495145#44495145) – user2471214 Jun 12 '17 at 08:55
  • I recommend using Alpha Vantage in the post-Yahoo era. They have a free stock data API and it works really well. I have written a blog post on it: http://www.the-data-wrangler.com/acquiring-stock-market-data-from-alpha-vantage/ – Ashley Davis Oct 14 '17 at 00:00
  • Note that Alpha Vantage appears to lack NASDAQ index data. – CodeLurker Feb 20 '19 at 16:03
  • https://stackoverflow.com/questions/28822780/fetching-1-minute-bars-from-yahoo-finance/36163585#36163585 – RasikhJ Dec 18 '19 at 12:03
  • https://stackoverflow.com/questions/28822780/fetching-1-minute-bars-from-yahoo-finance/36163585#36163585 – RasikhJ Dec 18 '19 at 12:05

10 Answers10

27

I was facing a similar issue from last 2-3 days. The url works on the smartphone, where on the desktop it gives "Not a valid parameter" error and HTTP Code 406.

This can be resolved by adding user agent as "Mozilla/5.0 (Linux; Android 6.0.1; MotoG3 Build/MPI24.107-55) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.81 Mobile Safari/537.36" while invoking the get request.

For example, if you are downloading from curl in php use as follows:

curl_setopt($session,CURLOPT_USERAGENT,"Mozilla/5.0 (Linux; Android 6.0.1; MotoG3 Build/MPI24.107-55) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.81 Mobile Safari/537.36");

I hope this will resolve the issue.

Hemant Prasad
  • 279
  • 2
  • 7
  • Please, help me to understand a bit more the problem, I'm issuing the network request from an app (with Retrofit) and it is giving me 406 NOT ACCEPTABLE answer. But when I make the same network request through Chrome in phone is returning correct results(as you said). Why is from the app failing(it is inside a phone!) – Carlos Hernández Gil Jul 18 '16 at 19:12
  • Hi Carlos, the web server is recognizing the request is from phone or desktop through USERAGENT header info in the request payload. So change the USERAGENT header info to phone as suggested above will not fail from the APP while sending the request. – Hemant Prasad Jul 19 '16 at 02:02
  • Thanks for the clarification Hemant, effectively it works, I hadn't included my headers correctly in the network request. Your solution works 100%. You save me months of work with a single line, not exaggerating. – Carlos Hernández Gil Jul 19 '16 at 17:05
  • Its working as per Hemant's solution.If you are sending bypass=true parameter please remove that too. – Desert Rose Jul 21 '16 at 05:57
  • 1
    This is great but it's probably only a matter of time until Yahoo gets rid of this loophole :( – allenlin1992 Aug 01 '16 at 01:47
  • 5
    it appears that Yahoo has finally fixed this. The hack no longer works recently – mkto Apr 28 '17 at 22:13
7

Yes, it does seem like Yahoo! has discontinued the (private, mostly-undocumented) Yahoo Finance API that many have been relying on for years for currency data. We received some notifications about it over the past 24 hours. (edit: All responses seem to be returning "Not a valid parameter". I suppose there's a chance they may switch it back on, but they don't officially support that API anywhere as far as I can tell.)

I created Open Exchange Rates about five years ago, and our exchange rate API now supports a community of tens of thousands of developers - and their tens of millions of users - with accurate, up-to-date information.

Please feel welcome to check out our Forever Free service at https://openexchangerates.org.

Our API is in a simple, original JSON format, which has actually caught on as a standard method for displaying rates because it's so simple to work with (unlike the Yahoo API, which required you to parse the obscure nested objects to pull out the basic info you needed...)

If you need assistance porting from the deprecated Yahoo! API, we'll be happy to assist via email.

(I am the founder of Open Exchange Rates.)

  • 5
    Thanks for confirming my observations. Unfortunately, I don't (currently) need exchange rates, but when I do, I'll check out your service. Thanks. – K Markey Jul 14 '16 at 19:13
  • 5
    "Open Exchange Rates" seems to be not free. Or plz give us example for replacement of http://finance.yahoo.com/webservice/v1/symbols/$SYMBOLS/quote?format=json – l0pan Sep 26 '16 at 13:05
  • 4
    Not "Forever Free" – BLuEGoD Jan 06 '17 at 16:17
  • 4
    `Please feel welcome to check out our Forever Free service at https://openexchangerates.org.` Your service isn't free... – ahinkle Jan 11 '17 at 00:22
  • 1
    Our Free service is listed above our supported plans, and used by over 60,000 people at present. Signup here: https://openexchangerates.org/signup/free – William Joss Crowcroft Jan 12 '17 at 20:07
  • OP is asking for quotes not exchange rates. – João Nunes May 03 '17 at 20:11
6

Since the service is down, I use the following URL to query Yahoo data (for ACA.PA):

Link

The JSON result is different but I found the informations that interests me.

For more information , visit the page https://developer.yahoo.com/yql/

ssuperczynski
  • 3,190
  • 3
  • 44
  • 61
Dimitri MASSA
  • 303
  • 2
  • 9
6

I had the same issue. Here is the API URL to pull stock from YAHOO. Hope this helps.

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22YHOO%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
JetSet
  • 189
  • 1
  • 2
  • 10
4

Check out this excellent API Wrapper, available on NuGet: https://github.com/salmonthinlion/YahooFinanceApi

Get stock quotes

var quotes = await Yahoo.Symbol("AAPL", "GOOG").Tag(Tag.LastTradePriceOnly, Tag,ChangeAndPercentChange, Tag.DaysLow, Tag.DaysHigh).GetAsync();
var aapl = quotes["AAPL"];
var price = aapl[Tag.LastTradePriceOnly];

Get historical data for a stock

// You should be able to query data from various markets including US, HK, TW
var history = await Yahoo.GetHistoricalAsync("AAPL", new DateTime(2016, 1, 1), new DateTime(2016, 7, 1), Period.Daily);
foreach (var candle in history)
{
    Console.WriteLine($"DateTime: {candle.DateTime}, Open: {candle.Open}, High: {candle.High}, Low: {candle.Low}, Close: {candle.Close}, Volume: {candle.Volume}, AdjustedClose: {candle.AdjustedClose}");
}

Get dividend history for a stock

// You should be able to query data from various markets including US, HK, TW
var dividendHistory = await Yahoo.GetHistoricalDividendsAsync("AAPL", new DateTime(2016, 1, 1), new DateTime(2016, 7, 1));
foreach (var candle in dividendHistory)
{
    Console.WriteLine($"DateTime: {candle.DateTime}, Dividend: {candle.Dividend}");
}
Erwin Mayer
  • 18,076
  • 9
  • 88
  • 126
4

I am the author of ValueViz on github.

Daily prices

You need to be familiar with RESTFUL services.

https://quantprice.herokuapp.com/api/v1.1/scoop/day?tickers=MSFT&date=2017-06-09

Historical prices

You have to provide a date range :

https://quantprice.herokuapp.com/api/v1.1/scoop/period?tickers=MSFT&begin=2012-02-19&end=2012-02-20

If you don't provide begin or end it will use the earliest or current date:

https://quantprice.herokuapp.com/api/v1.1/scoop/period?tickers=MSFT&begin=2012-02-19

Multiple tickers

You can just comma separate tickers:

https://quantprice.herokuapp.com/api/v1.1/scoop/period?tickers=IBM,MSFT&begin=2012-02-19

Rate limit

All requests are rate limited to 10 requests per hour. If you want to register for a full access API send me DM on twitter. You will receive an API key to add to the URL.

We are setting up a paypal account for paid subscription without rates.

List of tickers available

https://github.com/robomotic/valueviz/blob/master/scoop_tickers.csv

I am working also to provide fundamental data and company data from EDGAR. Cheers.

user2471214
  • 729
  • 9
  • 17
3

It is redirecting to the same page, but adding the parameter "bypass=true", which gives an error.

EDIT: The answer given by https://stackoverflow.com/users/6593038/hemant-prasad is working for me. When changing the user agent to a mobile device, the API works fine, and doesn't redirect so far.

This is the code I'm using in Java (it's for the XML version, but it can be use for JSON as well):

URL url = new URL ("https://finance.yahoo.com/webservice/v1/symbols/" + stocks + "/quote");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection ();
urlc.setRequestProperty ("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; MotoE2(4G-LTE) Build/MPI24.65-39) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.81 Mobile Safari/537.36");
Document xml = DocumentBuilderFactory.newInstance ().newDocumentBuilder ().parse (urlc.getInputStream ());
Community
  • 1
  • 1
  • At least from Safari on OS X, it is adding the bypass and complaining of an invalid parameter. On to another (private, mostly undocumented) API. – K Markey Jul 14 '16 at 19:12
  • Yes, you are right. I tried with incognito mode in Chrome (Linux) and it triggered the redirect. I suppose it didn't happen before because of the browser's cache. –  Jul 14 '16 at 20:52
  • @JoãoNunes No, the API has been shut down. You should look for other options. –  Nov 17 '17 at 01:00
3

I found a way to use the csv API.

link

where you need to write the symbol, the parameters and columns.

Use this website to find the parameters needed: http://www.jarloo.com/yahoo_finance/

example:

If you need to know the symbol's volume replace the string sl1d1t1c1ohgv with v

and replace the columns symbol%2Cprice%2Cdate%2Ctime%2Cchange%2Ccol1%2Chigh%2Clow%2Cvolume with volume

The only issue is that data is kinda random and not real time like it was in webservice API

ssuperczynski
  • 3,190
  • 3
  • 44
  • 61
João Nunes
  • 3,751
  • 31
  • 32
0

The Python Yahoo Finance API seems to have a problem too. If you use it to look up, for example, Amazon stock prices it just shows the same two values over and over.

from yahoo_finance import Share import time f = open('/tmp/amazon/amzn.csv', 'w') while True:
    amzn=Share("AMZN")
    s = amzn.get_price() + "," + amzn.get_trade_datetime() + '\n'
    print (s)
    f.write (s)
    f.flush()
    time.sleep(5)
    del amzn
Walker Rowe
  • 953
  • 1
  • 12
  • 24
-1

I think this could help, I have created a web service for all Nasdaq/Nyse tickers, you can test this REST API and check if it suits your need. Also you can visit this website below for the use cases example.

Rest API endpoint: https://rapidapi.com/moneygoddess888/api/nasdaq-stocks-dividend-history-live

Use Case Example: https://nasdaq-dividend-search-api.herokuapp.com

  • 1
    User is not asking your Implementation or what you have done. he is simple asking particular api is up or down or whatever reason for particular state ... if you have any update or link then please share that information. – Er. Amit Joshi May 30 '22 at 18:09
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 30 '22 at 18:10
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31892811) – Ravindu Jun 05 '22 at 07:52