jQuery 从谷歌金融、雅虎金融或交易所本身获取股票报价

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1316093/
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-08-26 11:12:59  来源:igfitidea点击:

fetch stock quotes from google finance, yahoo finance or the exchange itself

asp.netjqueryyahooquotesgoogle-finance

提问by Amit Kumar Jha

I am building a web based trading system where buy and sell signals would be generated by reading quotes from either Yahoo finance, google finance or the exchange(NSE of India) itself.My first preference would be to fetch data from this url:

我正在构建一个基于网络的交易系统,通过读取来自雅虎财经、谷歌财经或交易所(印度 NSE)本身的报价,可以生成买入和卖出信号。我的第一个偏好是从这个 url 获取数据:

http://www.nseindia.com/content/equities/niftywatch.htm

http://www.nseindia.com/content/equities/niftywatch.htm

the page on the site uses tables and i want to fetch data for a particular stock by using class/id of a particular row. Now the problem is I can't figure out how to fetch data from a diffrent domain on my server. I use jquery at the client side, on server-side I use ASP.Net in VB. So please help me out and suggest how do i fetch stock quotes from the above source. Even if i can get access to the table on the above url, my work will be done. Please help. Thanks a lot in advance.

网站上的页面使用表格,我想通过使用特定行的类/ID 来获取特定股票的数据。现在的问题是我不知道如何从我服务器上的不同域中获取数据。我在客户端使用 jquery,在服务器端我在 VB 中使用 ASP.Net。所以请帮助我并建议我如何从上述来源获取股票报价。即使我可以访问上述 url 上的表格,我的工作也将完成。请帮忙。非常感谢。

P.S.: Just noticed on google finance that they stream real time quote for this particular exchange, so if it is easy to fetch data from google(I understand that they have apis for virtually their every service) then please explain the same.

PS:刚刚在谷歌金融上注意到他们为这个特定的交易所流式传输实时报价,所以如果从谷歌获取数据很容易(我知道他们几乎每项服务都有api)那么请解释一下。

回答by dreeves

Here's how to grab historical daily stock prices (up through today) from Yahoo Finance in CSV format:

以下是如何以 CSV 格式从雅虎财经获取历史每日股价(截至今天):

http://ichart.finance.yahoo.com/table.csv?s=AAPL

where AAPLis the ticker symbol.

AAPL股票代码在哪里。

You can limit what that returns with some additional parameters:

您可以使用一些附加参数来限制返回的内容:

  • s - Ticker symbol. This is the only parameter that isn't optional.

    Start date for historical prices:

  • a - Month number, starting with 0 for January.

  • b - Day number, eg, 1 for the first of the month.

  • c - Year.

    End date for historical prices (default is the most current available closing price):

  • d - Month number, starting with 0 for January.

  • e - Day number, eg, 1 for the first of the month.

  • f - Year.

    And finally, the frequency of historical prices:

  • g - Possible values are 'd' for daily (the default), 'w' for weekly, and 'm' for monthly.

  • s - 股票代码。这是唯一不是可选的参数。

    历史价格的开始日期:

  • a - 月份编号,从 0 开始表示一月。

  • b - 天数,例如,1 表示一个月的第一天。

  • c - 年。

    历史价格的结束日期(默认为最新的可用收盘价):

  • d - 月份编号,从 0 开始表示一月。

  • e - 天数,例如,1 表示一个月的第一天。

  • f - 年。

    最后,历史价格的频率:

  • g - 可能的值是“d”代表每日(默认),“w”代表每周,“m”代表每月。

回答by VoteyDisciple

Google does indeed offer an API for Google Finance, documented here: http://code.google.com/apis/finance/

谷歌确实为谷歌财经提供了一个 API,记录在这里:http: //code.google.com/apis/finance/

It looks like it's designed around the idea of a portfolio, and I don't offhand see a way to request a quote for a specific stock. The closest fit seems to be "Retrieving specific positions."

看起来它是围绕投资组合的想法设计的,我没有立即看到一种请求特定股票报价的方法。最接近的似乎是“检索特定位置”

In any case, this is not something you want to tackle with jQuery. For one thing, you will not be able to read any data from another site (e.g., that nseindia.comsite), unless there's a JSONPscript setup on the site you could exploit.

无论如何,这不是您想用 jQuery 解决的问题。一方面,您将无法从另一个站点(例如,该nseindia.com站点)读取任何数据,除非JSONP站点上有您可以利用的脚本设置。

回答by Jayapal Chandran

I have been using a simple REST service for getting stock quote from yahoo and i have just posted in my site for my reference. People can just go through it.

