in reply to Finance::Quote returns nothing and no error

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:

use strict; use warnings; use Finance::Quote; getquote('googl', '20140822'); 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) { my $s = "getquote ERROR: No information returned for symbol $s +ym from $exch"; warn $s; return; } my $dt = $info{$sym, 'date'}; print "Price of $sym is " . $info{$sym, 'price'} . ' for ' . $dt . + "\n"; # DEBUG }

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,

Replies are listed 'Best First'.
Re^2: Finance::Quote returns nothing and no error
by pshen (Initiate) on Oct 11, 2018 at 07:29 UTC
    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