(Disclaimer: Securities indicated below are just examples and are not recommendations by the author. Obtain and read the prospectus before investing. For SEC filings by companies and mutual funds, visit the EDGAR database.)
Note: Perl 5.004 or later is required. However, the script requires no modules are than a few that are present in the standard library.
This script obtains quotes from the Yahoo! Finance quote server. It uses the CSV (comma-separated values) data available via the "Download Spreadsheet Format" link on that site.
Note that the script itself could have been written far more easily using the LWP module, which is available at CPAN. Thus it serves only to demonstrate how a web client might communicate with a CGI program on a remote site using a simple GET query.
January 12, 1999
quote2.pl ticker [ticker...]
The script takes one or more ticker symbols on the command line. These ticker symbols may be stocks, mutual funds, or anything that Yahoo! Finance accepts.
Tue Jan 12 01:50:45 (sam:cheah):~ $ quote2.pl mqifx smnxx xon Connecting to quote.yahoo.com (204.71.200.146) port 80... Connected. Ticker: MQIFX Last trade: 17.01 Last trade at: 1/11/1999 5:52PM Change: -0.02 (-0.12%) Opened at: N/A Day range: N/A - N/A Volume: N/A Ticker: SMNXX Last trade: 4.65 Last trade at: 1/11/1999 5:54PM Change: N/A (0.00%) Opened at: N/A Day range: N/A - N/A Volume: N/A Ticker: XON Last trade: 71.25 Last trade at: 1/11/1999 4:31PM Change: -3.0625 (-4.12%) Opened at: 72.75 Day range: 70.8125 - 73.5 Volume: 5727200 Tue Jan 12 01:50:47 (sam:cheah):~ $
By popular request, a CGI-ready version of the script is available here.
A live demo is not available at this time but assuming I have installed it into my cgi-bin directory, the following URL will bring up a form where you can enter ticker symbols to query:
http://localhost/cgi-bin/quotcgi.pl
And the following URL will display information on the same trio of securities as above:
http://localhost/cgi-bin/quotcgi.pl?tickers=MQIFX+SMNXX+XON
Send me e-mail and I'll look into it.