Java 如何使用 Google Finance API 获取股票报价?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/527703/
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
How can I get stock quotes using Google Finance API?
提问by Josema
I'm looking for access to financial data from Google services.
我正在寻找访问来自 Google 服务的财务数据的权限。
I found this URLthat 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.
Google 允许此类 HTTP 请求的所有可能参数是什么?我想查看我可以获得的所有不同信息。
采纳答案by cletus
There's a whole API for managing portfolios. *Link removed. Google no longer provides a developer API for this.
有一个用于管理投资组合的完整 API。*链接已删除。Google 不再为此提供开发人员 API。
Getting stock quotes is a little harder. I found one article where someone got stock quotes using Google Spreadsheets.
获取股票报价有点困难。我找到了一篇文章,其中有人使用 Google 电子表格获取股票报价。
You can also use the gadgetsbut 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).
您提到的 API 很有趣,但似乎没有记录(据我所知)。
Here is some information on historical prices, just for reference sake.
这里有一些历史价格的信息,仅供参考。
回答by Philipp Lenssen
Perhaps of interest, the Google Finance API documentaton includes a section detailing how to access different parameters via JavaScript.
或许有趣的是,Google Finance API 文档包含一个部分,详细介绍了如何通过 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.
我想 JavaScript API 可能是您上面提到的 JSON 请求的包装器……也许您可以检查正在发送哪些 HTTP 请求。
回答by fratrik
I found this site helpful.
我发现这个网站很有帮助。
http://benjisimon.blogspot.com/2009/01/truly-simple-stock-api.html
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.
它链接到 yahoo 似乎提供的一个非常简单和有用的 API。
For instance:
例如:
http://finance.yahoo.com/d/quotes.csv?s=GOOG+AAPL&f=snl1
http://finance.yahoo.com/d/quotes.csv?s=GOOG+AAPL&f=snl1
Full details here:
完整的细节在这里:
回答by Patrick
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.
这是您可以使用的示例。还没有谷歌财经,但这是雅虎的例子。您将需要HTMLAgilityPack,这很棒。快乐的符号狩猎。
Call the procedure by using YahooStockRequest(string Symbols);
通过使用调用该过程 YahooStockRequest(string Symbols);
Where Symbols = a comma-delimited string of symbols, or just one symbol
其中 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());
}
}
}
回答by digitalPBK
The Google Finance Gadget APIhas been officially deprecated since October 2012, but as of April 2014, it's still active:
在谷歌财经小工具API已正式自2012年10月弃用,但2014年4月,它的仍然有效:
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
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
您还可以获取图表: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.
请注意,如果您的应用程序供公众使用,则使用 Google Finance API 会违反 Google 的服务条款。
Check google-finance-get-stock-quote-realtimefor the complete code in python
检查google-finance-get-stock-quote-realtime以获取 python 中的完整代码
回答by Marcos
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:
建立在巨人的肩膀上......这是我写的一个单行代码,用于将谷歌当前的所有股票数据转换为本地 Bash shell 变量:
stock=
# 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
然后,您将拥有诸如 $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.
So for stock="FBM"
/tmp/stockprice.tmp.log(and your environment) will contain:
因此,对于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";
回答by Bart
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.phpor Xignite
雅虎和谷歌数据的问题在于,如果您将其用于商业用途,则会违反服务条款。当您的网站/应用程序仍然很小时,它并不是什么大事,但是一旦您成长了一点,您就会开始停止交流。获得许可的解决方案示例是 FinancialContent:http: //www.financialcontent.com/json.php或Xignite
回答by Christopher A. Lewis
This is no longer an active API for google, you can try Xignite, although they charge: http://www.xignite.com
这不再是谷歌的活跃 API,你可以试试 Xignite,虽然他们收费:http: //www.xignite.com
回答by MarmiK
The simplest way as you have explained is this linkthis is for 'Dow Jones Industrial Average'
正如您所解释的,最简单的方法是此链接适用于“道琼斯工业平均指数”
Link 2is for 'NASDAQ-100'
链接 2适用于“纳斯达克 100”
and for all related to NASDAQ link 3
以及所有与纳斯达克相关的链接 3
I think this should be it, else you want same in JSON notations the same as Microsoft
我认为应该是这样,否则你想要与 Microsoft 相同的 JSON 符号
Please refer this old postI 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..
要了解卷的详细信息和其他详细信息,我创建了一个使用 IE 对象从链接中获取详细信息的 vbscript,并提醒特定 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
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..
我相信这会有所帮助..
回答by OverrockSTAR
Try with this: http://finance.google.com/finance/info?client=ig&q=NASDAQ:GOOGL
试试这个: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:
您可以在此 URL 末尾添加公司股票代码以获取其详细信息:
http://finance.google.com/finance/info?client=ig&q=<YOUR COMPANY STOCK SYMBOL>