问题
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 yahoo-finance.
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.
回答1:
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.
回答2:
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=
回答3:
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/
回答4:
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:
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}");
}
回答6:
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.
回答7:
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 ());
回答8:
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
回答9:
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
来源:https://stackoverflow.com/questions/38355075/has-yahoo-finance-web-service-disappeared-api-changed-down-temporarily