Skip Menu |
 

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

Report information
The Basics
Id: 44798
Status: patched
Worked: 30 min
Priority: 0/
Queue: Finance-Quote

People
Owner: eco [...] ecocode.net
Requestors: strainu10 [...] gmail.com
Cc:
AdminCc:

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



Subject: Module for Bucharest Stock Exchange (BSE)
Download (untitled) / with headers
text/plain 501b
Hi, I've created a module for the Bucharest Stock Exchange stocks. As I'm not very good in Perl, I've based it on the Athens Stock Exchange module. I've tested the code with the attached tester (self-made) and with GnuCash and it works fine. This code does have a minor problem though - the module name is seen as "bsero" (no caps) instead of "BSERO" as I would expect. I couldn't find the problem, but I consider it minor. If you have the time, perhaps you can look into it. Thanks, Andrei Cipu
Subject: BSERO.pm
Download BSERO.pm
text/x-perl 5.6k
#!/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::BSERO; use vars qw($VERSION $BSERO_URL); use LWP::UserAgent; use HTTP::Request::Common; use HTML::TableExtract; $VERSION='0.1'; my $BSERO_URL = 'http://www.bvb.ro/mobile/m_SecurityDetails.aspx?'; sub methods { return ( romania => \&bsero, bsero => \&bsero, europe => \&bsero); } { my @labels = qw/name last date isodate p_change open high low close volume currency method exchange/; sub labels { return (romania => \@labels, bsero => \@labels, europe => \@labels); } } sub bsero { my $quoter = shift; my @stocks = @_; my (%info,$reply,$url,$te,$ts,$row,@cells, $ce); my($my_date,$my_last,$my_p_change,$my_volume,$my_high,$my_low,$my_open); my $ua = $quoter->user_agent(); $url = $BSERO_URL; foreach my $stocks (@stocks) { $reply = $ua->request(GET $url.join('',"s=",$stocks)); 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; # The date is not a number, so we don't bother modifying it if($cells[0] eq 'Data'){ $my_date = $cells[1]; } #The rest of the data needs to be modified else { foreach $ce (@cells) { next unless $ce; $ce =~ s/\.//; #remove thouthand separator $ce =~ s/,/\./g; #replace european decimal separator with american ones } #go through each row and get the data if($cells[0] eq 'Ultimul pret'){ $my_last = $cells[1]; } if($cells[0] eq 'Var (%)'){ $my_p_change = $cells[1]; } if($cells[0] eq 'Volum'){ $my_volume = $cells[1]; } if($cells[0] eq 'Pret maxim'){ $my_high = $cells[1]; } if($cells[0] eq 'Pret minim'){ $my_low = $cells[1]; } if($cells[0] eq 'Pret deschidere'){ $my_open = $cells[1]; } } } $info{$stocks, "success"} =1; $info{$stocks, "exchange"} ="Bucharest Stock Exchange"; $info{$stocks, "method"} ="bsero"; $info{$stocks, "name"} =$stocks; $info{$stocks, "last"} =$my_last; $info{$stocks, "close"} =$my_last; $info{$stocks, "p_change"} =$my_p_change; $info{$stocks, "volume"} =$my_volume; $info{$stocks, "high"} =$my_high; $info{$stocks, "low"} =$my_low; $info{$stocks, "open"} =$my_open; $quoter->store_date(\%info, $stocks, {eurodate => $my_date}); $info{$stocks,"currency"} = "RON"; } else { $info{$stocks, "success"}=0; $info{$stocks, "errormsg"}="Error retreiving $stocks "; } } return wantarray() ? %info : \%info; return \%info; } 1; =head1 NAME Finance::Quote::BSERO Obtain quotes from Bucharest Stock Exchange. =head1 SYNOPSIS use Finance::Quote; $q = Finance::Quote->new; %info = Finance::Quote->fetch("bsero","tlv"); # Only query BSERO %info = Finance::Quote->fetch("romania","brd"); # Failover to other sources OK. =head1 DESCRIPTION This module fetches information from the "Bucharest Stock Exchange" (Bursa de Valori Bucuresti), http://www.bvb.ro. All stocks are available. This module is loaded by default on a Finance::Quote object. It's also possible to load it explicity by placing "BSERO" in the argument list to Finance::Quote->new(). This module provides both the "bsero" and "romania" fetch methods. Please use the "romania" fetch method if you wish to have failover with future sources for Romanian stocks. Using the "bsero" method will guarantee that your information only comes from the Bucharest Stock Exchange. Information obtained by this module may be covered by www.bvb.go terms and conditions See http://www.bvb.ro/ for details. =head1 LABELS RETURNED The following labels may be returned by Finance::Quote::BSERO : name, last, date, p_change, open, high, low, close, volume, currency, method, exchange. =head1 SEE ALSO Bucharest Stock Exchange, http://www.bvb.ro =cut
Subject: BSERO.t
Download BSERO.t
text/x-perl 988b
#!/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 = ("TLV", "BRD", "SNP"); my %regexps = ( TLV => qr/\bTLV\b/, BRD => qr/\bBRD\b/, SNP => qr/\bSNP\b/, ); my %quotes = $q->fetch("bsero", @stocks); ok(%quotes); foreach my $stock (@stocks) { my $name = $quotes{$stock, "name"}; print "#Testing $stock: $name\n"; my $regexp = $regexps{$stock}; ok($name =~ /$regexp/i); ok($quotes{$stock, "exchange"} eq 'Bucharest Stock Exchange'); ok($quotes{$stock, "method"} eq 'bsero'); ok($quotes{$stock, "last"} > 0); ok($quotes{$stock, "open"} =~ /^-?\d+\.\d+$/); ok($quotes{$stock, "p_change"} =~ /^-?\d+\.\d+$/); ok($quotes{$stock, "success"}); ok($quotes{$stock, "volume"} >= 0); } # Check that a bogus stock returns no-success. %quotes = $q->fetch("tsx", "BOGUS"); ok(! $quotes{"BOGUS","success"});
Subject: Re: [rt.cpan.org #44798] Module for Bucharest Stock Exchange (BSE)
Date: Mon, 6 Apr 2009 00:31:40 +0200
To: bug-Finance-Quote [...] rt.cpan.org
From: Erik Colson <eco [...] ecocode.net>
Download (untitled) / with headers
text/plain 299b
On 04 Apr 2009, at 22:47, Andrei Cipu via RT wrote: Show quoted text
> I've created a module for the Bucharest Stock Exchange stocks. As I'm > not very good in Perl, I've based it on the Athens Stock Exchange > module.
Hi Andrei! Thanks for your code. I'll take a look at it later this week. regards -- erik
Download (untitled) / with headers
text/plain 696b
On Sat Apr 04 16:47:03 2009, strainu wrote: Show quoted text
> Hi, > > I've created a module for the Bucharest Stock Exchange stocks. As I'm > not very good in Perl, I've based it on the Athens Stock Exchange module. > > I've tested the code with the attached tester (self-made) and with > GnuCash and it works fine. > > This code does have a minor problem though - the module name is seen as > "bsero" (no caps) instead of "BSERO" as I would expect. I couldn't find > the problem, but I consider it minor. If you have the time, perhaps you > can look into it.
HI Strainu, Sorry for the long delay before incorporating your module. I included it for the next release now.. Thanks for your coding ! -- Erik


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.