The script (or "scriptlet", I guess) uses Paul Jamieson Fenwick's wonderful Finance::Quote Perl module. The rational behind making the script was basically to have an easy interface to the module and an easy (and easily configurable) way to get stock quotes for my rather meager portfolio of tech stocks (although after what's happened to the NASDAQ so far this April, I'm not sure anymore if I want to see what's happening to my stocks...). I wanted to be able to get certain quote info from within another script I have, yet I also wanted a plain old server-side includes to return more detailed information from my HTML "home page", all without having to edit the script itself. In addition, I wanted to get quote data on one or more than one stock as needed, again without editing the script or hacking together a new quotes script every time I wanted different data. So I get this by "packaging" Finance::Quote's functionality in a Perl "wrapper" that I can easily call from someplace else.
The script would probably be most useful for anyone that doesn't want to write Perl CGI scripts or is just too lazy to bother (in the Good Sense). If you want to get different stock data in many places all from one source, then getstockquote will probably save you some time. One future use of it for me is to have a page which gives many very terse quotes, each of which are linked to more detailed single quote info. With this script I can do all that using just plain old HTML.
All data fetched, except for ASX quotes, are in US Dollars. ASX data are in Australian Dollars.
QCOM Last: 65.76 High: N/A Low: N/A CSCO Last: 24.01 High: N/A Low: N/A
It can also return a lot more info if you turn on verbose fetches. Here's that same quote with all the data and a larger font size:
QCOM Last: 65.76 High: N/A Low: N/A Change: 0.00% Last Trade: 5/21/2013 at 4:00pm Volume: 0 shares Open: N/A Close: 65.76 Bid: 65.18 Ask: 66.80 CSCO Last: 24.01 High: N/A Low: N/A Change: 0.00% Last Trade: 5/21/2013 at 4:00pm Volume: 0 shares Open: N/A Close: 24.01 Bid: 23.82 Ask: 24.05
The output looks a little bare and out of place here all by itself, but imagine it embedded in your web page somewhere. The smaller font and less verbose output makes the output suitable for use in a web page's sidebar, for example.
tar zxvf getstockquote-1_02.tar.gzYou'll end up with this readme and the getstockquote script. Make sure the script is still executable and you're set.
You can get everything you need at CPAN:
/path/to/getstockquote [--fontsize=1..6] [--verbose=yes|no] <quote_source> <ticker1> [ticker2] ...
You can specify as many ticker symbols as you want -- there is no real limit. The options are global, however: One size fits all.
Options you can use are:
Script can be called as a server-side exec:
<!--#exec cmd="/path/to/getstockquote <quote_source> <ticker1> [ticker2] ... " -->
Script can also be called from another Perl script:
print `/path/to/getstockquote <quote_source> <ticker1>`;or
print system("/path/to/getstockquote <quote_source> <ticker1>");
Note that using this from a CGI script (as in the examples above) without trapping errors, checking for malicious input, etc. is not recommended and may represent an enormous security risk. Do this AT YOUR OWN PERIL! I'm serious about this, you can make yourself a brand new Very Bad Week if you use CGIs or (especially?) server-side execs incorrectly (or maybe at all, depending on your paranoia level). The script itself is fairly safe as far as CGIs go, but that and 50 cents will get you coffee. Don't run this unless you know that you'll be exposing yourself to greater risk (although probably no more than running any plain CGI script) and you know how to mitigate that risk.
As a stop-gap remedy, if you're having trouble, I would recommend setting the exit(-1) call at the end of the script to just "exit()". That will allow errors to show up on STDOUT, so you'll be able see what went wrong (I hope) in the browser or whatever.
Please try to be as descriptive as possible in whatever email you send.
If you find a bug, then by all means let me know so I can fix it. If you want to fix it, then please help yourself -- the script itself is pretty straightforward. And if you send me your changes, I'll think warm thoughts about you. Getting changes is always nice.
If you want something put into the script and you don't have the time or inclination to shoehorn it in yourself, then please let me know what you'd like to see. Most likely, I'll put it in.
If you want to contact me for any other reason, you can get me at firstname.lastname@example.org.
|1.02||2000/04/17||'yahoo_europe' wasn't seen as a valid quote source|
|1.01||2000/04/15||Changed input args, added quote source option|
William Rhodes <mailto:email@example.com>