Subject: | Proposed new module: bamosz |
I'd like to propose this module to get included in Finance::Quote.
I wrote it a few years ago, and using it since then on daily basis,
updated to work with 1.16.
This modules makes it possible to get daily quotes for every fund sold
in Hungary. Data is acquired from Bamosz (Association of Hungarian
Investment Fund and Asset Management Companies).
Subject: | Bamosz.pm |
#!/usr/bin/perl -w
package Finance::Quote::Bamosz;
require 5.005;
use strict;
use LWP::UserAgent;
use HTML::TableExtract;
use HTTP::Request::Common;
use vars qw/$VERSION $BAMOSZ_FUNDS_URL/;
$VERSION = '1.00';
$BAMOSZ_FUNDS_URL = "http://bamosz.econet.hu/index1.php";
sub methods { return ( bamosz => \&bamosz,
europe => \&bamosz); }
{
my @labels = qw /name date nav method/;
sub labels { return (bamosz => \@labels,
europe => \@labels); }
}
sub bamosz
{
my $quoter = shift;
my @funds = @_;
return unless @funds;
my $ua = $quoter->user_agent;
my %info;
my $response = $ua->request(GET $BAMOSZ_FUNDS_URL);
if ($response->is_success)
{
#my $te = new HTML::TableExtract( headers => [qw/Alap "Nettó eszközérték" Dátum Árfolyam "Hozam<br>3 hó" "Hozam<br>6 hó" "Hozam<br>12" hó/]);
my $te = new HTML::TableExtract( headers => [qw/Alap Dátum Árfolyam/]);
$te->parse($response->content);
my %found_funds;
foreach my $ts ($te->table_states) {
foreach my $row ($ts->rows) {
my $name = $$row[0];
$name = _translate_name($name);
$found_funds{$name, "name"} = $$row[0];
$found_funds{$name, "nav"} = $$row[2];
$found_funds{$name, "date"} = $$row[1];
}
}
foreach my $fund (@funds)
{
my $fund_id = _translate_name($fund);
if (defined ($found_funds{$fund_id, "name"})) {
my $name = $found_funds{$fund_id, "name"};
my $nav = $found_funds{$fund_id, "nav"};
my $date = $found_funds{$fund_id, "date"};
# Leave only digits and comma in the prize field
$nav =~ s/[^\d,]//g;
$nav =~ tr/,/./;
# Convert date into US format mm/dd/year
$date =~ /(\d{4})\.(\d{2})\.(\d{2})/;
$date = $2."/".$3."/".$1;
# Strip leading and trailing whitespace from name
$name =~ s/^\s*(.*?)\s*$/$1/;
$info{$fund, "symbol"} = $fund_id;
$info{$fund, "name"} = $name;
$info{$fund, "nav"} = $nav;
$info{$fund, "date"} = $date;
$info{$fund, "currency"} = "HUF";
$info{$fund, "method"} = "bamosz";
$info{$fund, "success"} = 1;
} else {
$info{$fund, "success"} = 0;
$info{$fund, "errormsg"} = "Not found";
}
}
}
else {
foreach my $fund (@funds)
{
$info{$fund, "success"} = 0;
$info{$fund, "errormsg"} = "HTTP error";
}
}
return wantarray() ? %info : \%info;
}
sub _translate_name
{
my $name = shift;
$name =~ tr/áíûõüöúóéÁÍÛÕÜÖÚÓÉ/aiuououoeaiuououoe/;
$name =~ tr/a-z/A-Z/;
$name =~ s/[^\w\d]//g;
return $name;
}
1;
=head1 NAME
Finance::Quote::Bamosz - Obtain hungarian fund prices from bamosz.econet.hu
=head1 SYNOPSYS
use Finance::Quote;
$q = Finance::Quote->new;
%stockinfo = $q->fetch("bamosz","BUDAPEST I");
=head1 DESCRIPTION
This modul obtains information from the Association of Fund Management
Companies in Hungay (BAMOSZ) http://bamosz.econet.hu.
Information returned by this module is governed by BAMOSZ's terms and
conditions.
=head1 LABELS RETURNED
The following labels are returned by Finance::Quote::Bamosz:
name, symbol, date, price, nav
=head1 NOTE
Since there aren't any common symbols for these funds, as symbol the modul
returns the translated name of the fund. All whitespaces, and non word or
non digit caracters are removed, and special hungarian characters are
translated to them ascii pairs. For example, the symbol of the fund named
"K&H Aranykosár" will be "KHARANYKOSAR". When retrieving information trough
fetch, one could use both formats or anything else, that could be translated
to the same value as used on the website.
=head1 SEE ALSO
BAMOSZ http://www.bamosz.hu, http://bamosz.econet.hu
=cut