#!/usr/bin/perl -w # This modules is based on the Finance::Quote::ASEGR module # # The code has been modified by Maciej Pasternacki # to be able to retrieve Polish stock and mutual fund information # from the Bossa.pl service. # # 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::Bossa; use vars qw($VERSION $NDOHLCV_URL); use LWP::UserAgent; use HTTP::Request::Common; $VERSION='0.1'; my $NDOHLCV_URL = 'http://bossa.pl/pub/fundinwest/omega/fun/ndohlcv.txt'; sub methods { return ( poland => \&bossa, bossa => \&bossa, europe => \&bossa); } { my @labels = qw/name date isodate open high low close last currency method/; sub labels { return (poland => \@labels, bossa => \@labels, europe => \@labels); } } sub bossa { my $quoter = shift; my @stocks = @_; my (%info,@ndohlcv,$success); my $ua = $quoter->user_agent(); { my $reply = $ua->request(GET $NDOHLCV_URL); $success = $reply->is_success; @ndohlcv = split /\s*\n\s*/, $reply->content; } foreach my $symbol (@stocks) { if ($success) { my @data = sort grep /^$symbol,/, @ndohlcv; unless ( @data ) { $info {$symbol, "success"} = 0; $info {$symbol, "errormsg"} = "Stock name $symbol not found"; next; } # Use newest data available. my @columns = $quoter->parse_csv($data[-1]); # NDOHLCV: Name, Date, Opening, Maximum, Minimum, Closing, Cycle $info {$symbol, "success"} = 1; $info {$symbol, "method"} = "bossa"; $info {$symbol, "name"} = $columns[0]; $quoter->store_date(\%info, $symbol, {year => substr($columns[1], 0, 4), month => substr($columns[1], 4, 2), day => substr($columns[1], 6, 2)}); $info {$symbol, "open"} = $columns[2]; $info {$symbol, "high"} = $columns[3]; $info {$symbol, "low"} = $columns[4]; $info {$symbol, "close"} = $columns[5]; $info {$symbol, "last"} = $columns[5]; # is it correct? $info {$symbol, "currency"} = "PLN"; } else { $info{$symbol, "success"}=0; $info{$symbol, "errormsg"}="Error retreiving $symbol"; } } return wantarray() ? %info : \%info; return \%info; } 1; =head1 NAME Finance::Quote::Bossa Obtain Polish stock and mutual fund quotes from Bossa.pl service. =head1 SYNOPSIS use Finance::Quote; $q = Finance::Quote->new; %info = Finance::Quote->fetch("bossa","AROK"); # Only query Bossa.pl %info = Finance::Quote->fetch("poland","AROK"); # Failover to other sources OK. =head1 DESCRIPTION This module fetches information from http://www.bossa.pl/ Polish stock market service. 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 "Bossa" in the argument list to Finance::Quote->new(). This module provides both the "bossa" and "poland" fetch methods. Please use the "poland" fetch method if you wish to have failover with future sources for Polish stocks. Using the "bossa" method will guarantee that your information only comes from the Bossa.pl service. =head1 LABELS RETURNED The following labels may be returned by Finance::Quote::Bossa : name date isodate open high low close last currency method =head1 SEE ALSO http://www.bossa.pl/ =cut