javascript 从 2017 年 9 月 6 日起,谷歌金融 api 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46090810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 06:27:13  来源:igfitidea点击:

google finance api not working from 6/september/2017

javascriptyahoo-financestockquotesgoogle-finance-apigoogle-javascript-api

提问by Ramaprasad Palanichamy

I was using google finance api to get the stock quotes and display the contents on my site. All of a sudden from 6/september/2017 this stopped working. The url i used to get the stock quotes is https://finance.google.com/finance/info?client=ig&q=SYMBOL&callback=?.

我正在使用谷歌金融 api 来获取股票报价并在我的网站上显示内容。从 2017 年 9 月 6 日起,这突然停止工作。我用来获取股票报价的网址https://finance.google.com/finance/info?client=ig&q=SYMBOL&callback=?。

Previously, i was using yahoo finance api and it was inconsistent. So, i switched over to google finance api.

之前我用的是雅虎财经的api,结果不一致。所以,我切换到谷歌金融 api。

Could you please help me on this?

你能帮我解决这个问题吗?

Thanks, Ram

谢谢,拉姆

采纳答案by Ramaprasad Palanichamy

In the end i started using yahoo finance. The data is not live, there is a 20 minutes delay. I thought it will be helpful to people who are facing issues like me.

最后我开始使用雅虎财经。数据不是实时的,有 20 分钟的延迟。我认为这对像我这样面临问题的人会有所帮助。

The yahoo api url is https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%3D%22MSFT%22&env=store://datatables.org/alltableswithkeys

雅虎 api 网址是https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%3D%22MSFT%22&env=store:// datatables.org/alltableswithkeys

This will return the stock data in xml format. You can parse the xml to get your desired fields.

这将以 xml 格式返回股票数据。您可以解析 xml 以获得所需的字段。

Thanks, Ram

谢谢,拉姆

回答by Gitesh

This url works. I think just the url changed from www.google.com to finance.google.com

这个网址有效。我认为只是网址从 www.google.com 更改为 Finance.google.com

https://finance.google.com/finance/getprices?q=ACC&x=NSE&p=15&i=300&f=d,c,o,h,l,v

https://finance.google.com/finance/getprices?q=ACC&x=NSE&p=15&i=300&f=d,c,o,h,l,v

回答by Shyamal Patel

We had a same issue & we found below alternative API provided by Microsoft Bing API for Stock Markets. Below API returns the stock data in JSON format.

我们遇到了同样的问题,我们在 Microsoft Bing API 为股票市场提供的替代 API 下方找到了。下面的 API 以 JSON 格式返回股票数据。

https://finance.services.appex.bing.com/Market.svc/ChartAndQuotes?symbols=139.1.500209.BOM&chartType=1d&isETF=false&iseod=False&lang=en-IN&isCS=false&isVol=true

https://finance.services.appex.bing.com/Market.svc/ChartAndQuotes?symbols=139.1.500209.BOM&chartType=1d&isETF=false&iseod=False&lang=en-IN&isCS=false&isVol=true

Thanks, Shyamal

谢谢,夏马尔

回答by Andrew

I had to switch to Google finance after using Yahoo finance for a long time after Verizon bought yahoo this May and ended the free API service. I went back and re-researched this issue and someone created a new Yahoo finance API call that works with the new yahoo API. https://stackoverflow.com/a/44092983/8316350

在Verizon今年5月收购雅虎并终止免费API服务后,我在长期使用雅虎金融后不得不转向谷歌金融。我回去重新研究了这个问题,有人创建了一个新的雅虎金融 API 调用,它可以与新的雅虎 API 配合使用。 https://stackoverflow.com/a/44092983/8316350

The python source and installer can be found here: https://github.com/c0redumb/yahoo_quote_download

可以在这里找到 python 源代码和安装程序:https: //github.com/c0redumb/yahoo_quote_download

The arguments are (ticker, start_date, and end_date) where dates are yyyymmdd format and returns a list of unicode strings. The following test will download a couple weeks worth of data and then extract only the adjusted close price to return a list called adj_close:

参数是 (ticker, start_date, and end_date) 其中日期是 yyyymmdd 格式并返回一个 unicode 字符串列表。以下测试将下载几周的数据,然后仅提取调整后的收盘价以返回一个名为 adj_close 的列表:

