Yahoo Stock Quote (AJAX component/module version)
Written by kksou   
Friday, 26 September 2008

This component/module pair allows you to display stock quotes from Yahoo Finance.

The stock quotes are obtained in "real-time" direct from Yahoo Finance. Note: as stated in the Yahoo Finance page, these quotes are delayed (for up to 15 to 20 minutes.), except where indicated otherwise.

Unlike the Yahoo Stock Quote - AJAX module version, this is a component/module pair. The user can enter the symbol in an input field in a module position. The stock quotes are obtained from Yahoo Finance and displayed in a component.

Since this is a component, the real-estate is bigger. So a lot more information can be displayed.

As a start, I've added a stock comparison chart. For example, if you've entered more than one symbol, the stock performance of the stocks will be displayed in a stock comparison chart as shown below:

For subsequent versions, I will add other useful charts provided by Yahoo Finance.


Live Demo

You can view a live demo here.

Note: I've turned off the automatic refresh in these demo so that the Yahoo Finance's server is not overloaded too much when too many users are trying out the demo all at the same time.

Unique Features

  • Retrieves "real-time" stock quotes through Yahoo Finance API.
  • Uses AJAX to display the result - no reloading of pages required!
  • Automatic refresh of the latest stock quotes at user-defined interval.
  • Full CSS support! This means that you can set the font family, font size, foreground and background color of the input field, submit button, symbols, stock quotes, etc.
  • The module can be included in a content item! (see below for details)

How to use

You can display a single quote: e.g. YHOO.

Or you can display multiple quotes all at once: e.g. GOOG,MSFT,YHOO.

If you have entered "GOOG,MSFT,YHOO", you will see the following displayed:

You can turn on or off any of these fields. For example, you can choose to display only some of the fields:

And you can choose to display the symbols by row or by column. This is useful, for example, if you wish to display the stock quotes in the left or right module position.

Automatic Refresh

Of course, the module supports automatic refresh without any reloading of pages.

If your browser supports AJAX, the stock quotes will be refreshed once every 5 seconds. You can set this interval to be longer. But the minimal is 5 seconds. (Of course, technically you can even refresh at a rate of once every one milliseconds. However, if you do so, I think Yahoo will soon come after you for absuing their servers. That's why I set the fastest refresh rate to be 5 seconds.)

To turn off automatic refresh, set the interval to be 0.

Note that the automatic refresh will only work if your browser supports javascript and AJAX. If it doesn't, then the stock quotes will only be displayed when you first click the submit button. The stock quotes will not be updated or refreshed subsequently. You need to manually click the submit button again to get the latest stock quotes from Yahoo Finance.

Intraday Graph - direct links to Yahoo Finance

If you click on any of the intraday thumbnail, it will bring you direct to the full graph at Yahoo Finance site:

Important!

I've implemented the Yahoo Stock Quote Mashup with the use of PHP's cURL library. So please make sure your PHP has the cURL library installed in order to use this module.

For those interested, the module uses cURL at the backend to retrieve the quotes using Yahoo Finance API. The result is then passed back to the client (i.e. the browser) using AJAX. Since AJAX is used, no reloading of pages is required when the result is displayed.

Support for non-javascript browser

The module will also work for non-javascript browser and browsers which do not allow javascript. For these browsers, since AJAX cannot run, there will be reloading of the page when the submit button is clicked. The same result will appear for both the AJAX and non-AJAX mode.

Download

Joomla 1.0.x:

Joomla 1.5.x:

Note: To upgrade to the newer version, simply uninstall the old version and install the new version of the plugin.

How to install

  1. First, make sure your PHP has the cURL library installed. You can do a quick check by doing a simple
  2. <?php
    phpinfo();
    ?>
    

    If your PHP has the cURL library installed, you should see something similar to the following:

    phpinfo.gif

    If you don't have the cURL library, there are numerous resources on the Internet that gives you very clear instructions on how to install cURL on various platform such as windows, linux, etc.

  3. Once you've made sure you have the cURL library set up, you can now install the component.
  4. Then install the module and select your desired module position for the module. Make sure you publish/enable the module.
  5. Go to Component, select "Yahoo Stock Quote - Configure", and enter your desired width and height of the search result.
  6. Create a menu item for the component. Although this is not necessary, but I would strongly encourage you to do so -
    so that there is an ItemID associated with the component.

That's it! You're now ready to use the Yahoo Stock Quote right inside your Joomla website!

Customizing the Component

  • Log on as Administrator, from the Component Menu, select "Yahoo Stock Quote" for Joomla 1.5, and "Yahoo Stock Quote - configure" in Joomla 1.0.
    1. Size of input field: This is the size of the input field for users to enter the symbols.
    2. Refresh frequency: This is the interval between each stock quotes refresh (in number of seconds). As noted above, the fastest refresh rate is once every 5 seconds.
    3. Label for Submit Button: Default is "Get Quotes". You may change this to your language.
    4. Layout style: There are currently two layout styles to choose from:
    5. Style 1 The stock quote for each symbol are listed by column.
      Style 2 The stock quote for each symbol are listed by row.

    6. The rest of the fields are the available stock quotes information from Yahoo Finance. Please select your desired fields accordingly.

    Styling the Module using CSS

    The entire formatting of the stock quotes is done using CSS. If you do not like the default look and feel of the stock data, you can edit the following CSS file:

    <your joomla root folder>/modules/mod_yahoostockquote/yahoostockquote.css

    Note that in the stylesheet yahoostockquote.css, I've only used some of the possible styles.

    In case you need even more control, below are listed some additional styles you can use. Just add these new styles to the file yahoostockquote.css.

    1. Input Box
    2. div.yahoostock input.inputbox {
      	font-family: Verdana;
      	font-size: 12pt;
      	font-style: italic;
      }
      
    3. Submit Button
    4. div.yahoostock input.button {
      	font-family: Verdana;
      	font-size: 10pt;
      }
      
    5. Use this if you wish to set the background color of the entire module block:
    6. div.yahoostock {
      	background: #33FF66;
      }
      

    FAQ (Frequently Asked Questions)

    Q1: I modified the stylesheet. But the new styles do not seem to take effect.

    A1: Note that after you have modified the stylesheet yahoostockquote.css, you have to reload the page so that the stylesheet is reloaded.

    I've also found that for some browsers, they still use the "cached" version of stylesheet even when you click the "Reload" button. In such case, you need to clear the cache so the the modified stylesheet gets reloaded.

    Q2: I changed the format from Style 1 to Style 2. But the stock quotes are still displayed as Style 1.

    A2: After you have changed the style in Modules Manager from Style 1 to Style 2, make sure you click the "Reload" button on the page in which the stock quotes are displayed.

    Q3: When I use the module, I need to press once on 'Get Quotes' before the quotes are retrieved. In your demo on this site I see the quotes are immediately available. How can I achieve this ?

    A3: Just pass in the parameters in the url.

    a = the symbols
    process = 1 (to get the stock quote immediately)
    

    For example, for the "Yahoo Stock Quote in content item - sample 2 ", you can use the following to give a direct stock quote:

    http://www.kksou.com/php-gtk2/Joomla-samples/
    Yahoo-Stock-Quote-in-content-item-sample-2.php?
    a=YHOO,GOOG,MSFT&process=1
    

    Note: Starting from version 1.01/1.51, the stock quotes will be displayed when the module is first loaded — without the need to press the Submit button.

    Q4: How to display the quotes for the indexes, e.g. NYSE, NASDAQ, NIKKEI 225, etc.

    A4: You can just enter the symbols for the respective indexes. For example, for NYSE, NASDAQ, NIKKEI 225, enter the following:

    ^NYA,^IXIC,^N225
    

    If you do not know the symbols for the indexes, you can look up the respective symbols from http://finance.yahoo.com/.


     

    Comments  

     
    # Cepeda 2012-10-03 07:49
    To Whom It May Concern:

    Do you have a Joomla 2.5 version for yahoo qoutes?
     
     
    # Michell 2012-10-09 00:16
    Fine but not for Joomla 2.5 :cry:
     
     
    # chittah chattah 2012-10-31 12:50
    Please update for Joomla 2.5 !!!
     
     
    # stock quotes 2013-11-20 06:38
    Hi everybody........

    I hope that you will get the best online free stock quotes of the universe from here.besides, here you will get special
    offer by select any the best online free stock quotes.for more details please visit here

    Thank you
    www.seekingtechnicals.com
     
    < Prev   Next >

    Blog - Forum - Privacy Policy - Contact Us
    Copyright © 2006-2015. kksou.com. All Rights Reserved