Finance-Quote
view release on metacpan or search on metacpan
lib/Finance/Quote/ASX.pm view on Meta::CPAN
# The JSON module will croak on errors, so use eval to trap this.
$data = eval{ decode_json($json) };
if ($@) {
$status = 0;
$error = "Failed to parse JSON data from ASX server '$url'. Error: '$@'.";
### ASX.pm Error: $error
return $status, $error, undef;
}
# Return valid, decoded data
$status = 1;
return $status, $error, $data;
}
# Internal function to push the ASX data elements into the Finance::Quote structure (%info)
sub process_asx_data {
my ($symbol, $data, $label_map, $info) = @_;
lib/Finance/Quote/Cdnfundlibrary.pm view on Meta::CPAN
$url = "$FUNDLIB_URL$mutual";
$reply = $ua->request(GET $url);
$te = new HTML::TableExtract(headers => ["NAVPS"],
slice_columns => 0);
# Make sure something is returned ##CAN exit more gracefully - add later##
return unless ($reply->is_success);
my $json = JSON->new;
my $data = decode_json($reply->decoded_content);
# If the fund is not found, "PriceAsOfDateString" is "0001-01-01T00:00"
if ( $$data{'PriceAsOfDateString'} eq "0001-01-01T00:00" )
{
$fundquote {$mutual,"success"} = 0;
$fundquote {$mutual,"errormsg"} = "Fund name $mutual not found";
next;
}
my $t = Time::Piece->strptime($$data{'PriceAsOfDateString'}, "%Y-%m-%dT%T");
lib/Finance/Quote/Fondsweb.pm view on Meta::CPAN
# The site check the user agent
$quoter->user_agent->agent("Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0");
my $reply = $quoter->user_agent->request(GET $url);
# Check response
unless ($reply->is_success) {
$info{ $symbol, "success" } = 0;
$info{ $symbol, "errmsg" } = join ' ', $reply->code, $reply->message;
} else {
# Parse the HTML tree
$tree->parse( $reply->decoded_content );
# Find data using xpath
# name
my $name = $tree->findvalue( '//h1[@class="fw--h1 fw--fondsModule-head-content-headline"]');
$info{ $symbol, 'name' } = $name;
# isin
my $isin_raw = $tree->findvalue( '//span[@class="text_bold"]');
my @isin = $isin_raw =~ m/^(\w\w\d+)\w./;
my $sym=$isin[0];
lib/Finance/Quote/Fondsweb.pm view on Meta::CPAN
}
$info{ $symbol, 'isin' } = $sym;
$info{ $symbol, 'symbol' } = $sym;
# date, isodate
my $raw_date = $tree->findvalue( '//i[@data-key="nav"]/..' );
my @date = $raw_date =~ m/.(\d\d)\.(\d\d)\.(\d\d\d\d)./;
$quoter->store_date(\%info, $symbol, {eurodate => "$date[0]/$date[1]/$date[2]"} );
# year_range, in this case use table extract
$te->parse($reply->decoded_content);
# the 6th table
my $details = $te->table(0, 6);
my $lastRowIndex = @{$details->rows} - 1;
# extract data with re
my $highest = decimalPeriod($details->cell($lastRowIndex - 1, 1));
my $lowest = decimalPeriod($details->cell($lastRowIndex, 1));
$info{ $symbol, "year_range" } = $lowest . ' - ' . $highest;
# nav, last, currency
my $raw_nav_currency = $tree->findvalue( '//div[@class="fw--fondDetail-price"]' );
lib/Finance/Quote/TreasuryDirect.pm view on Meta::CPAN
# my $post_data = [ "priceDate.month" => "4", "priceDate.day" => "13", "priceDate.year" => "2018", "submit" => "Show+Prices" ];
my $post_data = [ 'priceDate.month' => $m,
'priceDate.day' => $d,
'priceDate.year' => $y,
'submit' => 'Show Prices',
];
my $request = POST( $url, $post_data);
my $resp = $ua->request($request);
if ($resp->is_success) {
$content = $resp->decoded_content;
# print "[debug]: ", $content, "\n";
} else {
$info{$_, 'errormsg'} = 'Error contacting URL' for @symbols;
return wantarray() ? %info : \%info;
}
}
else {
my $url = 'https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate';
#my $data= 'priceDate.month=1&priceDate.day=4&priceDate.year=2021&submit=Show+Prices';
( run in 0.380 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )