Yahoo Stock Quote (AJAX module version)
Written by kksou   
Saturday, 06 September 2008

This module allows you to display stock quotes from Yahoo Finance in a module position.

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.

The latest version now allows you to display the time in your local time, e.g. Hong Kong's Hang Seng Index in Hong Kong time. Please refer to here for details.


Live Demo

There are three demos available:

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)

Latest Version

v1.0.7 (for Joomla 1.0) and v1.5.7 (for Joomla 1.5)
Released Jun 26, 2009

Thanks to Andrew to provide me with the list of additional yahoo stock quote APIs. The new version now allows you to display a lot more financial info such as P/E ratio, Earnings per share (EPS), market cap, etc.

The new version also incorporates some of the feature requests from users:

  • read yahoo data by CURL, file_get_contents() or fread()
  • display of symbol name from Yahoo e.g. ^N225 is NIKKEI 225, ^HSI is HANG SENG INDEX
  • date format e.g. for those in UK, you can now use j/n/Y to display dates in d/m/yyyy
  • added global time offset e.g. for those in UK, you can use a global time offset of +5
  • added global time zone name, e.g. for those using mountain time, you can set this as MT
  • provides link to different charts: 1d, 5d, 1m, ytd, 1y, 2y, 5y
  • now links to yahoo interactive chart instead of basic chart
  • you can now hide the search field and submit button
  • allow you to set the order of the display fields (similar to setting the order of Joomla modules in the admin page)

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.

Display in Local Time

The stock quote from Yahoo Finance are always displayed in ET time.

Global Time Offset

You can set a global time offset in the parameters page. All displayed time will be offset by this amount. Please refer to here for more details.

Local Time Offset

To do a local time offset, enter the following in search field:

^HSI(+13)

The +13 will auotmatically add 13 hours to the ET time.

You can add some additional characters behind the time offset to indicate the time zone, e.g.

^HSI(+13HK)

Note that there is now "HK" appended behind the time. Note that the program WILL NOT automatically find out the difference between HK and ET time. You have to manually specify how many hours to add or subtract from the ET time.

You can have multiple offsets for different symbols, e.g.

YHOO,^HSI(+13HK),^N225(+14JP)

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:

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.

Including this module in Content Item or Article

Since this is a standard Joomla module, you can easily include this module into a content item or article with the use of {mosloadposition} (for Joomla 1.0.x) or {loadposition} (for Joomla 1.5.x).

You can take a look at the demo here.

Download

The Yahoo Stock Quote module is FREE to use (even on commercial websites) as long as the Powered by JoomlaGadgets links remain intact and visible.

Remove the "Powered by" links

You may not edit or remove any copyright or Powered by statements in the Yahoo Stock Quote module.

However, if you find the module useful and would like to use the module without the "Powered-by" links, you may do so by purchasing a "Powered-by" removal license for only USD $10.

Secured payment is processed by 2checkout.com. All major credit cards are accepted, including Visa, Mastercard and American Express, etc. You can also pay by PayPal. Once the transaction is completed, you will be given a link to download the version with the "Powered by" links removed.

How to install

  1. Download and install the "Yahoo Stock Quote" module.
  2. Make sure the module is published / enabled.
  3. Select a module position where you want to place the module.

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

Parameters

You can set the following in the Parameters page:

  1. Use which method to retrieve data: There are now three methods to retrieve data from Yahoo Finance.
    • The default method uses fread().
    • You can also use file_get_contents(). Note that file_get_contents() is only available in PHP5 and above.
    • Use the cURL library. For this method, you need to make sure your PHP has the cURL library installed.

    Use the default method fread() first. If it doesn't work, then try file_get_contents(), and then the cURL library.

  2. Size of input field: This is the size of the input field for users to enter the symbols.
  3. 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.
  4. Label for Submit Button: Default is "Get Quotes". You may change this to your language.
  5. Layout style: There are currently two layout styles to choose from:
  6. Style 1 The stock quote for each symbol are listed by column.
    Style 2 The stock quote for each symbol are listed by row.

  7. Date Format: This is the date format in PHP's date format. For example, if you're from UK, you can use d/m/y to display date format in dd/mm/yyyy.
  8. Global Time Offset: The stock quote from Yahoo Finance are always displayed in ET time. If you are, say in UK, you can enter a +5 in this field to offset all time by +5 hours.
  9. Global Time Zone Name: The stock quote from Yahoo Finance are always displayed in ET time. If you are, say in the Mountain Time (MT) time zone, you can enter an "MT" here so that all time is displayed as time+'MT'.
  10. Hide Search Field: If you want to preset the symbols and do not want the users to enter other symbols, enter "Yes" here. The input field as well as the "Get Quotes" button will be hidden.
  11. Selection and ordering of the fields: The rest of the fields are the available stock quotes information from Yahoo Finance. Please select your desired fields accordingly.
  12. I've used the same method as that used in the ordering of modules/plugins in the Joomla admin page. You select and position a field by inputting an integer number 1, 2, 3, etc. A field with 0 will not be displayed. Note that the number need not be sequential, for example, you can also input 1, 10, 20, 30, 40, 100, 210, 300, etc.

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;
    }
    

History

  • v1.0.1 (for Joomla 1.0) and v1.5.1 (for Joomla 1.5)
    Released September 16, 2008
    • Stock quotes will now be displayed when the module is first loaded (without the need to press the Submit button).
    • Don't forget to define the parameter Default Symbols in the Module Manager. This is the initial list of symbols to be displayed when the module is first loaded.
  • v1.0.2 (for Joomla 1.0) and v1.5.2 (for Joomla 1.5)
    Released September 17, 2008
    • Changed the progress.gif to a smaller size so that there is no displacement of layouts when the animated gif is displayed via AJAX.
    • You can now use your own animated gif for the "loading-in-progress" image when the module is retrieving data from Yahoo. The filename of the animated gif is specified in the parameters page of the Module Manager, and the animated gif should be placed in the folder <joomla_root>/modules/mod_yahoostockquote.
    • I've included one additional animated gif called "progressbar.gif": . Use this if the width of your module is large enough. If you are using the module in the left or right module position, use the default progress image:
    • If you find the animated gif distracting, you can suppress this altogether in the parameters page.

  • v1.0.3 (for Joomla 1.0) and v1.5.3 (for Joomla 1.5)
    Released September 23, 2008
  • Thanks to Karen who informed about the "Division by zero" error when the previous trade value is zero. This sometimes occurs when Yahoo Finance reset these values a few hours before the market opens.

    Have fixed the code so that there will not be any "Division by zero" error.

  • v1.0.4 (for Joomla 1.0) and v1.5.4 (for Joomla 1.5)
    Released January 20, 2009
  • This is in response to Achdw's request to be able to display local time for the Yahoo stock quotes, for example, to display Hong Kong's Hang Seng Index in Hong Kong time

    The latest version now supports this. Please refer to here for details.

  • v1.0.5 (for Joomla 1.0) and v1.5.5 (for Joomla 1.5)
    Released January 24, 2009
  • Bug fix: you can now specify the fields to be displayed again. Thanks to Elie for highlighting the bug.

  • v1.0.6 (for Joomla 1.0) and v1.5.6 (for Joomla 1.5)
    Released April 8, 2009
  • Bug fix: v1.5.6 fixed line 297 $row is redundant.

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/.


User reviews   Average user ratings:    4.0   (from 7 users)
  1. h3ndro
    October 15, 2008 2:10am
    verry nice

    where's the component?

  2. kksou
    October 15, 2008 6:34am

    This one is the module version.

    There is another module/component version:
    Yahoo Stock Quote (AJAX component/module version)

    Regards,
    /kksou

  3. doutrax
    November 16, 2008 8:55am
    stand-a-lone

    hello!
    looks like a nice plugin, but is it possible with a stand-a-lone version?

  4. Gary Allen
    February 22, 2009 7:11pm

    I like the formatting and appearance flexibility of this module, and the fact that it just works. But there are a couple of tweaks that seem obvious. How about a currency sign ($, £) in front of the last trade? And shouldn't the quote input box be after the stock quotes themselves, rather than distractingly at the top?

  5. Hans Schuster
    April 06, 2009 7:58am
    Full name of share oder index

    hello!
    very great module!
    i zhe a possibility the i can show the full name of the shre or the index ? i mean i wish no shoert symbols, may i could definy what name comes for a symbol, like goo=Google

    hope you can help me

  6. Hans Schuster
    April 06, 2009 8:09am
    Full name of share oder index

    hello!
    very great module!
    i zhe a possibility the i can show the full name of the shre or the index ? i mean i wish no shoert symbols, may i could definy what name comes for a symbol, like goo=Google

    hope you can help me

  7. Jeff
    June 04, 2009 3:44pm

    I tried to insert the module code into my web page; however, I keep getting "Restricted access"

    Please help

Note: You have to be a registered member to leave a comment. Free registration here.

 
< Prev   Next >

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