Has Yahoo finance web service disappeared? API changed? Down temporarily?
Asked Answered
S

9

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.

Safekeeping answered 13/7, 2016 at 14:51 Comment(6)
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: 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".Cogan
Check this other API source dataPenniepenniless
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: the-data-wrangler.com/…Alpestrine
Note that Alpha Vantage appears to lack NASDAQ index data.Craze
#28823280Clad
#28823280Clad
I
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.

Interferon answered 15/7, 2016 at 7:43 Comment(6)
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!)Extensometer
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.Interferon
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.Extensometer
Its working as per Hemant's solution.If you are sending bypass=true parameter please remove that too.Adviser
This is great but it's probably only a matter of time until Yahoo gets rid of this loophole :(Ridglee
it appears that Yahoo has finally fixed this. The hack no longer works recentlyGuacharo
M
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.)

Madalinemadalyn answered 13/7, 2016 at 17:9 Comment(6)
Thanks for confirming my observations. Unfortunately, I don't (currently) need exchange rates, but when I do, I'll check out your service. Thanks.Safekeeping
"Open Exchange Rates" seems to be not free. Or plz give us example for replacement of finance.yahoo.com/webservice/v1/symbols/$SYMBOLS/…Baer
Not "Forever Free"Swatow
Please feel welcome to check out our Forever Free service at https://openexchangerates.org. Your service isn't free...Aruwimi
Our Free service is listed above our supported plans, and used by over 60,000 people at present. Signup here: openexchangerates.org/signup/freeMadalinemadalyn
OP is asking for quotes not exchange rates.Dagny
O
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/

Overstate answered 26/7, 2016 at 12:54 Comment(0)
C
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=
Casady answered 4/4, 2017 at 16:36 Comment(3)
@james.garriss You can copy and paste that link above in a browser and it still returns data. You probably doing something wrong on your end.Casady
So it does. Perhaps the service was down on the day that I tried it.Shoulders
I get NULL in resultsFirmament
P
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}");
}
Penalty answered 2/5, 2017 at 15:31 Comment(0)
P
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.

Penniepenniless answered 12/6, 2017 at 8:59 Comment(0)
S
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 ());
Shelley answered 13/7, 2016 at 22:44 Comment(3)
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.Safekeeping
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.Shelley
@JoãoNunes No, the API has been shut down. You should look for other options.Shelley
K
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

Killdeer answered 29/4, 2017 at 12:49 Comment(0)
B
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
Bryology answered 22/6, 2017 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.