雅虎突然今天终止了其财务下载API吗?

时间:2017-11-01 22:39:27

标签: api yahoo-finance

几个月来,我一直在使用这样的网址,来自perl:

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

今天,11/1/17,它突然返回999错误。

这是一个小问题,还是雅虎终止了这项服务?

即使我将URL直接输入浏览器,我也会收到错误,例如:

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

因此它似乎不是一个'碎屑'问题。

注意:这不是过去已经回答过的问题! 它昨天正在工作。它发生在本月的第一天是可疑的。

5 个答案:

答案 0 :(得分:16)

Yahoo confirmed他们终止了服务:

  

我们注意到此服务的使用违反了雅虎服务条款。因此,该服务正在停止。有关所有未来市场和股票数据研究,请参阅finance.yahoo.com。

答案 1 :(得分:15)

正如其他答案及其他地方(例如currency helper of yahoo - Sorry, Unable to process request at this time -- error 999)所述,雅虎确实已经停止了Yahoo Finance API的运营。但是,作为一种变通方法,您可以通过向https://finance.yahoo.com/quote/SYMBOL(例如https://finance.yahoo.com/quote/MSFT)执行HTTPS GET请求,以JSON格式访问给定的股票代码的大量财务信息。如果您对上述网址发出GET请求,您会看到财务数据包含在JSON格式的响应中。以下python脚本显示了如何解析您可能感兴趣的单个值:

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=resp.text.encode('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

脚本的输出应如下所示:

Symbol: MSFT
Name: Microsoft Corporation
Price: 84.14
Change: 0.08999634
Shares Outstanding: 7714590208
Market Cap: 649105637376
Trailing PE: 31.04797
Earnings Per Share: 2.71
Forward Annual Dividend Rate: 1.68
Forward_annual_dividend_yield: 0.02

答案 2 :(得分:6)

In [78]: a Out[78]: array([[1, 2, 3], [2, 3, 4], [5, 6, 7], [1, 2, 3], [1, 2, 3], [2, 3, 4]]) In [79]: classify_rows(a) Out[79]: [array([0, 3, 4]), array([1, 5]), array([2])] In [80]: classify_rows_list(a) Out[80]: [[0, 3, 4], [1, 5], [2]] 来电会抛出此错误:否“访问控制 - 允许 - 来源'标头出现在请求的资源上。起源' http://www.microplan.at/sar'因此不允许访问。

答案 3 :(得分:5)

还有一种方法可以通过查询finance.yahoo.com页面使用的某些API来获取此数据。不确定雅虎是否会像以前的API那样长期支持它(希望他们会这样做)。

我将https://github.com/pstadler/ticker.sh使用的方法改编成以下python hack,它从命令行获取符号列表并将一些变量输出为csv:

SELECT A.Id AS a_id, A.Time AS a_time, B.Id AS b_id, B.Time AS b_time 
FROM A
FULL OUTER JOIN B ON A.Time = B.Time

-- This works:
-- SELECT A.id, A.time, B.id, B.time
-- FROM A
-- FULL OUTER JOIN B ON A.id = B.id

示例运行:

#!/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]))

答案 4 :(得分:0)

我使用雅虎财经的Python程序最近停止了正常工作,但它没有返回该错误,它只是用0代替了股票价格。我最初在调试时看到了这个,然后,当我去那些股票的雅虎财务URL时,我确认了错误。由于实际数据搞砸了,我不认为已经提出的解决方法可以解决我的问题。这可能与雅虎停止其API有关吗?我无法理解什么可以解释这一点。

示例: