I am writing an app that uses Finance::QuoteHist to fetch historical stock prices.  My 
problem is that I want to read from a database a list of symbols that at last count 
was over 1500 entries long and I run out of memory trying to fetch all of this data at 
once.  It appears that there is no way of setting the list of quotes other then using 
the new function which would like an array reference of stock symbols.  What I would 
like to do is select the symbols list from the database and then fetch the data for 
each symbol one at a time instead of all at once, does any one have any suggestions?

Here is the code

#!/usr/bin/perl -w
use strict;
use DBI;
use Finance::QuoteHist;


my $user="me";
my $password="pass";
my $database="stocks";
my @data;
my $i=0;

my $dbh=DBI->connect("dbi:mysql:$database",$user,$password) or die "Cannot connect to 
database";
$dbh->{raiserror} = 1;

my $sth=$dbh->prepare("Select symbol from symbols;");
$sth->execute();
while(my @row=$sth->fetchrow_array()){
 $data[$i]=$row[0];
 $i++;
}

#Here is what I am having trouble with.
my $q = new Finance::QuoteHist(
 symbols =>\@data,  
 start_date => '01/01/01',
 end_date => 'today');

my @quotes = $q->quotes();

my $sth=$dbh->prepare("INSERT INTO 
stocks(symbol,date,open,high,low,close,volume,adjusted) VALUES(?,?,?,?,?,?,?,?);");

for my $i (0 .. $#quotes){
 
$sth->execute($quotes[$i][0],$quotes[$i][1],$quotes[$i][2],$quotes[$i][3],$quotes[$i][4],$quotes[$i][5],$quotes[$i][6],$quotes[$i][7])||
 die "error: ", $dbh->errstr;
}
#if any one knows how to make this a little bit prettier I would also appreciate it!!

$dbh->disconnect();


Thanks in advance

Will


Reply via email to