Quote/ASEGR.pm

filter: Statementstmt 45.1% 37 / 82 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 0.0% 0 / 5 totaltotal 41.5% 47 / 113 CC 11 SCAR 34.1
CC
11
Cov
39%
asegr
72.0
find_symbol
20.0
BEGIN
1.0
CRAP 30.3
« Quote/TMX.pm ↑ Summary Quote/BorsaItaliana.pm »
1 #!/usr/bin/perl -w
2 # vi: set ts=2 sw=2 noai ic expandtab showmode showmatch:
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 # 02110-1301, USA
17  
18 # Changes:
19 # Rewrite: 2025-10-11 - Many changes to web site, Bruce Schuck
20  
21 package Finance::Quote::ASEGR;
22  
23 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 5 ▶use constant DEBUG => $ENV{DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶use if DEBUG, 'Smart::Comments';
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 5 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 5 ▶use Text::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 5 ▶use JSON qw( decode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 5 our $VERSION = '1.72_02'; # TRIAL VERSION
34  
35 5 our $DISPLAY = 'ASEGR - Athens Exchange Group, GR';
36 5 our @LABELS = qw/symbol method instrument name isin currency last close high low open volume isodate date/;
37 5 our $METHODHASH = {subroutine => \&asegr,
38 display => $DISPLAY,
39 labels => \@LABELS};
40  
41 5 my $URL = Text::Template->new(TYPE => 'STRING', SOURCE => 'https://www.athexgroup.gr/en/market-data/instruments/{$instrument}/inbroker');
42  
43 5 my @instruments = qw/stocks bonds etfs lending derivatives indices/;
44 5 my ( %jsondata, %info );
45  
46 10 ▶sub methodinfo {
Subroutine methodinfo: called CC=1 SCAR=0.0
Pod undocumented
47 return (
48 10 asegr => $METHODHASH,
49 greece => $METHODHASH,
50 europe => $METHODHASH,
51 );
52 }
53  
54 5 ▶sub labels {
Subroutine labels: called CC=1 SCAR=0.0
Pod undocumented
55 5 my %m = methodinfo();
56 5 return map {$_ => [@{$m{$_}{labels}}] } keys %m;
57 }
58  
59 5 ▶sub methods {
Subroutine methods: called CC=1 SCAR=0.0
Pod undocumented
60 5 my %m = methodinfo();
61 5 return map {$_ => $m{$_}{subroutine} } keys %m;
62 }
63  
64 # Since %jsondata and %info are global to this module
65 # pass in the instrument and symbol to search for the data
66 0 ▶sub find_symbol {
Subroutine find_symbol: not called CC=4 SCAR=30.0
Pod undocumented
67 0 my $instrument = shift;
68 0 my $symbol = shift;
69 0 my $quoter = shift;
70  
71 0 my $searchparams = $instrument . $symbol;
72 ### [<now>] Searching for: $searchparams
73  
74 0 foreach my $item( @{$jsondata{$instrument}->{'data'}} ) {
75 0 ▶ if ($item->{instrCode} eq $symbol) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{"instrCode"} eq $symbol) 0 0 0
76 0 $info{ $symbol, 'success' } = 1;
77 0 $info{ $symbol, 'symbol' } = $symbol;
78 0 $info{ $symbol, 'method' } = 'asegr';
79 0 $info{ $symbol, 'instrument' } = $instrument;
80 0 ▶ if ($instrument ne 'stocks') {
Branch: 1 branch
BranchTrueFalseTotal
if ($instrument ne 'stocks') { } 0 0 0
81 0 $info{ $symbol, 'name' } = $item->{'instrName'};
82 } else {
83 0 $info{ $symbol, 'name' } = $item->{'companyName'};
84 }
85 0 $info{ $symbol, 'isin' } = $item->{'isinCode'};
86 0 $info{ $symbol, 'currency' } = $item->{'currCode'};
87 0 $info{ $symbol, 'last' } = $item->{'closePrice'};
88 0 $info{ $symbol, 'close' } = $item->{'closePrice'};
89 0 $info{ $symbol, 'high' } = $item->{'highPrice'};
90 0 $info{ $symbol, 'low' } = $item->{'lowPrice'};
91 0 $info{ $symbol, 'open' } = $item->{'openPrice'};
92 0 $info{ $symbol, 'volume' } = $item->{'totalVolume'};
93 0 $info{ $symbol, 'isodate' } = $item->{'tradeDate'};
94 0 my $isodate = $item->{'tradeDate'};
95 0 $info{ $symbol, 'date' } = $item->{'tradeDate'};
96 0 $quoter->store_date( \%info, $symbol, { isodate => $isodate } );
97 0 return 1;
98 }
99 }
100  
101 0 return 0;
102  
103 }
104  
105 0 ▶sub asegr {
Subroutine asegr: not called CC=8 SCAR=42.8
Pod undocumented
106 0 my $quoter = shift;
107 0 my @symbols = @_;
108 0 my $ua = $quoter->user_agent();
109 0 my ($url, $reply);
110  
111 0 my %table;
112 0 my $index = 0;
113  
114 0 SYMBOL: foreach my $symbol (@symbols) {
115 ### [<now>] Symbol: $symbol
116 # $info{ $symbol, 'success' } = 0;
117 # $info{ $symbol, 'errormsg' } = 'Symbol not found';
118 0 INSTRUMENT: foreach my $instrument (@instruments) {
119 # if $jsondata{$instrument} not defined, fetch data
120 0 ▶ if (!defined ($jsondata{$instrument}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $jsondata{$instrument}) { } 0 0 0
121 0 $url = $URL->fill_in(HASH => {instrument => $instrument});
122 ### [<now>] Fetching url: $url
123 0 $reply = $ua->get($url);
124 0 ▶ if ($reply->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reply->is_success) { } 0 0 0
125 0 $jsondata{$instrument} = decode_json($reply->content);
126 ### [<now>] jsondata: $jsondata{$instrument}
127 0 ▶ find_symbol($instrument, $symbol, $quoter) && next SYMBOL;
Branch: 1 branch
BranchTrueFalseTotal
find_symbol($instrument, $symbol, $quoter) and next SYMBOL 0 0 0
128 } else {
129 0 next INSTRUMENT;
130 }
131 } else {
132 0 ▶ find_symbol($instrument, $symbol, $quoter) && next SYMBOL;
Branch: 1 branch
BranchTrueFalseTotal
find_symbol($instrument, $symbol, $quoter) and next SYMBOL 0 0 0
133 }
134 }
135 }
136  
137 0 ▶ return wantarray() ? %info : \%info;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
138 }
139  
140 5 1;
141  
142 =head1 NAME
143  
144 Finance::Quote::ASEGR - Obtain quotes from Athens Exchange Group
145  
146 =head1 SYNOPSIS
147  
148 use Finance::Quote;
149  
150 $q = Finance::Quote->new;
151  
152 %info = Finance::Quote->fetch("asegr","minoa"); # Only query ASEGR
153 %info = Finance::Quote->fetch("greece","aaak"); # Failover to other sources OK.
154  
155 =head1 DESCRIPTION
156  
157 This module fetches information from https://www.athexgroup.gr.
158  
159 This module is loaded by default on a Finance::Quote object. It's also possible
160 to load it explicitly by placing 'asegr' in the argument list to
161 Finance::Quote->new().
162  
163 This module provides both the 'asegr' and 'greece' fetch methods.
164  
165 =head1 LABELS RETURNED
166  
167 The following labels may be returned:
168  
169 =over
170  
171 =item symbol
172  
173 =item method
174  
175 =item instrument
176  
177 =item name
178  
179 =item isin
180  
181 =item currency
182  
183 =item last
184  
185 =item close
186  
187 =item high
188  
189 =item low
190  
191 =item open
192  
193 =item volume
194  
195 =item isodate
196  
197 =item date
198  
199 =back
200  
201 =head1 Terms & Conditions
202  
203 Use of www.athexgroup.gr is governed by any terms & conditions of that site.
204  
205 Finance::Quote is released under the GNU General Public License, version 2,
206 which explicitly carries a "No Warranty" clause.
207  
208 =cut
« Quote/TMX.pm ↑ Summary Quote/BorsaItaliana.pm »