34

For months I've been using a url like this, from perl:

http://finance.yahoo.com/d/quotes.csv?s=$s&f=ynl1 #returns yield, name, price;

Today, 11/1/17, it suddenly returns a 999 error.

Is this a glitch, or has Yahoo terminated the service?

I get the error even if I enter the URL directly into a browser as, eg:

http://finance.yahoo.com/d/quotes.csv?s=INTC&f=ynl1

so it doesn't seem to be a 'crumb' problem.

Note: This is NOT a question which has been answered in the past! It was working yesterday.That it happened on the first of the month is suspicious.

Mark Amery
  • 110,735
  • 57
  • 354
  • 402
user1067305
  • 2,561
  • 5
  • 22
  • 28
  • 5
    I'm voting to close this question as off-topic because this is not the Yahoo site status. We're not support for any third-party off site location or vendor. Contact that site directly to inquire about their status. This site is for programming related questions. – Rob Nov 02 '17 at 02:36
  • 3
    I am facing the same issue as well on my side, it was all good yesterday. Anyone have a working API code? – Dennis Nov 02 '17 at 02:40
  • 5
    Many people are having this problem, but congratulations - your site remains pure. – user1067305 Nov 02 '17 at 05:06
  • They change public type to private for some tables, but (server-side, without yahoo login, only with app key and app secret) auth api doesn't exist – Salavat Nov 02 '17 at 10:06
  • It seems like they know about the issue, and intended to fix it. https://forums.yahoo.net/t5/Known-issues-and-updates/Finance-download-error-999/m-p/387511#M13 – despecher Nov 02 '17 at 15:49
  • New message from Yahoo Admin "... the service is being discontinued..." https://forums.yahoo.net/t5/Known-issues-and-updates/Finance-download-errors/td-p/387511 – despecher Nov 02 '17 at 18:50
  • Someone already flagged/voted to close this as a "not coding related" vote. Maybe not "coding" but "coders". Code is nothing, people (coders) are something. Many probably don't know how to handle this. Some probably don't know what PHP errors or how to interpret them. – Funk Forty Niner Nov 04 '17 at 21:25
  • Addendum to my above comment. I know how to deal with code-related issues. That is the only control we/I have, we just can't control who runs the show. TBH, Stack wasn't my first stop in researching this issue, I was more after going for the "real" reason as to why Yahoo suddenly just "pulled the plug" as it were. Actually, [this is the first site](https://www.stockmarketeye.com/blog/quote-issues-due-to-changes-at-yahoo-finance/) I found/visited. – Funk Forty Niner Nov 04 '17 at 21:29
  • This is being discussed on [meta](https://meta.stackoverflow.com/q/358883/1415724). – Funk Forty Niner Nov 06 '17 at 02:03

5 Answers5

17

Yahoo confirmed that they terminated the service:

It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com .

Nissa
  • 4,589
  • 8
  • 27
  • 37
aleg
  • 179
  • 5
17

As noted in the other answers and elsewhere (e.g. https://stackoverflow.com/questions/47076404/currency-helper-of-yahoo-sorry-unable-to-process-request-at-this-time-erro/47096766#47096766), Yahoo has indeed ceased operation of the Yahoo Finance API. However, as a workaround, you can access a trove of financial information, in JSON format, for a given ticker symbol, by doing a HTTPS GET request to: https://finance.yahoo.com/quote/SYMBOL (e.g. https://finance.yahoo.com/quote/MSFT). If you do a GET request to the above URL, you'll see that the financial data is contained within the response in JSON format. The following python3 script shows how you can parse individual values that you may be interested in:

import requests
import json

symbol='MSFT'
url='https://finance.yahoo.com/quote/' + symbol
resp = requests.get(url)

#parse the section from the html document containing the raw json data that we need
#you can write jsonstr to a file, then open the file in a web browser to browse the structure of the json data
r=str(resp.content, 'utf-8')
i1=0
i1=r.find('root.App.main', i1)
i1=r.find('{', i1)
i2=r.find("\n", i1)
i2=r.rfind(';', i1, i2)
jsonstr=r[i1:i2]      


#load the raw json data into a python data object
data = json.loads(jsonstr)

#pull the values that we are interested in 
name=data['context']['dispatcher']['stores']['QuoteSummaryStore']['price']['shortName']
price=data['context']['dispatcher']['stores']['QuoteSummaryStore']['price']['regularMarketPrice']['raw']
change=data['context']['dispatcher']['stores']['QuoteSummaryStore']['price']['regularMarketChange']['raw']
shares_outstanding=data['context']['dispatcher']['stores']['QuoteSummaryStore']['defaultKeyStatistics']['sharesOutstanding']['raw']
market_cap=data['context']['dispatcher']['stores']['QuoteSummaryStore']['summaryDetail']['marketCap']['raw']
trailing_pe=data['context']['dispatcher']['stores']['QuoteSummaryStore']['summaryDetail']['trailingPE']['raw']
earnings_per_share=data['context']['dispatcher']['stores']['QuoteSummaryStore']['defaultKeyStatistics']['trailingEps']['raw']
forward_annual_dividend_rate=data['context']['dispatcher']['stores']['QuoteSummaryStore']['summaryDetail']['dividendRate']['raw']
forward_annual_dividend_yield=data['context']['dispatcher']['stores']['QuoteSummaryStore']['summaryDetail']['dividendYield']['raw']

#print the values
print('Symbol:', symbol)
print('Name:', name)
print('Price:', price)
print('Change:', change)
print('Shares Outstanding:', shares_outstanding)
print('Market Cap:', market_cap)
print('Trailing PE:', trailing_pe)
print('Earnings Per Share:', earnings_per_share)
print('Forward Annual Dividend Rate:', forward_annual_dividend_rate)
print('Forward_annual_dividend_yield:', forward_annual_dividend_yield)
mti2935
  • 9,797
  • 3
  • 23
  • 28
  • Is there any javascript equivalence of this Python implementation? Thanks. – chaohuang Jul 07 '18 at 16:56
  • As of now, when I put `https://finance.yahoo.com/quote/MSFT` into a browser's address bar what comes back is not JSON, but a pretty formatted HTML page. – mbmast Mar 28 '20 at 22:53
  • 2
    @mbmast - It may be that the server is responding differently to the request from the browser, based on the headers that the browser is sending. I tested again just now using the python script above, and it produced the expected results. I've also updated the script for python3. – mti2935 Mar 28 '20 at 23:10
  • @mti2935 Right. I had forgotten about User Agent and things like that. – mbmast Mar 28 '20 at 23:14
  • @mbmast - Actually, if you point your browser to the URL (e.g. https://finance.yahoo.com/quote/MSFT), then view the source of the page, you'll see that the JSON is in there. – mti2935 Mar 29 '20 at 00:52
6

There is still a way to get this data by querying some APIs used by the finance.yahoo.com page. Not sure if Yahoo will be supporting it long term as the previous API was (hopefully they will).

I adapted the method used by https://github.com/pstadler/ticker.sh into the following python hack that takes a list of symbols from the command line and outputs some of the variables as a csv:

#!/usr/bin/env python

import sys
import time
import requests

if len(sys.argv) < 2:
    print("missing parameters: <symbol> ...")
    exit()

apiEndpoint = "https://query1.finance.yahoo.com/v7/finance/quote"
fields = [
    'symbol',
    'regularMarketVolume',
    'regularMarketPrice',
    'regularMarketDayHigh',
    'regularMarketDayLow',
    'regularMarketTime',
    'regularMarketChangePercent']
fields = ','.join(fields)
symbols = sys.argv[1:]
symbols = ','.join(symbols)
payload = {
    'lang': 'en-US',
    'region': 'US',
    'corsDomain': 'finance.yahoo.com',
    'fields': fields,
    'symbols': symbols}
r = requests.get(apiEndpoint, params=payload)
for i in r.json()['quoteResponse']['result']:
    if 'regularMarketPrice' in i:
        a = []
        a.append(i['symbol'])
        a.append(i['regularMarketPrice'])
        a.append(time.strftime(
            '%Y-%m-%d %H:%M:%S', time.localtime(i['regularMarketTime'])))
        a.append(i['regularMarketChangePercent'])
        a.append(i['regularMarketVolume'])
        a.append("{0:.2f} - {1:.2f}".format(
            i['regularMarketDayLow'], i['regularMarketDayHigh']))
        print(",".join([str(e) for e in a]))

Sample Run:

$ ./getquotePy.py AAPL GOOGL
AAPL,174.5342,2017-11-07 17:21:28,0.1630961,19905458,173.60 - 173.60
GOOGL,1048.6753,2017-11-07 17:21:22,0.5749836,840447,1043.00 - 1043.00
AlejandroVD
  • 991
  • 10
  • 17
6

var API = "https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL"; $.getJSON(API, function (json) {...});call throws this error: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.microplan.at/sar' is therefore not allowed access.

0

My Python program using Yahoo Finance has recently stopped working properly, but it didn't return that error, it just replaced stock prices with 0's. I initially saw this when I debugged and then, when I went to the yahoo finance URLS for those stocks, I confirmed the error. Since the actual data is messed up, I don't think the work-arounds that have been suggested would fix my problems. Is this likely related to yahoo discontinuing their API? I can't understand what could explain this.

Examples:

partyphysics
  • 163
  • 5