如何使用 Google Finance API 获取股票报价?

发布于 2024-07-13 12:55:46 字数 230 浏览 13 评论 0原文

我正在寻找通过 Google 服务访问财务数据的权限。

我发现此网址可以获取 Microsoft 的股票数据。

Google 允许这种 HTTP 请求使用哪些可能的参数? 我想看看我能得到的所有不同的信息。

I'm looking for access to financial data from Google services.

I found this URL that gets the stock data for Microsoft.

What are all the possible parameters that Google allows for this kind of HTTP request? I'd like to see all the different information that I could get.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

等风也等你 2024-07-20 12:55:46

Google Finance Gadget API 已正式自 2012 年 10 月起已弃用但截至 2014 年 4 月,它仍然活跃。 截至 2022 年 3 月,它已完全失效。


http://www.google.com/finance/info?q=NASDAQ:GOOG
http://www.google.com/finance/info?q=CURRENCY:GBPUSD
http://finance.google.com/finance/info?client=ig&q=AAPL,YHOO

您还可以获取图表:https://www.google.com/finance/getchart?q=YELP

请注意,如果您的申请用于公共消费,使用 Google Finance API违反 Google 的服务条款

请查看 google -finance-get-stock-quote-realtime 获取 python 中的完整代码

The Google Finance Gadget API has been officially deprecated since October 2012, but as of April 2014, it's still active. It is completely dead as of March 2022.


http://www.google.com/finance/info?q=NASDAQ:GOOG
http://www.google.com/finance/info?q=CURRENCY:GBPUSD
http://finance.google.com/finance/info?client=ig&q=AAPL,YHOO

You can also get charts: https://www.google.com/finance/getchart?q=YELP

Note that if your application is for public consumption, using the Google Finance API is against Google's terms of service.

Check google-finance-get-stock-quote-realtime for the complete code in python

淡墨 2024-07-20 12:55:46

有一个完整的 API 用于管理投资组合。 *链接已删除。 Google 不再为此提供开发者 API。

获取股票报价有点困难。 我发现一篇文章有​​人使用 Google 电子表格获取股票报价。

您还可以使用小工具,但是我想这不是你所追求的。

您提到的 API 很有趣,但似乎没有记录(据我所知)。

以下是一些历史价格的信息,仅供参考。

There's a whole API for managing portfolios. *Link removed. Google no longer provides a developer API for this.

Getting stock quotes is a little harder. I found one article where someone got stock quotes using Google Spreadsheets.

You can also use the gadgets but I guess that's not what you're after.

The API you mention is interesting but doesn't seem to be documented (as far as I've been able to find anyway).

Here is some information on historical prices, just for reference sake.

请别遗忘我 2024-07-20 12:55:46

我发现这个网站很有帮助。

http://benjisimon.blogspot.com/2009/01/truly -simple-stock-api.html

它链接到雅虎似乎提供的 API,该 API 非常简单且有用。

例如:

http://finance.yahoo.com/ d/quotes.csv?s=GOOG+AAPL&f=snl1

完整详细信息请参见:

http://www.gummy-stuff.org/Yahoo-data.htm

I found this site helpful.

http://benjisimon.blogspot.com/2009/01/truly-simple-stock-api.html

It links to an API yahoo seems to offer that is very simple and useful.

For instance:

http://finance.yahoo.com/d/quotes.csv?s=GOOG+AAPL&f=snl1

Full details here:

http://www.gummy-stuff.org/Yahoo-data.htm

装迷糊 2024-07-20 12:55:46

编辑:API 调用已被谷歌删除。 所以它不再起作用了。

同意Pareshkumar的回答。 现在有一个用于 URL 调用的 Python 包装器 googlefinance

安装googlefinance

$pip install googlefinance

获取当前股票价格很容易:

