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 "Ca
+nnot 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,cl
+ose,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
Edit: chipmunk 2001-07-16
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.