Finance-YahooQuote
view release on metacpan or search on metacpan
YahooQuote.pm view on Meta::CPAN
'Last Trade (Real-time) with Time'=> 'k1',
'Bid (Real-time)' => 'b3',
'Ask (Real-time)' => 'b2',
'Change Percent (Real-time)' => 'k2',
'Change (Real-time)' => 'c6',
'Holdings Value (Real-time)' => 'v7',
"Day's Value Change (Real-time)" => 'w4',
'Holdings Gain Pct (Real-time)' => 'g5',
'Holdings Gain (Real-time)' => 'g6',
"Day's Range (Real-time)" => 'm2',
'Market Cap (Real-time)' => 'j3',
'P/E (Real-time)' => 'r2',
'After Hours Change (Real-time)' => 'c8',
'Order Book (Real-time)' => 'i5',
'Stock Exchange' => 'x' # old default
);
# Let the user define which colums to retrive from yahoo
#
sub getcustomquote {
my $symbols = shift;
my $columns = shift;
my $format = join('',map {$fields{$_}} @{$columns});
my $qr = readYahoo($symbols,$format);
return wantarray() ? @$qr : $qr;
}
# get quotes for all symbols in array
sub getquote {
my @symbols = @_;
my $format = $QURLformat; ## Old default from variable
my $qr = readYahoo(\@symbols,$format);
return wantarray() ? @$qr : $qr;
}
# Input: A single stock symbol
# Output: An array, containing the list elements mentioned above.
sub getonequote {
my @x;
@x = &getquote($_[0]);
return wantarray() ? @{$x[0]} : \@{$x[0]} if @x;
}
BEGIN { # Local variant of LWP::UserAgent that
use LWP; # checks for user/password if document
package RequestAgent; # this code taken from lwp-request, see
no strict 'vars'; # the various LWP manual pages
@ISA = qw(LWP::UserAgent);
sub new {
my $self = LWP::UserAgent::new(@_);
$self->agent("Finance-YahooQuote/0.18");
$self;
}
sub get_basic_credentials {
my $self = @_;
if (defined($PROXYUSER) and defined($PROXYPASSWD) and
$PROXYUSER ne "" and $PROXYPASSWD ne "") {
return ($PROXYUSER, $PROXYPASSWD);
} else {
return (undef, undef)
}
}
}
1;
__END__
=head1 NAME
Finance::YahooQuote - Get stock quotes from Yahoo! Finance
=head1 SYNOPSIS
use Finance::YahooQuote;
# setting TIMEOUT and PROXY is optional
$Finance::YahooQuote::TIMEOUT = 60;
$Finance::YahooQuote::PROXY = "http://some.where.net:8080";
@quote = getonequote $symbol; # Get a quote for a single symbol
@quotes = getquote @symbols; # Get quotes for a bunch of symbols
useExtendedQueryFormat(); # switch to extended query format
useRealtimeQueryFormat(); # switch to real-time query format
@quotes = getquote @symbols; # Get quotes for a bunch of symbols
@quotes = getcustomquote(["DELL","IBM"], # using custom format
["Name","Book Value"]); # note array refs
=head1 DESCRIPTION
B<NOTE>: As of November 2017, the module is no longer all that useful
as Yahoo! decided to halt the API service it relies on.
This module gets stock quotes from Yahoo! Finance. The B<getonequote>
function will return a quote for a single stock symbol, while the
B<getquote> function will return a quote for each of the stock symbols
passed to it. B<getcustomquote> allows to specify a format other than
the default to take advantage of the extended range of available information.
The download operation is efficient: only one request is made even if
several symbols are requested at once. The return value of
B<getonequote> is an array, with the following elements:
0 Symbol
1 Company Name
2 Last Price
3 Last Trade Date
4 Last Trade Time
5 Change
6 Percent Change
7 Volume
8 Average Daily Vol
9 Bid
10 Ask
11 Previous Close
( run in 1.207 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )