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

39,845

Solution 1

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

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

where AAPL is the ticker symbol.

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.

Solution 2

Google does indeed offer an API for Google Finance, documented here: 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.com site), unless there's a JSONP script setup on the site you could exploit.

Solution 3

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.

http://vikku.info/codetrash/Yahoo_Finance_Stock_Quote_API

Solution 4

Instead of posting examples, here's a 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).

Solution 5

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").

For example: 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.

Share:
39,845
Ming Liu
Author by

Ming Liu

Updated on March 04, 2020

Comments

  • Ming Liu
    Ming Liu about 4 years

    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:

    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.

    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.