开发者

fetch google finance data

开发者 https://www.devze.com 2023-01-01 20:44 出处:网络
can anyon开发者_高级运维e provide me an example on how I can fetch the real-time stocks of google financeCame across this (and your post) trying to figure this out myself...

can anyon开发者_高级运维e provide me an example on how I can fetch the real-time stocks of google finance


Came across this (and your post) trying to figure this out myself...

This currently retrieves some XML:

http://www.google.com/ig/api?stock=F

Of course they may close this down as well soon...

I think 'last data=' will give current quote

EDIT:

The api is now completely shutdown and no longer works. An alternative to 'api' for a 'realtime' quote would be:

http://finance.google.com/finance/info?client=ig&q=NYSE:F


As for now (2015), the google finance api is deprecated. If you are comfortable with python, you may use the pypi module googlefinance.

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.


I've been struggling with trying to find a lifetime free access for this data for some time as well, but today I came across Alpha Vantage (https://www.alphavantage.co) and used their data to build an Annotated Timeline from Google Charts.
All you need is to request an API Key (which you get at the moment you fill in their form) and follow their Documentation.

An example of getting a JSON output in PHP:

$url = file_get_contents('https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&outputsize=full&symbol=AAPL&apikey='.$apiKey);
$decoded = json_decode($url, true);


Here's a very simple example: http://googlified.com/files/finance-api.html


The link in the earlier answer was broken when I tried it, so here is another example. You have to do a bit of processing but otherwise it's pretty easy. http://www.google.com/finance/info?client=ig&q=goog,msft

0

精彩评论

暂无评论...
验证码 换一张
取 消