| 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 |
use strict; |
| 24 |
use warnings; |
| 25 |
|
| 26 |
use constant DEBUG => $ENV{DEBUG}; |
| 27 |
use if DEBUG, 'Smart::Comments'; |
| 28 |
|
| 29 |
use LWP::UserAgent; |
| 30 |
use Text::Template; |
| 31 |
use JSON qw( decode_json ); |
| 32 |
|
| 33 |
our $VERSION = '1.71'; # VERSION |
| 34 |
|
| 35 |
our $DISPLAY = 'ASEGR - Athens Exchange Group, GR'; |
| 36 |
our @LABELS = qw/symbol method instrument name isin currency last close high low open volume isodate date/; |
| 37 |
our $METHODHASH = {subroutine => \&asegr, |
| 38 |
display => $DISPLAY, |
| 39 |
labels => \@LABELS}; |
| 40 |
|
| 41 |
my $URL = Text::Template->new(TYPE => 'STRING', SOURCE => 'https://www.athexgroup.gr/en/market-data/instruments/{$instrument}/inbroker'); |
| 42 |
|
| 43 |
my @instruments = qw/stocks bonds etfs lending derivatives indices/; |
| 44 |
my ( %jsondata, %info ); |
| 45 |
|
| 46 |
sub methodinfo { |
| 47 |
return ( |
| 48 |
asegr => $METHODHASH, |
| 49 |
greece => $METHODHASH, |
| 50 |
europe => $METHODHASH, |
| 51 |
); |
| 52 |
} |
| 53 |
|
| 54 |
sub labels { |
| 55 |
my %m = methodinfo(); |
| 56 |
return map {$_ => [@{$m{$_}{labels}}] } keys %m; |
| 57 |
} |
| 58 |
|
| 59 |
sub methods { |
| 60 |
my %m = methodinfo(); |
| 61 |
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 |
sub find_symbol { |
| 67 |
my $instrument = shift; |
| 68 |
my $symbol = shift; |
| 69 |
my $quoter = shift; |
| 70 |
|
| 71 |
my $searchparams = $instrument . $symbol; |
| 72 |
### [<now>] Searching for: $searchparams |
| 73 |
|
| 74 |
foreach my $item( @{$jsondata{$instrument}->{'data'}} ) { |
| 75 |
if ($item->{instrCode} eq $symbol) { |
| 76 |
$info{ $symbol, 'success' } = 1; |
| 77 |
$info{ $symbol, 'symbol' } = $symbol; |
| 78 |
$info{ $symbol, 'method' } = 'asegr'; |
| 79 |
$info{ $symbol, 'instrument' } = $instrument; |
| 80 |
if ($instrument ne 'stocks') { |
| 81 |
$info{ $symbol, 'name' } = $item->{'instrName'}; |
| 82 |
} else { |
| 83 |
$info{ $symbol, 'name' } = $item->{'companyName'}; |
| 84 |
} |
| 85 |
$info{ $symbol, 'isin' } = $item->{'isinCode'}; |
| 86 |
$info{ $symbol, 'currency' } = $item->{'currCode'}; |
| 87 |
$info{ $symbol, 'last' } = $item->{'closePrice'}; |
| 88 |
$info{ $symbol, 'close' } = $item->{'closePrice'}; |
| 89 |
$info{ $symbol, 'high' } = $item->{'highPrice'}; |
| 90 |
$info{ $symbol, 'low' } = $item->{'lowPrice'}; |
| 91 |
$info{ $symbol, 'open' } = $item->{'openPrice'}; |
| 92 |
$info{ $symbol, 'volume' } = $item->{'totalVolume'}; |
| 93 |
$info{ $symbol, 'isodate' } = $item->{'tradeDate'}; |
| 94 |
my $isodate = $item->{'tradeDate'}; |
| 95 |
$info{ $symbol, 'date' } = $item->{'tradeDate'}; |
| 96 |
$quoter->store_date( \%info, $symbol, { isodate => $isodate } ); |
| 97 |
return 1; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
return 0; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
sub asegr { |
| 106 |
my $quoter = shift; |
| 107 |
my @symbols = @_; |
| 108 |
my $ua = $quoter->user_agent(); |
| 109 |
my ($url, $reply); |
| 110 |
|
| 111 |
my %table; |
| 112 |
my $index = 0; |
| 113 |
|
| 114 |
SYMBOL: foreach my $symbol (@symbols) { |
| 115 |
### [<now>] Symbol: $symbol |
| 116 |
# $info{ $symbol, 'success' } = 0; |
| 117 |
# $info{ $symbol, 'errormsg' } = 'Symbol not found'; |
| 118 |
INSTRUMENT: foreach my $instrument (@instruments) { |
| 119 |
# if $jsondata{$instrument} not defined, fetch data |
| 120 |
if (!defined ($jsondata{$instrument}) ) { |
| 121 |
$url = $URL->fill_in(HASH => {instrument => $instrument}); |
| 122 |
### [<now>] Fetching url: $url |
| 123 |
$reply = $ua->get($url); |
| 124 |
if ($reply->is_success) { |
| 125 |
$jsondata{$instrument} = decode_json($reply->content); |
| 126 |
### [<now>] jsondata: $jsondata{$instrument} |
| 127 |
find_symbol($instrument, $symbol, $quoter) && next SYMBOL; |
| 128 |
} else { |
| 129 |
next INSTRUMENT; |
| 130 |
} |
| 131 |
} else { |
| 132 |
find_symbol($instrument, $symbol, $quoter) && next SYMBOL; |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
return wantarray() ? %info : \%info; |
| 138 |
} |
| 139 |
|
| 140 |
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 |