RSS Subscription
Linux Howtos & Tutorials

Enter your email:

Delivered by


NOTE:New tutorials are from LinuxCareer.com

Poll

Do you own or wish to have iPhone?
 


Linux eBooks FREE Download
A guide to programming Linux kernel modules
Introduction to Linux - A Hands on Guide
A Newbie's Getting Started Guide to Linux

Linux from Scratch - Create Your Own Linux System - Free eBook

Linux: The Hacking Solution (v.3.0)

SQLite 3 with PHP Essential Training – Free Video Training Tutorials

This guide will introduce you to the world of GNU/Linux

The GNU/Linux Advanced Administration

A Complete Beginner's Manual for Ubuntu 10.04 (Lucid Lynx)

Advanced Bash-Scripting Guide

Set up, maintain, and secure a small office email server

Partner Linux Sites:
How-To.LinuxCareer.com
Jobs.LinuxCareer.com
TuxMachines
Monsterb
LinuxBloggers
AdamsInfo
LinuxScrew
All For Linux

Fetch stock quotes with perl Finance Quote module

This simple example uses Finance::Quote Perl module to fetch real time stock quotes for a companies listed in a CSV file. First we need to install Finance::Quote perl module: Feel free to get from a cpan or use package management tool to get from your linux distribution's repository. For debian o ubuntu do:

# apt-get install libfinance-quote-perl

Here is our sample CSV file containing list of ticker and exchange values:

stocks.csv:

AAON,NASDAQ
CMS,NYSE
TDSC,NASDAQ
CWST,NASDAQ
BDC,NYSE
EDN,NYSE

create a following perl script and save it as fetch-stock-price.pl:

#!/usr/bin/perl

use Finance::Quote;

my $q = Finance::Quote->new();
open (FIN, $ARGV[0]) || die ("Could not open $ARGV[0]");

while ($line = <FIN>) { ($field1,$field2) = split ',', $line;

my %hash = ( $field1 => $field2 ); chomp(%hash); foreach my $i (keys %hash) { my %data = $q->fetch( $hash{$i}, $i); print $hash{$i} . " " . $i . ": " . $data{$i, 'price'} . "\n"; } }
close (FIN);

At this point we need this script executable and execute it with an argument stocks.csv:

$ chmod +x fetch-stock-price.pl
$ ./fetch-stock-price.pl stocks.csv

OUTPUT:

NASDAQ AAON: 25.10
NYSE CMS: 17.95
NASDAQ TDSC: 27.10
NASDAQ CWST: 4.54
NYSE BDC: 33.06
NYSE EDN: 10.21

Share this linux post:

Submit Fetch stock quotes with perl Finance Quote module in Delicious Submit Fetch stock quotes with perl Finance Quote module in Digg Submit Fetch stock quotes with perl Finance Quote module in FaceBook Submit Fetch stock quotes with perl Finance Quote module in Google Bookmarks Submit Fetch stock quotes with perl Finance Quote module in Stumbleupon Submit Fetch stock quotes with perl Finance Quote module in Technorati Submit Fetch stock quotes with perl Finance Quote module in Twitter
 
Comments for this page are closed !!!
Please visit our new Linux Forum for additional help or discussion.


Linux eBooks FREE Download