Stock Quote Sidebar

Update:  Now hosted at http://wordpress.org/extend/plugins/stock-quote-sidebar/ – please rate the plugin there if you like it!  This page will still be updated, and comments are welcome here.

Important Note:  Yahoo no longer provides the Dow Jones Industrial Average in downloadable format, due to restrictions imposed by Dow Jones.  Therefore, you will not be able to include ^DJI or INDU in your quotes list.  There is currently no workaround.

This is a WordPress plugin that allows you to put a list of stock quotes in your sidebar (or anywhere you want, really). This should be considered beta software, although I’ve been using it without problems for a while, as you can see in my sidebar. I have a different plugin that allows inline stock quote tooltips – check that out here.

Usage:
Unzip into your WordPress plugins directory, which should result in a directory called sqsidebar. Enable the StockQuoteSB plugin in the Admin page. Configure the plugin under WordPress Options, Stock Quote Sidebar.

Then, wherever you want the quotes to appear, put in code like the following, depending on what quotes you want:
<?php get_stock_quote(); ?>

You can also override the symbols configured in WordPress options by explicitly calling get_stock_quote with the symbols as parameters:

<?php get_stock_quote("NOVL,PFE,INTC"); ?>

The options allow you to specify the following:

  • Yahoo URLs to use for quotes and charts
  • Chart range (1 day, 5 day, etc)
  • Date and time format
  • Number of randomly selected quotes to display
  • Whether to display the symbol or the company name

A chart is displayed in a tooltip when you mouse-over the day’s change.

As of version 1.2, cURL is used to download quote data.  Accordingly, cURL must be available and enabled in your PHP environment.

Version 1.3 fixes the issue caused by Yahoo changing the URL for stock data downloads. Existing users will need to download version 1.3 or later, and change the URLs in the plugin’s options to NOT include the “http://” portion. For example, enter finance.yahoo.com and NOT http://finance.yahoo.com

Versions 1.4 and later use a different plugin directory, due to the way the SVN downloads work from WordPress.org.

This plugin has been tested with WordPress 1.5 and later.
Please leave feedback or let me know of any problems below.

This is free software, but donations are accepted in the sidebar.

Download here

Change Log

Share

