| 1 | # | ||||||||||
| 2 | # Copyright (C) 2024, Przemyslaw Kryger | ||||||||||
| 3 | # | ||||||||||
| 4 | # This program is free software: you can redistribute it and/or modify | ||||||||||
| 5 | # it under the terms of the GNU General Public License as published by | ||||||||||
| 6 | # the Free Software Foundation, either version 3 of the License, or | ||||||||||
| 7 | # (at your option) any later version. | ||||||||||
| 8 | # | ||||||||||
| 9 | # This program is distributed in the hope that it will be useful, | ||||||||||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||
| 12 | # GNU General Public License for more details. | ||||||||||
| 13 | # | ||||||||||
| 14 | # You should have received a copy of the GNU General Public License | ||||||||||
| 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||
| 16 | # | ||||||||||
| 17 | # $Id: $ | ||||||||||
| 18 | # | ||||||||||
| 19 | |||||||||||
| 20 | package Finance::Quote::MorningstarJP; | ||||||||||
| 21 | 5 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | 5 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 23 | |||||||||||
| 24 | 5 | ▶ | use constant DEBUG => $ENV{DEBUG}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 5 | ▶ | use if DEBUG, 'Smart::Comments'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 5 | ▶ | use XML::LibXML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 5 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 5 | ▶ | use String::Util qw(trim); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 5 | our $VERSION = '1.72_02'; # TRIAL VERSION | |||||||||
| 32 | |||||||||||
| 33 | 5 | our $DISPLAY = 'Morningstar JP'; | |||||||||
| 34 | 5 | our @LABELS = qw/nav isin symbol name currency date isodate/; | |||||||||
| 35 | 5 | our $METHODHASH = {subroutine => \&morningstarjp, | |||||||||
| 36 | display => $DISPLAY, | ||||||||||
| 37 | labels => \@LABELS}; | ||||||||||
| 38 | |||||||||||
| 39 | 10 | ▶ | sub methodinfo { | ||||||||
|
Subroutine
methodinfo: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 40 | return ( | ||||||||||
| 41 | 10 | morningstarjp => $METHODHASH, | |||||||||
| 42 | ); | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 5 | ▶ | sub labels { my %m = methodinfo(); return map {$_ => [@{$m{$_}{labels}}] } keys %m; } | ||||||||
|
Subroutine
labels: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 46 | |||||||||||
| 47 | 5 | ▶ | sub methods { | ||||||||
|
Subroutine
methods: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 48 | 5 | my %m = methodinfo(); return map {$_ => $m{$_}{subroutine} } keys %m; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 0 | ▶ | sub morningstarjp { | ||||||||
|
Subroutine
morningstarjp: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||
| 52 | 0 | my $quoter = shift; | |||||||||
| 53 | 0 | my @symbols = @_; | |||||||||
| 54 | 0 | my $ua = $quoter->user_agent(); | |||||||||
| 55 | 0 | my %info; | |||||||||
| 56 | |||||||||||
| 57 | 0 | foreach my $symbol (@_) { | |||||||||
| 58 | 0 | eval { | |||||||||
| 59 | 0 | my $url = "https://apl.wealthadvisor.jp/webasp/funddataxml/basic/basic_$symbol.xml"; | |||||||||
| 60 | 0 | my $reply = $ua->get($url); | |||||||||
| 61 | |||||||||||
| 62 | 0 | my $dom; | |||||||||
| 63 | 0 | eval {$dom = XML::LibXML->load_xml(string => $reply->decoded_content)}; | |||||||||
| 64 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 0 | $info{$symbol, 'success' } = 0; | |||||||||
| 66 | 0 | $info{$symbol, 'errormsg' } = $@; | |||||||||
| 67 | 0 | next; | |||||||||
| 68 | } | ||||||||||
| 69 | ### [<now>] DOM: $dom->toString() | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | unless ($dom->findnodes('//Fund/@MS_FUND_CODE')->[0]->to_literal() eq $symbol) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | $info{$symbol, 'success'} = 0; | |||||||||
| 73 | 0 | $info{$symbol, 'errormsg'} = 'Symbol not found'; | |||||||||
| 74 | 0 | next; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 0 | my $nav = $dom->findnodes('//Fund/Price/@KIJYUNKAGAKU')->[0]->to_literal(); | |||||||||
| 78 | 0 | $nav =~ s/,//; | |||||||||
| 79 | 0 | my $date = $dom->findnodes('//Fund/Price/@KIJYUN_YMD')->[0]->to_literal(); | |||||||||
| 80 | 0 | $date =~ s/[^0-9]/-/g; | |||||||||
| 81 | 0 | my $isin = $dom->findnodes('//Fund/@ISIN')->[0]->to_literal(); | |||||||||
| 82 | 0 | my $name = $dom->findnodes('//Fund/@FUND_NAME')->[0]->to_literal(); | |||||||||
| 83 | |||||||||||
| 84 | 0 | $info{$symbol, 'success'} = 1; | |||||||||
| 85 | 0 | $info{$symbol, 'method'} = 'MorningstarJP'; | |||||||||
| 86 | 0 | $info{$symbol, 'currency'} = 'JPY'; | |||||||||
| 87 | 0 | $info{$symbol, 'symbol'} = $symbol; | |||||||||
| 88 | 0 | $info{$symbol, 'nav'} = $nav; | |||||||||
| 89 | 0 | $info{$symbol, 'isin'} = $isin; | |||||||||
| 90 | 0 | $info{$symbol, 'name'} = $name; | |||||||||
| 91 | |||||||||||
| 92 | 0 | $quoter->store_date(\%info, $symbol, {isodate => $date}); | |||||||||
| 93 | }; | ||||||||||
| 94 | |||||||||||
| 95 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 0 | my $error = "Search failed: $@"; | |||||||||
| 97 | 0 | $info{$symbol, 'success'} = 0; | |||||||||
| 98 | 0 | $info{$symbol, 'errormsg'} = trim($error); | |||||||||
| 99 | } | ||||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | ### info : %info | ||||||||||
| 103 | |||||||||||
| 104 | 0 | ▶ | return wantarray() ? %info : \%info; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 5 | 1; | |||||||||
| 108 | |||||||||||
| 109 | __END__ | ||||||||||