>>> from googlefinance import getQuotes
>>> import json
>>> print json.dumps(getQuotes('AAPL'), indent=2)
[
  {
    "Index": "NASDAQ", 
    "LastTradeWithCurrency": "129.09", 
    "LastTradeDateTime": "2015-03-02T16:04:29Z", 
    "LastTradePrice": "129.09", 
    "Yield": "1.46", 
    "LastTradeTime": "4:04PM EST", 
    "LastTradeDateTimeLong": "Mar 2, 4:04PM EST", 
    "Dividend": "0.47", 
    "StockSymbol": "AAPL", 
    "ID": "22144"
  }
]

Google Finance是提供实时股票数据的来源。 yahoo也有其他API,例如yahoo-finance,但延迟15分钟纽约证券交易所和纳斯达克股票。

Edit: the api call has been removed by google. so it is no longer functioning.

Agree with Pareshkumar's answer. Now there is a python wrapper googlefinance for the url call.

Install googlefinance

$pip install googlefinance

It is easy to get current stock price:

>>> from googlefinance import getQuotes
>>> import json
>>> print json.dumps(getQuotes('AAPL'), indent=2)
[
  {
    "Index": "NASDAQ", 
    "LastTradeWithCurrency": "129.09", 
    "LastTradeDateTime": "2015-03-02T16:04:29Z", 
    "LastTradePrice": "129.09", 
    "Yield": "1.46", 
    "LastTradeTime": "4:04PM EST", 
    "LastTradeDateTimeLong": "Mar 2, 4:04PM EST", 
    "Dividend": "0.47", 
    "StockSymbol": "AAPL", 
    "ID": "22144"
  }
]

Google finance is a source that provides real-time stock data. There are also other APIs from yahoo, such as yahoo-finance, but they are delayed by 15min for NYSE and NASDAQ stocks.

淑女气质 2024-07-20 12:55:46

雅虎和谷歌数据的问题在于,如果您将其用于商业用途,则会违反服务条款。 当您的网站/应用程序还很小时,它并不大,但是一旦您成长一点,您就开始停止交流。
许可的解决方案示例是 FinancialContent:http://www.financialcontent.com/json.php
Xignite

The problem with Yahoo and Google data is that it violates terms of service if you're using it for commercial use. When your site/app is still small it's not biggie, but as soon as you grow a little you start getting cease and desists from the exchanges.
A licensed solution example is FinancialContent: http://www.financialcontent.com/json.php
or Xignite

泛泛之交 2024-07-20 12:55:46

也许有趣的是,Google Finance API 文档包含详细介绍如何进行操作的部分通过 JavaScript 访问不同的参数

我想 JavaScript API 可能是您上面提到的 JSON 请求的包装器...也许您可以检查正在发送哪些 HTTP 请求。

Perhaps of interest, the Google Finance API documentaton includes a section detailing how to access different parameters via JavaScript.

I suppose the JavaScript API might be a wrapper to the JSON request you mention above... perhaps you could check which HTTP requests are being sent.

夜深人未静 2024-07-20 12:55:46

这不再是 google 的有效 API,您可以尝试 Xignite,尽管它们收费:http://www.xignite.com< /a>

This is no longer an active API for google, you can try Xignite, although they charge: http://www.xignite.com

七七 2024-07-20 12:55:46

正如您所解释的,最简单的方法是这个链接,这是为了
“道琼斯工业平均指数”

链接 2 适用于“NASDAQ-100”

,并且对于所有与纳斯达克相关的链接 3

我认为应该是这样,否则你想要同样的采用与 Microsoft 相同的 JSON 表示法

请参阅此旧帖子 我认为这会有所帮助,

更新:

要了解卷的详细信息和其他详细信息,
我创建了一个 vbscript,它使用 IE 对象从链接中获取详细信息,并提醒特定 id 中的内容(创建一个 .vbs 文件并运行它..

Set IE = CreateObject("InternetExplorer.Application")
while IE.readyState = 4: WScript.Sleep 10: wend
IE.Navigate "https://www.google.com/finance?q=INDEXNASDAQ%3ANDX&sq=NASDAQ&sp=2&ei=B3UoUsiIH5DIlgPEsQE"
IE.visible = true
while IE.readyState = 4: WScript.Sleep 10: wend
dim ht
ht= IE.document.getElementById("market-data-div").innerText
msgBox ht
IE.quit

这将提醒页面中的值
像这样

3,124.54 0.00 (0.00%)
Sep 4 - Close
INDEXNASDAQ real-time data - Disclaimer
Range       -
52 week 2,494.38 - 3,149.24
Open        -
Vol.    0.00

我相信这会有所帮助..

The simplest way as you have explained is this link this is for
'Dow Jones Industrial Average'

Link 2 is for 'NASDAQ-100'

and for all related to NASDAQ link 3

I think this should be it, else you want same in JSON notations the same as Microsoft

Please refer this old post I think this will help,

Update:

To know the details of volume and other details,
I have created a vbscript that is using IE object to fetch details from the link, and alerts the content in the particular id(Create a .vbs file and run it..

Set IE = CreateObject("InternetExplorer.Application")
while IE.readyState = 4: WScript.Sleep 10: wend
IE.Navigate "https://www.google.com/finance?q=INDEXNASDAQ%3ANDX&sq=NASDAQ&sp=2&ei=B3UoUsiIH5DIlgPEsQE"
IE.visible = true
while IE.readyState = 4: WScript.Sleep 10: wend
dim ht
ht= IE.document.getElementById("market-data-div").innerText
msgBox ht
IE.quit

this will alert the values from page
like this

3,124.54 0.00 (0.00%)
Sep 4 - Close
INDEXNASDAQ real-time data - Disclaimer
Range       -
52 week 2,494.38 - 3,149.24
Open        -
Vol.    0.00

I am sure this will help..

烛影斜 2024-07-20 12:55:46

这是您可以使用的示例。 还没有谷歌财经,但这是雅虎的例子。 您将需要 HTMLAgilityPack ,这非常棒。 快乐的符号狩猎。

使用 YahooStockRequest(string Symbols); 调用该过程,

其中 Symbols = 以逗号分隔的符号字符串,或仅一个符号

public string YahooStockRequest(string Symbols,bool UseYahoo=true)
        {
            {
                string StockQuoteUrl = string.Empty;

                try
                {
                    // Use Yahoo finance service to download stock data from Yahoo
                    if (UseYahoo)
                    {
                        string YahooSymbolString = Symbols.Replace(",","+");
                        StockQuoteUrl = @"http://finance.yahoo.com/q?s=" + YahooSymbolString + "&ql=1";
                    }
                    else
                    {
                        //Going to Put Google Finance here when I Figure it out.
                    }

                    // Initialize a new WebRequest.
                    HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(StockQuoteUrl);
                    // Get the response from the Internet resource.
                    HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
                    // Read the body of the response from the server.

                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    string pageSource;
                    using (StreamReader sr = new StreamReader(webresp.GetResponseStream()))
                    {
                        pageSource = sr.ReadToEnd();
                    }
                    doc.LoadHtml(pageSource.ToString());
                    if (UseYahoo)
                    {
                        string Results=string.Empty;
                        //loop through each Symbol that you provided with a "," delimiter
                        foreach (string SplitSymbol in Symbols.Split(new char[] { ',' }))
                        {
                            Results+=SplitSymbol + " : " + doc.GetElementbyId("yfs_l10_" + SplitSymbol).InnerText + Environment.NewLine;
                        }
                        return (Results);
                    }
                    else
                    {
                        return (doc.GetElementbyId("ref_14135_l").InnerText);
                    }

                }
                catch (WebException Webex)
                {
                    return("SYSTEM ERROR DOWNLOADING SYMBOL: " + Webex.ToString());

                }

            }
        }

Here is an example that you can use. Havent got Google Finance yet, but Here is the Yahoo Example. You will need the HTMLAgilityPack , Which is awesome. Happy Symbol Hunting.

Call the procedure by using YahooStockRequest(string Symbols);

Where Symbols = a comma-delimited string of symbols, or just one symbol

public string YahooStockRequest(string Symbols,bool UseYahoo=true)
        {
            {
                string StockQuoteUrl = string.Empty;

                try
                {
                    // Use Yahoo finance service to download stock data from Yahoo
                    if (UseYahoo)
                    {
                        string YahooSymbolString = Symbols.Replace(",","+");
                        StockQuoteUrl = @"http://finance.yahoo.com/q?s=" + YahooSymbolString + "&ql=1";
                    }
                    else
                    {
                        //Going to Put Google Finance here when I Figure it out.
                    }

                    // Initialize a new WebRequest.
                    HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(StockQuoteUrl);
                    // Get the response from the Internet resource.
                    HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
                    // Read the body of the response from the server.

                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    string pageSource;
                    using (StreamReader sr = new StreamReader(webresp.GetResponseStream()))
                    {
                        pageSource = sr.ReadToEnd();
                    }
                    doc.LoadHtml(pageSource.ToString());
                    if (UseYahoo)
                    {
                        string Results=string.Empty;
                        //loop through each Symbol that you provided with a "," delimiter
                        foreach (string SplitSymbol in Symbols.Split(new char[] { ',' }))
                        {
                            Results+=SplitSymbol + " : " + doc.GetElementbyId("yfs_l10_" + SplitSymbol).InnerText + Environment.NewLine;
                        }
                        return (Results);
                    }
                    else
                    {
                        return (doc.GetElementbyId("ref_14135_l").InnerText);
                    }

                }
                catch (WebException Webex)
                {
                    return("SYSTEM ERROR DOWNLOADING SYMBOL: " + Webex.ToString());

                }

            }
        }
好多鱼好多余 2024-07-20 12:55:46

建立在巨人的肩膀上...这是我写的一句话,用于将 Google 当前的所有股票数据转换为本地 Bash shell 变量:

stock=$1 

# Fetch from Google Finance API, put into local variables
eval $(curl -s "http://www.google.com/ig/api?stock=$stock"|sed 's/</\n</g' |sed '/data=/!d; s/ data=/=/g; s/\/>/; /g; s/</GF_/g' |tee /tmp/stockprice.tmp.log)

echo "$stock,$(date +%Y-%m-%d),$GF_open,$GF_high,$GF_low,$GF_last,$GF_volume"

然后您将拥有诸如 $GF_last $GF_open $GF_volume 等随时可用的变量。 运行 env 或查看 /tmp/stockprice.tmp.log 内部

http://www.google.com/ig/api?stock=TVIX&output=csv by itself returns:

<?xml version="1.0"?>
<xml_api_reply version="1">
<finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<symbol data="TVIX"/>
<pretty_symbol data="TVIX"/>
<symbol_lookup_url data="/finance?client=ig&q=TVIX"/>
<company data="VelocityShares Daily 2x VIX Short Term ETN"/>
<exchange data="AMEX"/>
<exchange_timezone data="ET"/>
<exchange_utc_offset data="+05:00"/>
<exchange_closing data="960"/>
<divisor data="2"/>
<currency data="USD"/>
<last data="57.45"/>
<high data="59.70"/>
<low data="56.85"/>

etc.

因此对于 stock="FBM" /tmp/stockprice.tmp.log (以及您的环境)将包含:

GF_symbol="FBM"; 
GF_pretty_symbol="FBM"; 
GF_symbol_lookup_url="/finance?client=ig&q=FBM"; 
GF_company="Focus Morningstar Basic Materials Index ETF"; 
GF_exchange="NYSEARCA"; 
GF_exchange_timezone=""; 
GF_exchange_utc_offset=""; 
GF_exchange_closing=""; 
GF_divisor="2"; 
GF_currency="USD"; 
GF_last="22.82"; 
GF_high="22.82"; 
GF_low="22.82"; 
GF_volume="100"; 
GF_avg_volume=""; 
GF_market_cap="4.56"; 
GF_open="22.82"; 
GF_y_close="22.80"; 
GF_change="+0.02"; 
GF_perc_change="0.09"; 
GF_delay="0"; 
GF_trade_timestamp="8 hours ago"; 
GF_trade_date_utc="20120228"; 
GF_trade_time_utc="184541"; 
GF_current_date_utc="20120229"; 
GF_current_time_utc="033534"; 
GF_symbol_url="/finance?client=ig&q=FBM"; 
GF_chart_url="/finance/chart?q=NYSEARCA:FBM&tlf=12"; 
GF_disclaimer_url="/help/stock_disclaimer.html"; 
GF_ecn_url=""; 
GF_isld_last=""; 
GF_isld_trade_date_utc=""; 
GF_isld_trade_time_utc=""; 
GF_brut_last=""; 
GF_brut_trade_date_utc=""; 
GF_brut_trade_time_utc=""; 
GF_daylight_savings="false"; 

Building upon the shoulders of giants...here's a one-liner I wrote to zap all of Google's current stock data into local Bash shell variables:

stock=$1 

# Fetch from Google Finance API, put into local variables
eval $(curl -s "http://www.google.com/ig/api?stock=$stock"|sed 's/</\n</g' |sed '/data=/!d; s/ data=/=/g; s/\/>/; /g; s/</GF_/g' |tee /tmp/stockprice.tmp.log)

echo "$stock,$(date +%Y-%m-%d),$GF_open,$GF_high,$GF_low,$GF_last,$GF_volume"

Then you will have variables like $GF_last $GF_open $GF_volume etc. readily available. Run env or see inside /tmp/stockprice.tmp.log

http://www.google.com/ig/api?stock=TVIX&output=csv by itself returns:

<?xml version="1.0"?>
<xml_api_reply version="1">
<finance module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
<symbol data="TVIX"/>
<pretty_symbol data="TVIX"/>
<symbol_lookup_url data="/finance?client=ig&q=TVIX"/>
<company data="VelocityShares Daily 2x VIX Short Term ETN"/>
<exchange data="AMEX"/>
<exchange_timezone data="ET"/>
<exchange_utc_offset data="+05:00"/>
<exchange_closing data="960"/>
<divisor data="2"/>
<currency data="USD"/>
<last data="57.45"/>
<high data="59.70"/>
<low data="56.85"/>

etc.

So for stock="FBM" /tmp/stockprice.tmp.log (and your environment) will contain:

GF_symbol="FBM"; 
GF_pretty_symbol="FBM"; 
GF_symbol_lookup_url="/finance?client=ig&q=FBM"; 
GF_company="Focus Morningstar Basic Materials Index ETF"; 
GF_exchange="NYSEARCA"; 
GF_exchange_timezone=""; 
GF_exchange_utc_offset=""; 
GF_exchange_closing=""; 
GF_divisor="2"; 
GF_currency="USD"; 
GF_last="22.82"; 
GF_high="22.82"; 
GF_low="22.82"; 
GF_volume="100"; 
GF_avg_volume=""; 
GF_market_cap="4.56"; 
GF_open="22.82"; 
GF_y_close="22.80"; 
GF_change="+0.02"; 
GF_perc_change="0.09"; 
GF_delay="0"; 
GF_trade_timestamp="8 hours ago"; 
GF_trade_date_utc="20120228"; 
GF_trade_time_utc="184541"; 
GF_current_date_utc="20120229"; 
GF_current_time_utc="033534"; 
GF_symbol_url="/finance?client=ig&q=FBM"; 
GF_chart_url="/finance/chart?q=NYSEARCA:FBM&tlf=12"; 
GF_disclaimer_url="/help/stock_disclaimer.html"; 
GF_ecn_url=""; 
GF_isld_last=""; 
GF_isld_trade_date_utc=""; 
GF_isld_trade_time_utc=""; 
GF_brut_last=""; 
GF_brut_trade_date_utc=""; 
GF_brut_trade_time_utc=""; 
GF_daylight_savings="false"; 
迟月 2024-07-20 12:55:46

Google 股票报价 API 已消失。 不过,Investor's Exchange 提供了一个 API,非常易于使用报价数据。

The Google stock quote API has gone away. However, Investor's Exchange offers an API that's very easy to use for quote data.

尝蛊 2024-07-20 12:55:46

两年前,我亲自使用 Intrinio 构建了一个用于股票数据和基本面的应用程序,但放弃了该项目,因为我被打败了竞争对手的市场。

我用 Java 构建了它,但它们支持多个堆栈。 那时,您可以免费访问他们的 api 进行测试,但我认为他们现在会根据您的需求构建软件包。

无论如何,他们非常有帮助,并且根据我的记忆收取很低的费用,而且他们的库有很好的文档记录,因此以 json 形式提取数据非常简单。

I have personally built an app for stock data and fundamentals with Intrinio Two years ago but abandoned the project because I was beaten to market by a competitor.

I built it in Java but they support multiple stacks. Back then, You could access their api for free for testing purposes, but I think they build packages based on your needs now.

In any case, they were exceptionally helpful and charge low fees from what I remember, and their library is well documented so pulling data in json is very straightforward.

2024-07-20 12:55:46

为了使用 Google 的金融数据 API 查找图表数据,只需像查找搜索词一样访问 Google,在搜索引擎中输入 Finance,就会出现 Google Finance 的链接。 进入 Google 金融搜索引擎后,在金融数据 API 引擎中输入股票代码名称,结果就会显示。 不过,需要注意的是,所有谷歌财经图表都会延迟15分钟,最多可以用来更好地了解股票的过去历史,而不是当前价格。

解决图表信息延迟的一个办法是获取实时金融数据API。 一个例子是 barchartondemand 界面,它具有实时报价信息,以及其他详细功能,可以更轻松地找到您正在寻找的确切图表。 barchartondemand 的工具具有完全可定制的功能,以及可满足您所需的精确交易信息的特定编程工具,远远超过了 Google 金融。

In order to find chart data using the financial data API of Google, one must simply go to Google as if looking for a search term, type finance into the search engine, and a link to Google finance will appear. Once at the Google finance search engine, type the ticker name into the financial data API engine and the result will be displayed. However, it should be noted that all Google finance charts are delayed by 15 minutes, and at most can be used for a better understanding of the ticker's past history, rather than current price.

A solution to the delayed chart information is to obtain a real-time financial data API. An example of one would be the barchartondemand interface that has real-time quote information, along with other detailed features that make it simpler to find the exact chart you're looking for. With fully customizable features, and specific programming tools for the precise trading information you need, barchartondemand's tools outdo Google finance by a wide margin.

寒江雪… 2024-07-20 12:55:46

尝试用这个:
http://finance.google.com/finance/info? client=ig&q=NASDAQ:GOOGL

它将返回您有关所提及股票的所有可用详细信息。

例如,输出如下所示:

// [ {
"id": "694653"
,"t" : "GOOGL"
,"e" : "NASDAQ"
,"l" : "528.08"
,"l_fix" : "528.08"
,"l_cur" : "528.08"
,"s": "0"
,"ltt":"4:00PM EST"
,"lt" : "Dec 5, 4:00PM EST"
,"lt_dts" : "2014-12-05T16:00:14Z"
,"c" : "-14.50"
,"c_fix" : "-14.50"
,"cp" : "-2.67"
,"cp_fix" : "-2.67"
,"ccol" : "chr"
,"pcls_fix" : "542.58"
}
]

您可以在此 URL 末尾添加您公司的股票代码以获取其详细信息:

http://finance.google.com/finance/info?client=ig&q=<YOUR COMPANY STOCK SYMBOL>

Try with this:
http://finance.google.com/finance/info?client=ig&q=NASDAQ:GOOGL

It will return you all available details about the mentioned stock.

e.g. out put would look like below:

// [ {
"id": "694653"
,"t" : "GOOGL"
,"e" : "NASDAQ"
,"l" : "528.08"
,"l_fix" : "528.08"
,"l_cur" : "528.08"
,"s": "0"
,"ltt":"4:00PM EST"
,"lt" : "Dec 5, 4:00PM EST"
,"lt_dts" : "2014-12-05T16:00:14Z"
,"c" : "-14.50"
,"c_fix" : "-14.50"
,"cp" : "-2.67"
,"cp_fix" : "-2.67"
,"ccol" : "chr"
,"pcls_fix" : "542.58"
}
]

You can have your company stock symbol at the end of this URL to get its details:

http://finance.google.com/finance/info?client=ig&q=<YOUR COMPANY STOCK SYMBOL>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文