getstockquote

Retrieve stock and mutual fund info easily and flexibly

Download Latest Version (1.02, 4/17/00) | Readme

What is getstockquote?
getstockquote is an embeddable Perl script that fetches stock or mutual fund data from a variety of sources. It uses command line arguments for grabbing data and so can be used in different ways without altering the script itself. It's "embeddable" because it was designed to be run from within another HTML framework such as via server-side execs, regular CGI scripts, or PHP (although I've used it on the command line as well).

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.

Where does it get data from?
It gets data from any of the following sources:

What kind of data does it fetch?
getstockquote can fetch the following information:

What kind of output does it produce?
getstockquote produces an HTML table with rows for each ticker symbol you want to fetch. The tables have the ticker symbol at the top (in a greyish cell) with each element of the stock's data on a separate row. Changing the default output is as easy as changing any normal HTML doc. An option to produce ASCII output is planned. It will likely be a command line option like everything else.

All data fetched, except for ASX quotes, are in US Dollars. ASX data are in Australian Dollars.

What does the output look like?
The default output is pretty small -- it only fetches the ticker symbol, last traded price, high, and low. Here's an example (using the defaults) of a stock quote I use on my "home page" where I keep all my links and such:

QCOM
Last: N/A
High: N/A
Low: N/A
CSCO
Last: N/A
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: N/A
High: N/A
Low: N/A
Change: N/A
Last Trade: at
Volume: shares
Open: N/A
Close: N/A
Bid: N/A
Ask: N/A
CSCO
Last: N/A
High: N/A
Low: N/A
Change: N/A
Last Trade: at
Volume: shares
Open: N/A
Close: N/A
Bid: N/A
Ask: N/A

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.

Where can I get it?
You can get version 1.02 (4/17/00) right here: getstockquote-1_02.tar.gz. This is the latest version. It's tarred and zipped and only about 5K. You can take a look at the readme right now if you want.

How do I install it?
Installing is about as easy as it gets: put the tarball where you want the script to live and then run:
tar zxvf getstockquote-1_02.tar.gz
You'll end up with this readme and the getstockquote script. Make sure the script is still executable and you're set.

What else does it need to run?
getstockquote needs Perl >5.005, patch 3 and the Finance::Quote Perl module installed. You may also have to install the LWP modules as well (they are required by Finance::Quote).

You can get everything you need at CPAN:

What operating systems will it run on?
I've run it on Linux (Red Hat 6.1, Intel) and Solaris (2.6, 2.7). I don't have any other unixes at my immediate disposal. It'll probably work on any OS that Perl 5.005 will run on (although I doubt it'll run on Windows or MacOS, and I have no interest in trying either OS). If you get it running on a platform not listed here, please let me know so I can update this page. If you had to tweak it at all to get it to work on a particular OS, that would be great info to have.

So how do I use it?
The general syntax is:
/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:

fontsize - Size of HTML font returned. These correlate to the regular HTML absolute sizes.
Possible values are:
1 = very small
2 = kinda small (default)
3 = normal size
4 = kinda large
5 = large
6 = damn big

verbose - Return either a small or large set of data.
Possible values are:
yes = return everything
no = return only symbol, last, high, low (default)

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.

What if I can't get it to work? What if I found a bug? What if I want a new feature? How do I contact the author?
If you can't get it to work, please let me know and I'll try to help you as much as possible. I can tell you already that if your using it as a server-side exec, your server must be configured for it (most http servers aren't set up to allow execs by default and you must explicitly turn them on, usually on a directory-by-directory basis).

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 wee@27.org.

What license is the script distributed under?
getstockquote is licensed under the GNU General Public License. You're free to do whatever you wish to it as long as you stay under the GPL umbrella.

Revision History
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
0.9 2000/04/11 Inital release


William Rhodes <mailto:wee@27.org>

Last updated: 2000/04/17 at 07:42:33 GMT