/usr/share/perl5/Finance/Quote/CSE.pm is in libfinance-quote-perl 1.38-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | #!/usr/bin/perl -w
#
# This modules is based on the AEX module. The code has been modified by
# Hiranya Samarasekera <hiranyas@gmail.com> to be able to retrieve stock
# information from the Colombo Stock Exchange (CSE) in Sri Lanka.
# ----------------------------------------------------------------------
#
# 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::CSE;
use vars qw($CSE_URL);
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use HTML::TableExtract;
use CGI;
our $VERSION = '1.38'; # VERSION
my $CSE_URL = "http://www.cse.lk/trade_summary_report.do?reportType=CSV";
sub methods { return (cse => \&cse) }
{
my @labels = qw/ID SYMBOL NAME LAST_TRADE_QUANTITY TRADE_DATE PRICE SHAREVOLUME TRADEVOLUME TURNOVER HI_TRADE LO_TRADE CHANGE CHANGE_PERCENTAGE ISSUE_DATE CLOSING_PRICE PREVIOUS_CLOSE MARKET_CAP MARKET_CAP_PERCENTAGE OPEN currency method exchange/;
sub labels { return (cse => \@labels) }
}
# Colombo Stock Exchange (CSE), Sri Lanka
sub cse {
my $quoter = shift;
my @symbols = @_;
return unless @symbols;
my (%info,$url,$reply,$te);
my ($row, $datarow, $matches);
my ($time);
$url = $CSE_URL; # base url
# Create a user agent object and HTTP headers
my $ua = new LWP::UserAgent(agent => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)');
# Compose POST request
my $request = new HTTP::Request("GET", $url);
$reply = $ua->request( $request );
#print Dumper $reply;
if ($reply->is_success) {
# Write retreived data to temp file for debugging
use POSIX;
my $filename = tmpnam();
open my $fw, ">", $filename or die "$filename: $!";
print $fw $reply->content;
close $fw;
# Open reply to read lines
open FP, "<", \$reply->content or die "Unable to read data: $!";
# Open temp file instead while debugging
#open FP, "<", $filename or die "Unable to read data: $!";
while (my $line = <FP>) {
my @row_data = $quoter->parse_csv($line);
#print Dumper \@row_data;
my $row = \@row_data;
#print Dumper $row;
next unless @row_data;
foreach my $symbol (@symbols) {
my $found = 0;
# Match stock symbol (e.g. JKH.N0000, HNB.X0000)
if ( @$row[1] eq uc($symbol) ) {
$info {$symbol, "exchange"} = "Colombo Stock Exchange, Sri Lanka";
$info {$symbol, "method"} = "cse";
$info {$symbol, "symbol"} = @$row[1];
$info {$symbol, "name"} = @$row[2];
($info {$symbol, "last"} = @$row[5]) =~ s/\s*//g;
$info {$symbol, "bid"} = undef;
$info {$symbol, "offer"} = undef;
$info {$symbol, "open"} = @$row[18];
$info {$symbol, "nav"} = undef;
$info {$symbol, "price"} = @$row[5];
$info {$symbol, "low"} = @$row[10];
$info {$symbol, "close"} = @$row[15];
$info {$symbol, "p_change"} = @$row[12];
($info {$symbol, "high"} = @$row[9]) =~ s/\s*//g;
($info {$symbol, "volume"} = @$row[6]) =~ s/,//g;;
$quoter->store_date(\%info, $symbol, {today => 1});
$info {$symbol, "currency"} = "LKR";
$info {$symbol, "success"} = 1;
}
}
}
}
foreach my $symbol (@symbols) {
unless ( !defined($info {$symbol, "success"}) || $info {$symbol, "success"} == 1 )
{
$info {$symbol,"success"} = 0;
$info {$symbol,"errormsg"} = "Fund name $symbol not found";
next;
}
}
#print Dumper \%info;
return %info if wantarray;
return \%info;
}
1;
=head1 NAME
Finance::Quote::CSE - Obtain quotes from Colombo Stock Exchange in Sri Lanka
=head1 SYNOPSIS
use Finance::Quote;
$q = Finance::Quote->new;
@stocks = ("JKH.N0000", "HPWR.N0000", "HNB.X0000");
%info = Finance::Quote->fetch("cse", @stocks);
=head1 DESCRIPTION
This module retrieves information from the Colombo Stock Exchange (CSE)
in Sri Lanka http://www.cse.lk.
This module is loaded by default on a Finance::Quote object. It's
also possible to load it explicity by placing "cse" in the argument
list to Finance::Quote->new().
=head1 LABELS RETURNED
The following labels may be returned by Finance::Quote::CSE :
symbol, name, last, open, price, low, close, p_change,
high, volume, exchange, method
=head1 SEE ALSO
Colombo Stock Exchange (CSE), Sri Lanka, http://www.cse.lk
=cut
|