# Finance::Quote Perl module to retrieve prices of funds from DKB # Copyright (C) 2016 Matthias Merz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA package Finance::Quote::DKB; use strict; use HTML::TreeBuilder::XPath; my $BASE_URL = "https://dkb.mdgms.com/MIS/?id_instrument=19035880&id=0107980&pid=DKB_fnd_profile&id_notation=23679474"; sub methods {return ('dkb' => \&dkb, 'europe' => \&dkb);} sub labels { return (dkb=>[qw/name date price currency/]); } sub dkb { my $quoter = shift; # The Finance::Quote object. my @stocks = @_; my $ua = $quoter->user_agent(); my %info; foreach my $stock (@stocks) { my $response = $ua->get($BASE_URL . "&search_value=" . $stock); #print $response->content, "\n"; $info{$stock,"success"} = 0; if (!$response -> is_success()) { $info{$stock,"errormsg"} = "HTTP failure"; } else { $info{$stock,"success"} = 1; $info{$stock,'symbol'} = $stock; my $parser = HTML::TreeBuilder::XPath->new_from_content($response->decoded_content); my @names = $parser->findnodes( '//span[@class="dkbPortraitName"]'); if (@names) { $info{$stock,'name'} = $names[0]->as_text; }; my @prices = $parser->findnodes( '//span[@class="dkbPortraitPrice"]'); if (@prices) { my $pricestr = $prices[0]->as_text; my @splitvals = ( $pricestr =~ /((\d|,|\.)*)\s*/g); if (@splitvals) { $info{$stock,'price'} = $splitvals[0]; $info{$stock,'last'} = $splitvals[0]; if ($pricestr =~ /EUR/) { $info{$stock,'currency'} = 'EUR'; } } }; my @dates = $parser->findnodes( '//span[@class="dkbPortraitDate"]'); if (@dates) { #$info{$stock,'date'} = $dates[0]->as_text; $quoter->store_date(\%info, $stock, {eurodate => $dates[0]->as_text}); }; #$info{$stock,'last'} = '18.70'; #$info{$stock,'currency'} = 'EUR'; } } return wantarray ? %info : \%info; } 1; =head1 NAME Finance::Quote::DKB - Obtain fonds quotes from DKB. =head1 SYNOPSIS use Finance::Quote; $q = Finance::Quote->new("DKB"); %info = Finance::Quote->fetch("dkb","A0M9A2"); =head1 DESCRIPTION This module obtains fund prices from DKB, http://www.dkb.de/. =head1 LABELS RETURNED The following labels may be returned by Finance::Quote::DKB: name, date, price, last, method. =head1 SEE ALSO DKB, http://www.dkb.de/ Finance::Quote; =cut