175 Responses to “Stock Quote Sidebar”


  • Hi Andrew, great work on the plug-in. I’m using it on my site as we speak.

    There’s a small technical error with the way the plugin forms tags, which means that the resulting code isn’t strict XML.

    Where the plugin provides output as:

    table border=0

    for example, to make it comply with strict XML, it should be

    table border=”0″

    The only reason this came up was because I was trying to get some MathML to display on my blog, and ended up getting some XML parsing errors from my browser. It’s an easy to fix, minor bug, and it shouldn’t effect too many users.

    I’d submit a modified version of the script, only I don’t know php very well, so there are probably more quotation marks, literal quotation marks and echo statements in the modified version that I’ve got running than strictly required.

  • Just FYI, line 50 of the Stock Quote Sidebar “fclose($fp);” returned an invalid stream resource error. Once I removed the line, everything worked fine.

    I’m using the same theme you are, but I’m manually editing a lot of stuff, so I can’t be sure what caused the error. Just thought you might want to know.

  • Well, that is more or less just what I have been looking for for quite a while.

    The question for me is: Is this stripping of Yahoo stock quote information legally sound?

    The reason for this question is, that I want to build a German speaking virtual investment community build on individual portfolios and discussions of them. It would be nice to have those stock quotes with this kind of site, too.
    But I am really worried about staying legal (in fact my master thesis will build on this kind of web site).

    Thx for listening in.

  • Andy,

    What about showing only one stock’s price and one of the charts that Yahoo creates? Is there any way to include a graph?

  • Any ideas why the tooltip isn’t showing all the way and if you could add some code to fix it for ANY theme?

    My link is here

  • man it doesn’t work =(

    I down’t know how to do it, can you help me?

    my page http://thebest.net.ru/

  • Fatal error: Cannot redeclare insert_sqsb_header_code() (previously declared in C:\apachefriends\xampp\htdocs\LOCALHOST\TheNewStandard\wp-content\plugins\sqsidebar\stockquote.php:40) in C:\apachefriends\xampp\htdocs\LOCALHOST\TheNewStandard\wp-content\plugins\sqsidebar\stockquote.php on line 47

    Not sure why I’m getting this error when I attempt to access the Stock Quote Sidebar tab under the options menu…

  • Beautiful plugin–everyone should use it.

    I have it running right now on my site.

  • I am getting the same error as Nathan above.

    Fatal error: Cannot redeclare insert_sqsb_header_code() (previously declared in C:\ApacheFriends\xampp\htdocs\wp-content\plugins\sqsidebar\stockquote.php:40) in C:\ApacheFriends\xampp\htdocs\wp-content\plugins\sqsidebar\stockquote.php on line 47

    I am running WP 1.5.2 Any ideas what is going on?

  • Works for me in 1.5.2

    Maybe you just need a real operating system ;)

  • I tried to use your stock quote plugin, but it appears it doesn’t support working behind a firewall. I see $url = sprintf(“%s/d/quotes.csv?s=%s&f=snl1d1t1c1ohgv”, $yahoosite, $stocksymbols); in your code, then $fp = fopen($url, “r”); afterward. I don’t see a method to specify a proxy. Suggestions?

  • Ah – I did a little more research and found out that the user has to be running PHP 5.0.0 or greater to support fopen($url, …). With a little more reading of http://us3.php.net/manual/en/function.fopen.php, I learned even more…

    rafaelbc at matrix dot com dot br
    23-May-2005 10:23
    pflaume dot NOSPAM at NOSPAM dot gmx dot de’s proxy_url() was very helpful to me!
    Although, I still had a problem: proxy authentication.

    So I added some code to enable http get through a proxy with user authentication.

  • Follow-up to above: since the <?php ?> section got cut out from above, here is just that section again…

    <?php
    function proxy_url($proxy_url)
    {
    $proxy_name = ’127.0.0.1′;
    $proxy_port = 4001;
    $proxy_user = “user”; // added
    $proxy_pass = “password”; // added
    $proxy_cont = ”;

    $proxy_fp = fsockopen($proxy_name, $proxy_port);
    if (!$proxy_fp) {return false;}
    fputs($proxy_fp, “GET $proxy_url HTTP/1.0\r\nHost: $proxy_name\r\n”);
    fputs($proxy_fp, “Proxy-Authorization: Basic ” . base64_encode (“$proxy_user:$proxy_pass”) . “\r\n\r\n”); // added
    while(!feof($proxy_fp)) {$proxy_cont .= fread($proxy_fp,4096);}
    fclose($proxy_fp);
    $proxy_cont = substr($proxy_cont, strpos($proxy_cont,”\r\n\r\n”)+4);
    return $proxy_cont;
    }
    ?>

  • This is a great plugin! Thank you. I am using it on my site.

  • Amazing plugin! I was having a problem though: Whenever I rollover the +/- prices, the small charts don’t come up. Is there anything else I need to do to show that?

    Currently, in my script, I am using the following code:

    Help please! I’ve linked my blog site to it. Thanks again! (worst comes to worse, just leave a response in a comment (which I’ll moderate), and I’ll try to fix it.

    Once again, GREAT plugin.

  • Orlando,
    Make sure you have the chart display set for 5 days. Otherwise you wont see it on the roll over at first. I think by default it is not on that. Once I changed mine to 5 days they showed up.

  • I had been using this plugin successfully in WP 2.0 until I moved my site to a new server. Now, whenever I activate the plugin and put the code in my sidebar, my page won’t load. The whole page just comes up blank with no errors at all.
    The only difference I can tell between my old host and my new server is that the new one runs php as cgi. Any ideas? Please shoot me an email if you have any suggestions. Thanks!

  • I changed mine to 5d and the charts still don’t show up. Any ideas?

  • Ok…

    For everyone having the issue of no charts showing up on rollover.

    When the plugin is first enabled it stores the wrong value in the database.

    On initialization of the plugin it will modify an array named ‘$options’ then store the values of ‘$options’ into the database.

    See Line 69.
    It initializes one of the values to:
    $options['yahoochartrange'] = ’1d’;

    When it should be:
    $options['yahoochartrange'] = ‘/t?s=’;

    Unfortunately you can change the value in the php file, but it won’t be reflected in the database, since it’s already been stored in the database on initialization.

    You have two options.
    The first option is to change the value in the script to 5-day or 1-year and save the changes. This will overwrite the default value of ’1d’ to something else. If you want 1-day, then change it back to 1-day in the options and save changes. The value should be now ‘/t?s=’.

    Unfortunately I can’t verify if this works, since I have another error in the script, which I haven’t started to debug yet. #10 in this post. The one that Bruce has documented.

    The second option is easy if you know how to modify a table in a database.

    To modify the value in the database directly open up your MySql table editor of choice (I use phpMyAdmin). The value is the last (or one of the last) entries in the ‘wp_options’ table.

    My value is as follows:
    a:9:{s:15:”sqsbstatsymbols”;a:3:{i:0;s:4:”^DJI”;i:1;s:5:”^IXIC”;i:2;s:5:”^GSPC”;}s:11:”sqsbsymbols”;a:5:{i:0;s:4:”NOVL”;i:1;s:4:”MSFT”;i:2;s:4:”INTC”;i:3;s:3:”PFE”;i:4;s:4:”GOOG”;}s:9:”yahoosite”;s:24:”http://finance.yahoo.com”;s:14:”yahoochartsite”;s:31:”http://ichart.finance.yahoo.com”;s:15:”yahoochartrange”;s:2:”1d”;s:8:”dateform”;s:5:”Y-m-d”;s:8:”timeform”;s:3:”H:i”;s:11:”displayname”;s:6:”symbol”;s:19:”randomquotequantity”;i:0;}

    Find where it says:
    “yahoochartrange”;s:2:”1d”

    Change it to:
    “yahoochartrange”;s:5:”/t?s=”

    Hope this helps.

    Check out my working charts here:
    http://jjfresh.homeip.net/blog/

  • Hello,

    Great plug in, and I’m using it, but it has an interesting twist here. As you will see (if you go here) I have the code in, but instead of having the graphs show up from hoverings, they are up all the time. (At least on my computers.)

    What did I do wrong? Just downloaded and installed per the instructions here.

  • I’ve got the plugin working and displaying the quotes and charts fine, but I seem to be having a problem where it is slowing my site right down – sometimes up to 9 seconds to load, compared to 0.3 if I disable it. I’m assuming this is because my server is taking this time to download the relevant entries from Yahoo (I’m just displaying 3 indices). Is there a way to put a timeout on it, or any other ways to speed it up?

  • Hello;

    Problem with the plugin; When installed;
    My site won’t load at all. Using wordpress 2.01.

    If I remove the ?php call, the site will load.

    Would really like to use your plugin !!!

    ; Ray

  • On version 0.9, you forgot to update the version number reported in “plugins” page.

  • Hi,
    Got it. Loaded it. It works… sort of. I can use the get_stock_quote(“^DJI,^IXIC,^GSPC,NOVL,ko,pfe,intc”) method just fine. But I am actually tracking mutual funds for our 401k. I get no chart data. Is that a function of some update interval? Also, on the options page I cannot add the stocks or mutual funds. When I click on update, I get a blank white page. When I bring up the options for the plugin the changes I made are gone. The install isn’t rocket science, and the dir permissions are correct. Can you think of anything else it might be? Thanks!

  • Fatal error: Cannot redeclare insert_sqsb_header_code() (previously declared in c:\domains\eternalprofits.net\wwwroot\wp-content\plugins\sqsidebar\stockquote.php:44) in c:\domains\eternalprofits.net\wwwroot\wp-content\plugins\sqsidebar\stockquote.php on line 42

    How can i overcome this error.
    My Page at http://www.eternalprofits.net
    Please Help me. I really want ot use it on my site.

  • Hi,

    Is there a way to hard set the interval for the chart in the “stand-alone” version of the script? The default is the 1day view. I am tracking mutual funds for my 401k and the minimum seems to be 3 month.

    Thanks!

  • Hi:
    I installed this plugin, but had some issues. Here they are (btw: I’m pointing to fr.finance.yahoo.com):
    1) the CSV2Array conversion didn’t work because of the separator. I changed it from “,” to “;”.
    2) the getStockQuote didn’t send back correct values for “last” and “change”, so I took out the sprintf statements and now it works fine.
    Is this normal? Do other people have the same issues or is this because I’m pointing to a “European” site?

  • Thanks for the stock sidebar plugin. It works very well on my fairly new site.

    I wanted to ask you also, how did you get your header to randomize since in the theme its in the css file? Thanks for you help in advance.

    -MM

  • I so want to be able to use this but I am using dreamhost and they do not allow the fopen call. I have been reading up on using CURL instead but I am really not very good at programming.

    Any help in adapting this program to use CURL?

    Thanks!

  • Great plug in! Easy, too. Just wondering if you’ve got a theory as to why the S&P 500 shows no current trading level or trend, even though the links to Yahoo function and the tooltip chart works.

    Seems to be doing the same thing on this page, as well as mine.

    Now, if we oculd only show futures trading for crude oil and gold! ;-)

    Cheers!
    M

  • On mouse hover, the stock chart appears, centered underneath the cursor. But my Web page style put the stock quote on the right-hand side of the page, so the stock chart box floats off the right side of the page–only about half is visible. Any way to make the stock box pop up left-justified so it’s all visible?

  • Hello there,

    (using WP2.1) installed the plugin and inserted the code and lo and be hold the site wont load? remove the code and all is well…

    is this a wp2.1 thing?

    thanks,

  • i try to find something at google.com and take it on your site…thanks

  • I installed this but

    “Warning: Invalid argument supplied for foreach() in /[WORDPRESS]/wp-content/plugins/sqsidebar/stockquote.php on line 145″

    on option page!

    I have no idea about “PHP”
    What should I do?

  • I have the same chart cut-off problem as #32, and in fact, this Web page has cut-off charts, too. A small sliver of the chart is cut off from the right side, despite the update history that seems to say the charts were relocated to prevent this.

  • Hey thanks for the awesome plug in. My investment groups thanks you it is a quite useful plug in. You have probably seen the new yahoo badge, I dislike it because it raises security issues also it would be nice if one could really tweak it. One improvement on your plug in would the ability to show percent change. Just a suggestion. Thanks again. You can view your work in action at http://www.theragingbulls.info I am working getting the pop-up stock quotes to just have not got around to it.

  • that’s an awesome plugin! thanks so much!

    Jon

  • Terrific plugin! Thanks for releasing it!

    A suggestion for some future, future, future release– and I know it’s probably a lot of work.

    I think it would be an excellent addition to be able to choose between presenting Yahoo!finance data and charts and those of Google Finance.

    Thanks again for the plugin– glad there are people out there with the brains needed to pull something like this off!

  • Hi Andy- I really appreciate the plug-in. I have a site that I kind of abandoned which is http://stocksblogger.com

    Anyway, if you check it out, you can see that the ticker works great. I love it. Very cool.

    However, I have a new site and I could really use this ticker. Both sites use WordPress 2.0 and both are hosted on the same server with the same hosting package.

    I followed the instructions and added it to my second site. However, after the second site ATTEMPTS to load- it seems to be in some kind of loop and I usually have to shut down I.E.- I get the following error message after a little while:

    Warning: fopen(): URL file-access is disabled in the server configuration in /home/content/c/a/s/casinowinner/html/wp-content/plugins/sqsidebar/stockquote.php on line 307

    Warning: fopen(http://finance.yahoo.com/d/quotes.csv?s=^DJI,^IXIC,^GSPC&f=snl1d1t1c1ohgv): failed to open stream: no suitable wrapper could be found in /home/content/c/a/s/casinowinner/html/wp-content/plugins/sqsidebar/stockquote.php on line 307

    I don’t mind leaving a donation or whatever I have to do. I just really need to get this working!

    Thank you in advance,

    Mike

  • Hi, I was curious what were the legal implications of displaying Yahoo content on my web site as if it was my own? I would love to use this plugin, but I would like to understand if it’s ok to just grab info from Yahoo and just display on my site.

    Thanks

  • Hi Andrew,
    thank you so much for this plugin, it’s very precious for website development.

    In order to make the plugin totally W3C compliant, I was wondering if you knew how to add “width” and “height” tags to the image charts displayed, please?

    I tried hard but diddn’t succeed..

    Thank you again,

    Paul

  • I love this plugin as well, but I do have a similar problem to that of a previous commenter. It seems that, when I use this plugin, loading time for my site goes to around the 10 second range as opposed to nearly instantaneous. It doesn’t seem like the plugin is slowing down the load time for this site or some other sites using the plugin so I was wondering if you could help me shed some light on how to optimize its useage on my site. Thanks so much for your help.

  • Cool! It works great. Thanks!

  • Had to take your plugin out (.8) when I upgraded to WP2. I have now fully widgetized the site and tried various php widget interpreters to call the info (King Text, Widgetize anything etc) but nothing seems to work.
    Any ideas?
    Thanks.

    PS It’s a great tool.

  • Is it possible to use it with Google based quotes? My stock exchange is not supported by Yahoo.

  • I have no idea where to post this I’m new to wordpress please help me.

  • I have no idea where to post this “”. I’m new to wordpress please help me.

  • I have no idea where to post this ?php get_stock_quote(“NOVL,PFE,INTC”); I’m new to wordpress please help me

Leave a Reply

 

Recent Tweets