from yahoo_quote_download import yqd
import string
quote = yqd.load_yahoo_quote('AAPL', '20170515', '20170530')
print(quote[0]) # print the column headers
print(quote[1]) # print a couple rows of data
print(quote[2]) # just to make sure it looks right
quote.pop()  # get rid of blank string at end of data
quote = [row.encode("utf-8") for row in quote]  # convert to byte data
quote = [string.split(row, ',') for row in quote] # split the string to create a list of lists
adj_close = [row[5] for row in quote]  # grab only the 'adj close' data and put into a new list
print(adj_close)

Returns:

返回:

Date,Open,High,Low,Close,Adj Close,Volume
2017-05-15,156.009995,156.649994,155.050003,155.699997,155.090958,26009700
2017-05-16,155.940002,156.059998,154.720001,155.470001,154.861862,20048500
['Adj Close', '155.090958', '154.861862', '149.662277', '151.943314', '152.461288', '153.387650', '153.198395', '152.740189', '153.268112', '153.009140', '153.068893']

回答by ATOzTOA

I was manually reading from Google Finance page for each stock before I got the ?infolink. As this is not working anymore, I am going back to the webpage.

在获得?info链接之前,我正在从 Google 财经页面手动阅读每只股票。由于这不再起作用,我将返回网页。

Here is my python snippet:

这是我的python片段:

def get_market_price(symbol):
    print "Getting market price: " + symbol

    base_url = 'http://finance.google.com/finance?q='

    retries = 2

    while True:
        try:
            response = urllib2.urlopen(base_url + symbol)
            html = response.read()
        except Exception, msg:
            if retries > 0:
                retries -= 1
            else:
                raise Exception("Error getting market price!")

        soup = BeautifulSoup(html, 'lxml')

        try:
            price_change = soup.find("div", { "class": "id-price-change" })
            price_change = price_change.find("span").find_all("span")
            price_change = [x.string for x in price_change]

            price = soup.find_all("span", id=re.compile('^ref_.*_l$'))[0].string
            price = str(unicode(price).encode('ascii', 'ignore')).strip().replace(",", "")

            return (price, price_change)
        except Exception as e:
            if retries > 0:
                retries -= 1
            else:
                raise Exception("Can't get current rate for scrip: " + symbol)

Example:

例子:

Getting market price: NSE:CIPLA
('558.55', [u'+4.70', u'(0.85%)'])

回答by dev-sonnyk

I was dying to look for thread like this yesterday when I faced the issue!

昨天当我遇到这个问题时,我很想寻找这样的线程!

Like Salketer said, Google Finance API was officially "closed" in 2012. However, for some reason it was still working until September 5, 2017. I built a program to manage my portfolio that uses GF API to get live quotes for US stocks. It stopped working on Sep 6, 2017, so I am assuming that engineers behind "secretly providing" API now "actually" stopped the service.

正如 Salketer 所说,Google Finance API 于 2012 年正式“关闭”。但是,由于某种原因,它一直工作到 2017 年 9 月 5 日。我构建了一个程序来管理我的投资组合,该程序使用 GF API 来获取美国股票的实时报价。它于 2017 年 9 月 6 日停止工作,因此我假设“秘密提供”API 背后的工程师现在“实际上”停止了该服务。

I found an alternative https://www.alphavantage.co/documentation/, and this seems like the best alternative for free live US equity quotes. They just require your email, nothing else. It's a bit slow because it doesn't have multi-symbol query yet, but beggars can't be choosers.

我找到了另一个https://www.alphavantage.co/documentation/,这似乎是免费实时美国股票报价的最佳选择。他们只需要您的电子邮件,别无其他。它有点慢,因为它还没有多符号查询,但乞丐不能成为选择者。

回答by Frank

You can simply parse the result of this request:

您可以简单地解析此请求的结果:

https://finance.google.com/finance/getprices?q=GOOG&x=NASD&p=1d&i=60&f=d,c,o,h,l,v

https://finance.google.com/finance/getprices?q=GOOG&x=NASD&p=1d&i=60&f=d,c,o,h,l,v

(GOOG at NASDAQ, one day, frequency 60 seconds, DATE,CLOSE,HIGH,LOW,OPEN,VOLUME)

(纳斯达克的 GOOG,一天,频率 60 秒,日期,收盘,高,低,开盘,成交量)

回答by Surya Adhikari

I had a same problem in PHP.

我在 PHP 中遇到了同样的问题。

I replace the URL https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency

我替换了 URL https://www.google.com/finance/converter?a=$amount&from=$from_Currency&to=$to_Currency

to

https://finance.google.com/finance/converter?a=1&from=$from_Currency&to=$to_Currency

https://finance.google.com/finance/converter?a=1&from=$from_Currency&to=$to_Currency

Works fine for me.

对我来说很好用。