Simple stock quote grabbing with Perl

Hackszine reader 3riador wrote in to recommend a quick and easy way to grab stock quotes using Perl and the Finance::Quote CPAN module. The codebase is actively maintained and has been around for some time, having first been distributed as part of GNUCash before becoming its own project.

Paul Fenwick, one of the GNUCash developers, had this to say in an article for The Perl Journal in 2000:

If you have a reason to watch the world's financial markets, and you know a little about perl, then you may find that the Finance::Quote package comes in handy. I personally use it to remind myself that I should never buy shares, as I have a good history of losing money on the stock exchange. However, you can use Finance::Quote to help track those tasty stock options you've been offered, or even to help you build dynamic artwork driven by fluctuations in the world markets.

Near as I can tell, the dynamic artwork that's referred to is the Stock Puppets presentation which was shown at 2000s Burning Man event (can anyone confirm this?). The idea was to have large marionettes controlled directly by stock market data, some servos, Basic Stamp microcontrollers, and IBM Thinkpads pulling market data using the Finance::Quote library.

To use Finance::Quote in your own projects is a simple task. Here's a few lines of code that will print the current price of Google shares:

#!/usr/bin/perl -w

use strict;
use Finance::Quote;


my $q = Finance::Quote->new();
my %data = $q->fetch('usa', 'GOOG');
print $data{'GOOG', 'price'} . "\n";

The Dabbler Blog has more information on installation and basic usage, and The Perl Journal article is a good resource for those wishing to delve any deeper.

Finance::Quote Perl Library
Dabbler Blog - Fast and Simple Stock Quotes Using Perl
Finance::Quote Article In The Perl Journal
Stock Puppets

Posted by Jason Striegel | Oct 23, 2008 07:53 PM
Data, Life, Online Investing, Perl | Permalink | Comments (3) Bookmark and Share

Recent Entries

Comments

Newest comments listed first.

Posted by: tim on October 23, 2008 at 9:54 PM

Title Error

I love the error on the title! Hilarious!


Posted by: Jason Striegel on October 23, 2008 at 10:07 PM

re: title error

Crap. Well, everyone still needs socks in a recession.


Posted by: Andy Lester on November 14, 2008 at 8:56 AM

Andy Lester

Here's a one-line that could be made into a shell alias if necessary:


perl -MFinance::Quote -le'print +({Finance::Quote->new->fetch(q{usa},$ARGV[0])})->{$ARGV[0],q{price}}' $@


That's all one line.


Leave a comment



Bloggers

Welcome to the Hacks Blog!

Brian Jepson.Brian Jepson


Jason Striegel.Jason Striegel


Philip Torrone.Phillip Torrone



See all of the books in the Hacks Series!
Advertise here.

Recent Posts

www.flickr.com
photos in Hacks More photos in Hacks