我一直在使用一个简单的 REST 服务从雅虎获取股票报价,我刚刚在我的网站上发布以供参考。人们只能通过它。

http://vikku.info/codetrash/Yahoo_Finance_Stock_Quote_API

http://vikku.info/codetrash/Yahoo_Finance_Stock_Quote_API

回答by RobotHumans

Instead of posting examples, here'sa link to the API docs for yahoo finance. It covers both the CSV and REST APIs(although the CSV seems to be covered more completely).

这里没有发布示例,而是指向 yahoo Finance 的 API 文档的链接。它涵盖了 CSV 和 REST API(尽管 CSV 似乎涵盖得更完整)。

回答by Jake88

You can download the page containing all the information about a particular stock by using wget. After the page is saved to your local hard drive, you can parse and retrieve the real-time price (,p:"stock_price").

您可以使用wget下载包含有关特定股票的所有信息的页面。页面保存到本地硬盘后,可以解析检索实时价格(,p:"stock_price")。

For example: wget http://www.google.ca/finance?q=some_particular_stock

例如: wget http://www.google.ca/finance?q=some_particular_stock

Program this to retrieve information at a regular interval and you have yourself a real-time quote tracker.

对此进行编程以定期检索信息,您就拥有了一个实时报价跟踪器。

回答by Joe Holloway

I'm confused from your comments when you say you can't fetch data from another site.

当您说无法从其他站点获取数据时,我对您的评论感到困惑。

Are you saying that you can't make HTTP calls from your server because it's prohibited by a firewall policy or some other constraint? Or, are you saying you simply don't know how to make HTTP calls from your server?

你是说你不能从你的服务器进行 HTTP 调用,因为它被防火墙策略或其他一些限制所禁止?或者,您是说您根本不知道如何从您的服务器进行 HTTP 调用?

If it's the latter, you should be able to very easily find a .NET library for making HTTP GET calls (I don't use .NET so I can't say exactly what library to use).

如果是后者,您应该能够很容易地找到一个 .NET 库来进行 HTTP GET 调用(我不使用 .NET,所以我不能确切地说要使用哪个库)。

Once you've figured that out, then you need to figure out how you're going to parse the response. Is it data from a HTML table, is it a CSV file, is it an XML feed, or...? They are all going to have different parsing needs, so it's hard to explain how to do it without more specificity. There are likely to be libraries available that you can use for that too, but it certainly depends on what your data source looks like.

一旦你弄清楚了,那么你需要弄清楚你将如何解析响应。它是来自 HTML 表的数据,是 CSV 文件,是 XML 提要,还是...?它们都有不同的解析需求,因此如果没有更多的特殊性,很难解释如何做到这一点。可能有可用的库也可以用于此目的,但这当然取决于您的数据源的外观。

If this is truly the case, it sounds to me like maybe you have only a shallow understanding of how HTTP works and could perhaps benefit from learning how HTTP 1.1 works before going any further. You don't have to understand the whole specification, but enough to distinguish the role of the user agent, server, content types, etc.

如果情况确实如此,那么在我看来,您可能对 HTTP 的工作原理只有肤浅的了解,并且在进一步研究之前可能会从学习 HTTP 1.1 的工作原理中受益。您不必了解整个规范,但足以区分用户代理、服务器、内容类型等的角色。

Otherwise, if you are saying that you can't get around firewall policies and the like, then you will have to give more information about your server environment before we can help.

否则,如果您说您无法绕过防火墙策略等,那么在我们提供帮助之前,您必须提供有关您的服务器环境的更多信息。

回答by Joe Holloway

R u looking for end of day data. If that is the case, you can compose url for bhavcopy or historical data between two dates (there is a limit for duration. I think 3 years or so).

R u 正在寻找日终数据。如果是这种情况,您可以为两个日期之间的 bhavcopy 或历史数据编写 url(持续时间有限制。我认为 3 年左右)。

Interesting thing is, while you download historical data from nseindia, pay attention to the link they have provided while downloading zip data, copy it, modify it to fit your date range, hit it.

有趣的是,当你从 nseindia 下载历史数据时,注意他们在下载 zip 数据时提供的链接,复制它,修改它以适应你的日期范围,点击它。

this way you can automate the download of historical data from nseindia. In fact we are using the same for http://kakup.com

通过这种方式,您可以自动从 nseindia 下载历史数据。事实上,我们对http://kakup.com使用相同的

ofcourse, we convert it to metastock format also. its working fine.

当然,我们也将其转换为 metastock 格式。它的工作正常。