bulrush has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Finance::Quote 1.35 with Strawberry Perl 5.18.2 (built for MSwin32-x86-multi-thread-64int) in Windows 8 cmd window. Also have McAfee Security Center 12.8.988, McAfee Anti-Virus 16.8.819, McAfee Personal Firewall 13.8. Strawberry Perl is running on a flash drive if that matters.

Here's my subroutine.

sub getquote {my($sym,$qdate)=@_; # Symbol is 'googl' in lowercase and date is '201 +40822'. my($dt,$quote,$s,$t,$procname,$exch); my(%info,@exchanges); $procname="getquote"; $sym=uc($sym); # First qet quote. # Do not load Yahoo::Base. #$quote=Finance::Quote->new("-defaults","Fidelity","Yahoo::USA","Tiaac +ref"); $quote=Finance::Quote->new; # Loads 116 default exchanges. @exchanges=sort($quote->sources); # See all exchanges here. $quote->timeout(60); $quote->require_labels(qw/success errormsg price date exchange name/); $quote->set_currency("USD"); $exch="usa"; %info=$quote->fetch($exch,$sym,'A','MSFT'); if (! %info) { $s="$procname ERROR: No information returned for symbol $sym from +$exch"; writeerr($s); return; # getquote() } $dt=$info{$sym,'date'}; print "Price of $sym is ".$info{$sym,'price'}." for ".$dt."\n"; # DEBU +G return; # getquote }
Right after the $quote->fetch I do at the debugger prompt "print Dumper(\%info)" and I get this: "$VAR1 = {};" which indicates the hash has nothing in it.

  1. Has anyone else gotten F::Q working in a command box on Win 8?
  2. Any ideas what may be going wrong? I'm stumped.

Thanks.


Got it. This line:
$quote->require_labels(qw/success errormsg price date exchange name/);
has invalid labels but F::Q doesn't give an error msg. So this line works:
$quote->require_labels(qw/price date exchange name/);
I can also remove the above line and F::Q still returns all data it can about the equity. F::Q really needs better error checking, but I think I have to have an account to file a bug report.
Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)

Replies are listed 'Best First'.
Re: Finance::Quote returns nothing and no error
by Athanasius (Archbishop) on Sep 06, 2014 at 13:32 UTC

    Hello bulrush,

    By making some changes to your code I was able to get this result (running from the command line under Windows 8.1):

    23:25 >perl 1001_SoPW.pl Price of GOOGL is 597.78 for 09/05/2014 23:25 >

    Here is my revised script:

    The major change is to the line:

    $quote->require_labels(qw/success errormsg price date exchange name/);

    which I replaced with this line:

    $quote->require_labels(qw/price date high low volume/);

    copied from the “SYNOPSIS” section of the module’s documentation. I conclude that the module works, you just need to tweak the label settings.

    BTW: Please note that Perl variables are best declared at the point of first use. Also, the second parameter to sub getquote is unused.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      Hi Athanasius, I tried running your code on windows 7 enterprise (64 bit) but its not able to get the data. Please see below the output.
      C:\strawberryPerl\scripts>perl getStockPrice2.pl getquote ERROR: No information returned for symbol GOOGL from usa at g +etStockPri ce2.pl line 24. C:\strawberryPerl\scripts>
      Here is the code (same as yours)
      use strict; use warnings; use Finance::Quote; getquote('googl', '20140822'); my $s; sub getquote { my ($sym, $qdate) = @_; $sym = uc($sym); my $quote = Finance::Quote->new; my @exchanges = sort($quote->sources); $quote->timeout(60); $quote->require_labels(qw/price date high low volume/); $quote->set_currency('USD'); my $exch = 'usa'; my %info = $quote->fetch($exch, $sym, 'A', 'MSFT'); if (!%info) { $s = "getquote ERROR: No information returned for symbol $sym +from $exch"; warn $s; return; } my $dt = $info{$sym, 'date'}; print "Price of $sym is " . $info{$sym, 'price'} . ' for ' . $dt . + "\n"; # DEBUG }

        Looks like the API was terminated last year. Also see Finance::YahooQuote which now says

        NOTE: As of November 2017, the module is no longer all that useful as Yahoo! decided to halt the API service it relies on.

        Some info is available using yahoo_json if you have a recent version of Finance::Quote

        use strict; use warnings; use Finance::Quote; use Data::Dumper; printf "Version : %s\n", $Finance::Quote::VERSION; my $q = Finance::Quote->new(); $q->timeout(60); $q->set_currency("USD"); my $stock = 'googl'; my $info = $q->fetch("yahoo_json",$stock); print Dumper $info; printf "Latest price for %s is %s", $info->{$stock,'name'},$info->{$st +ock,'last'};
        poj