Skip Menu |

This queue is for tickets about the Finance-Quote CPAN distribution.

Report information
The Basics
Id: 51757
Status: open
Priority: 0/
Queue: Finance-Quote

People
Owner: Nobody in particular
Requestors: strainu10 [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: New module to fetch the value of Romanian Mutual Funds
Hi, I made a new module to fetch the values for some Romanian Mutual Funds from the www.kmarket.ro site. Only the funds listed at http://www.kmarket.ro/fonduri/fonduri.php are covered. Because this is not an exchange, there are no symbols and instead, you have to use the name of the funds as they are mentioned at the above location. The case is not relevant. I'm attaching the module and the test file. Thanks, Andrei
Subject: ROFunds.pm
#!/usr/bin/perl -w # This modules is based on the Finance::Quote::ASEGR module # # The code has been modified by Andrei Cipu <strainu@strainu.ro> to be able to # retrieve stock information from the Bucharest Exchange in Romania. # # 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., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA require 5.005; use strict; package Finance::Quote::ROFunds; use vars qw($VERSION $ROFUNDS_URL); use LWP::UserAgent; use HTTP::Request::Common; use HTML::TableExtract; $VERSION='0.1'; my $ROFUNDS_URL = 'http://www.kmarket.ro/fonduri/sumare/sumarfonduri12112009.htm'; sub methods { return ( romania => \&rofunds, rofunds => \&rofunds, europe => \&rofunds); } { my @labels = qw/name last date isodate p_change currency method exchange/; sub labels { return (romania => \@labels, rofunds => \@labels, europe => \@labels); } } sub rofunds { my $quoter = shift; my @stocks = @_; my (%info,$reply,$url,$te,$ts,$row,@cells, $ce); my($my_date,$my_last,$my_p_change); my $ua = $quoter->user_agent(); $url = $ROFUNDS_URL; foreach my $stocks (@stocks) { $reply = $ua->request(GET $url); if ($reply->is_success) { $te = new HTML::TableExtract(); $te->parse($reply->content); unless ( $te->tables) { $info {$stocks,"success"} = 0; $info {$stocks,"errormsg"} = "Stock name $stocks not found"; next; } $ts = $te->first_table_found(); foreach $row ($ts->rows) { @cells = @$row; $ce = $cells[1]; #we found the date if(substr($ce, 0, 4) eq "Data") { $my_date = $cells[2]; } #the fund name is in the second column if(substr(lc($ce), 0, length($stocks)) eq lc($stocks)) { $my_last = $cells[3]; $my_p_change = $cells[4]; } } $info{$stocks, "success"} =1; $info{$stocks, "exchange"} ="Romanian Funds"; $info{$stocks, "method"} ="rofunds"; $info{$stocks, "name"} =$stocks; $info{$stocks, "last"} =$my_last; $info{$stocks, "close"} =$my_last; $info{$stocks, "p_change"} =$my_p_change; $quoter->store_date(\%info, $stocks, {eurodate => $my_date}); $info{$stocks,"currency"} = "RON";#TODO this will not work when funds denominated in EUR will appear. } else { $info{$stocks, "success"}=0; $info{$stocks, "errormsg"}="Error retreiving $stocks "; } } return wantarray() ? %info : \%info; return \%info; } =head1 NAME Finance::Quote::ROFUNDS Obtain weekly values for the Romanian open Mutual Funds =head1 SYNOPSIS use Finance::Quote; $q = Finance::Quote->new; %info = Finance::Quote->fetch("rofunds","bt index"); # Only query ROFUNDS %info = Finance::Quote->fetch("romania","simfonia 1"); # Failover to other sources OK. =head1 DESCRIPTION This module fetches information from the Kmarket site, http://www.kmarket.ro. Only the funds listed at http://www.kmarket.ro/fonduri/fonduri.php are available. This module is loaded by default on a Finance::Quote object. It's also possible to load it explicity by placing "ROFUNDS" in the argument list to Finance::Quote->new(). This module provides both the "rofunds" and "romania" fetch methods. Please use the "romania" fetch method if you wish to have failover with future sources for Romanian stocks. Using the "rofunds" method will guarantee that your information only comes from the kmarket site. Information obtained by this module may be covered by www.kmarket.ro terms and conditions See http://www.kmarket.ro/ for details. =head1 LABELS RETURNED The following labels may be returned by Finance::Quote::BSERO : name, last, date, p_change, currency, method, exchange. =head1 SEE ALSO Kmarket, http://www.kmarket.ro =cut
Subject: ROFUNDS.t
#!/usr/bin/perl -w use strict; use Test; use Data::Dumper; BEGIN {plan tests => 26}; use Finance::Quote; # Test BSERO functions. my $q = Finance::Quote->new(); my @stocks = ("BT Index", "SIMFONIA 1", "OPORTUNITATI NATIONALE"); my %regexps = ( "BT Index" => qr/\bBT Index\b/, "SIMFONIA 1" => qr/\bSIMFONIA 1\b/, "OPORTUNITATI NATIONALE" => qr/\bOPORTUNITATI NATIONALE\b/, ); my %quotes = $q->fetch("rofunds", @stocks); ok(%quotes); foreach my $stock (@stocks) { print $quotes{$stock, "date"}."\n"; my $name = $quotes{$stock, "name"}; print "#Testing $stock: $name\n"; my $regexp = $regexps{$stock}; ok($name =~ /$regexp/i); ok($quotes{$stock, "exchange"} eq 'Romanian Funds'); ok($quotes{$stock, "method"} eq 'rofunds'); ok($quotes{$stock, "last"} > 0); ok($quotes{$stock, "p_change"} =~ /^-?\d+\.\d+$/); ok($quotes{$stock, "success"}); } # Check that a bogus stock returns no-success. %quotes = $q->fetch("tsx", "BOGUS"); ok(! $quotes{"BOGUS","success"});
Just realised I had put a static URL. Uploading the new version...
#!/usr/bin/perl -w # This modules is based on the Finance::Quote::ASEGR module # # The code has been modified by Andrei Cipu <strainu@strainu.ro> to be able to # retrieve stock information from the Bucharest Exchange in Romania. # # 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., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA require 5.005; use strict; package Finance::Quote::ROFunds; use vars qw($VERSION $ROFUNDS_URL); use LWP::UserAgent; use HTTP::Request::Common; use HTML::TableExtract; use Date::Manip; Date::Manip::Date_Init("TZ=GMT"); $VERSION='0.1'; my $ROFUNDS_URL = 'http://www.kmarket.ro/fonduri/sumare/sumarfonduri'; sub methods { return ( romania => \&rofunds, rofunds => \&rofunds, europe => \&rofunds); } { my @labels = qw/name last date isodate p_change currency method exchange/; sub labels { return (romania => \@labels, rofunds => \@labels, europe => \@labels); } } sub rofunds { my $quoter = shift; my @stocks = @_; my (%info,$reply,$url,$te,$ts,$row,@cells, $ce, $last_date); my($my_date,$my_last,$my_p_change); my $ua = $quoter->user_agent(); $url = $ROFUNDS_URL; $last_date = UnixDate( ParseDate("last Thursday"), "%d%m%Y" ); foreach my $stocks (@stocks) { $reply = $ua->request(GET $url.join('',$last_date,".htm")); if ($reply->is_success) { $te = new HTML::TableExtract(); $te->parse($reply->content); unless ( $te->tables) { $info {$stocks,"success"} = 0; $info {$stocks,"errormsg"} = "Stock name $stocks not found"; next; } $ts = $te->first_table_found(); foreach $row ($ts->rows) { @cells = @$row; $ce = $cells[1]; #we found the date if(substr($ce, 0, 4) eq "Data") { $my_date = $cells[2]; } #the fund name is in the second column if(substr(lc($ce), 0, length($stocks)) eq lc($stocks)) { $my_last = $cells[3]; $my_p_change = $cells[4]; } } $info{$stocks, "success"} =1; $info{$stocks, "exchange"} ="Romanian Funds"; $info{$stocks, "method"} ="rofunds"; $info{$stocks, "name"} =$stocks; $info{$stocks, "last"} =$my_last; $info{$stocks, "close"} =$my_last; $info{$stocks, "p_change"} =$my_p_change; $quoter->store_date(\%info, $stocks, {eurodate => $my_date}); $info{$stocks,"currency"} = "RON";#TODO this will not work when funds denominated in EUR will appear. } else { $info{$stocks, "success"}=0; $info{$stocks, "errormsg"}="Error retreiving $stocks "; } } return wantarray() ? %info : \%info; return \%info; } =head1 NAME Finance::Quote::ROFUNDS Obtain weekly values for the Romanian open Mutual Funds =head1 SYNOPSIS use Finance::Quote; $q = Finance::Quote->new; %info = Finance::Quote->fetch("rofunds","bt index"); # Only query ROFUNDS %info = Finance::Quote->fetch("romania","simfonia 1"); # Failover to other sources OK. =head1 DESCRIPTION This module fetches information from the Kmarket site, http://www.kmarket.ro. Only the funds listed at http://www.kmarket.ro/fonduri/fonduri.php are available. This module is loaded by default on a Finance::Quote object. It's also possible to load it explicity by placing "ROFUNDS" in the argument list to Finance::Quote->new(). This module provides both the "rofunds" and "romania" fetch methods. Please use the "romania" fetch method if you wish to have failover with future sources for Romanian stocks. Using the "rofunds" method will guarantee that your information only comes from the kmarket site. Information obtained by this module may be covered by www.kmarket.ro terms and conditions See http://www.kmarket.ro/ for details. =head1 LABELS RETURNED The following labels may be returned by Finance::Quote::BSERO : name, last, date, p_change, currency, method, exchange. =head1 SEE ALSO Kmarket, http://www.kmarket.ro =cut