| 1 | #!/usr/bin/perl -w |
| 2 | # vi: set ts=2 sw=2 noai expandtab ic 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 | package Finance::Quote::Sinvestorscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/; |
| 19 | |
| 20 | use strictscip-perl cpan Finance-Quote 1.70 strict/; |
| 21 | use warningsscip-perl cpan Finance-Quote 1.70 warnings/; |
| 22 | use HTML::Entitiesscip-perl cpan Finance-Quote 1.70 HTML/Entities/; |
| 23 | use String::Utilscip-perl cpan Finance-Quote 1.70 String/Util/ qw(trim); |
| 24 | |
| 25 | use constantscip-perl cpan Finance-Quote 1.70 constant/ DEBUGscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/DEBUG(). => $ENV{DEBUG}; |
| 26 | use ifscip-perl cpan Finance-Quote 1.70 if/ DEBUG, 'Smart::Comments'; |
| 27 | |
| 28 | use LWP::UserAgentscip-perl cpan Finance-Quote 1.70 LWP/UserAgent/; |
| 29 | use Web::Scraperscip-perl cpan Finance-Quote 1.70 Web/Scraper/; |
| 30 | use Encodescip-perl cpan Finance-Quote 1.70 Encode/ qw(encode_utf8); |
| 31 | |
| 32 | our $VERSIONscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$VERSION. = '1.70'; # VERSION |
| 33 | |
| 34 | my $SINVESTOR_URL = 'https://web.s-investor.de/app/detail.htm?isin='; |
| 35 | |
| 36 | our $DISPLAYscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$DISPLAY. = 'Sinvestor'; |
| 37 | # see https://web.s-investor.de/app/webauswahl.jsp for "Institutsliste" |
| 38 | our $FEATURESscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$FEATURES. = {'INST_ID' => 'Institut Id (default: 0000057 for "Sparkasse Krefeld")', |
| 39 | 'EXCHANGE' => 'select market place (i.e. "gettex", "Xetra", "Tradegate")'}; |
| 40 | our @LABELSscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/`@LABELS`. = qw/symbol isin last close exchange exchanges volume open price change p_change date time low high ask bid source/; |
| 41 | our $METHODHASHscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$METHODHASH. = {subroutine => \&sinvestorscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/sinvestor()., |
| 42 | display => $DISPLAYscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$DISPLAY., |
| 43 | labels => \@LABELSscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/`@LABELS`., |
| 44 | features => $FEATURESscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$FEATURES.}; |
| 45 | |
| 46 | sub labelsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/labels(). { |
| 47 | my %m = methodinfoscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/methodinfo().(); return mapscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/map(). {$_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_. => [@{$m{$_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.}{labels}}] } keysscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/keys(). %m; |
| 48 | } |
| 49 | |
| 50 | sub methodinfoscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/methodinfo(). { |
| 51 | return ( |
| 52 | sinvestor => $METHODHASHscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$METHODHASH., |
| 53 | europe => $METHODHASHscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$METHODHASH., |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | sub methodsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/methods(). { |
| 58 | my %m = methodinfoscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/methodinfo().(); return mapscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/map(). {$_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_. => $m{$_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.}{subroutine} } keysscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/keys(). %m; |
| 59 | } |
| 60 | |
| 61 | sub strip_exchange_namescip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/strip_exchange_name(). { |
| 62 | my $exchange_name = shiftscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/shift().; |
| 63 | $exchange_name =~ s/^(Zürich) - SWX$/$1/g; |
| 64 | return $exchange_name; |
| 65 | } |
| 66 | |
| 67 | sub get_utf8_stringscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_utf8_string(). { |
| 68 | return encode_utf8scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/encode_utf8().(shiftscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/shift().); |
| 69 | } |
| 70 | |
| 71 | sub get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number(). { |
| 72 | my $number = shiftscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/shift().; |
| 73 | $number = trimscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/trim().($number); |
| 74 | $number =~ s/\.//g; |
| 75 | $number =~ s/,/\./; |
| 76 | return ($number =~ /^([-+]?[0-9]+(\.[0-9]+)?)/) ? $1scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$1. : undef; |
| 77 | } |
| 78 | |
| 79 | sub get_iso_currencyscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_iso_currency(). { |
| 80 | my ($currency) = @_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/`@_`.; |
| 81 | $currency =~ s/Euro/EUR/ and return $currency; |
| 82 | $currency =~ s/Schweizer Franken/CHF/ and return $currency; |
| 83 | $currency =~ s/US Dollar/USD/ and return $currency; |
| 84 | $currency =~ s/^Taiwan-Dollar.*/TWD/ and return $currency; |
| 85 | # TODO: add more currencies .. |
| 86 | } |
| 87 | |
| 88 | sub td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search(). { |
| 89 | my ($tree, $text) = @_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/`@_`.; |
| 90 | my $td = $tree->look_downscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/look_down().('_tag'=>'td', sub { $_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/`@_`.[0]->as_textscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/as_text(). eq $text }) or return; |
| 91 | my @tds = $td->parentscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/parent().->look_downscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/look_down().('_tag'=>'td'); |
| 92 | return mapscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/map(). { $tds[$_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.]->as_textscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/as_text(). } (1..$#tdsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/`$#tds`.); |
| 93 | } |
| 94 | |
| 95 | sub sinvestorscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/sinvestor(). { |
| 96 | my $quoter = shiftscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/shift().; |
| 97 | my $inst_id = existsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/exists(). $quoter->{module_specific_data}->{sinvestor}->{INST_ID} ? |
| 98 | $quoter->{module_specific_data}->{sinvestor}->{INST_ID} : |
| 99 | '0000057'; |
| 100 | |
| 101 | my $exchange_code = existsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/exists(). $quoter->{module_specific_data}->{sinvestor}->{EXCHANGE} ? |
| 102 | $quoter->{module_specific_data}->{sinvestor}->{EXCHANGE} : |
| 103 | undef; |
| 104 | |
| 105 | my %exchange2code = ( 'Gettex' => 'GTX', |
| 106 | 'Tradegate' => 'TDG', |
| 107 | 'Stuttgart' => 'STU', |
| 108 | 'Frankfurt' => 'FRA', |
| 109 | 'Xetra' => 'GER', |
| 110 | 'Paris' => 'PAR', |
| 111 | "Düsseldorf" => 'DUS', |
| 112 | 'Berlin' => 'BER', |
| 113 | 'Hamburg' => 'HAM', |
| 114 | 'Hannover' => 'HAN', |
| 115 | "München" => 'MUN', |
| 116 | 'Refinitiv CT' => 'RCT', |
| 117 | 'Zürich' => 'SWX', |
| 118 | 'Zürich - SWX' => 'SWX', |
| 119 | 'NASDAQ - Pink Sheets' => 'PNK', |
| 120 | # undef means: this exchange is not selectable by name |
| 121 | 'Quotrix' => undef, # '0QT', 'QTX', |
| 122 | 'KVG Fondskurse' => undef, # 'LIP', |
| 123 | 'Lipper Fondsdaten' => undef, # 'LIP' |
| 124 | ); |
| 125 | |
| 126 | my %exchange2code_uc = ( mapscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/map(). { ucscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/uc().($_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.) => $exchange2code{$_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.} } keysscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/keys(). %exchange2code ); |
| 127 | |
| 128 | if (definedscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/defined().($exchange_code) and $exchange_code !~ /^[A-Z0-9]{3}$/) { |
| 129 | # we need the exchange_code for the querry |
| 130 | if (existsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/exists(). $exchange2code_uc{ucscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/uc().($exchange_code)} |
| 131 | and definedscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/defined(). $exchange2code_uc{ucscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/uc().($exchange_code)}) { |
| 132 | $exchange_code = $exchange2code_uc{ucscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/uc().($exchange_code)}; |
| 133 | } else { |
| 134 | diescip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/die().("unsupported exchange(-code): $exchange_code"); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | my $ua = $quoter->user_agentscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/user_agent().(); |
| 139 | my $agent = $ua->agentscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/agent().; |
| 140 | $ua->agentscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/agent().('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'); |
| 141 | |
| 142 | my %info; |
| 143 | |
| 144 | foreach my $symbol (@_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/`@_`.) { |
| 145 | my $url = $SINVESTOR_URL |
| 146 | . $symbol |
| 147 | . '&INST_ID=' |
| 148 | . $inst_id; |
| 149 | |
| 150 | $url .= '&boerse=' . $exchange_code if definedscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/defined().($exchange_code); |
| 151 | |
| 152 | eval { |
| 153 | my $tree = HTML::TreeBuilder->new_from_urlscip-perl cpan Finance-Quote 1.70 HTML/TreeBuilder/new_from_url().($url); |
| 154 | ### [<now>] tree: $tree |
| 155 | |
| 156 | my $lastvalue = $tree->look_downscip-perl cpan Finance-Quote 1.70 HTML/TreeBuilder/look_down().('class'=>'si_seitenbezeichnung'); |
| 157 | |
| 158 | if (definedscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/defined().($lastvalue)) { |
| 159 | $info{ $symbol, 'success' } = 0; |
| 160 | $info{ $symbol, 'errormsg' } = 'Invalid institute id. Get a valid institute id from https://web.s-investor.de/app/webauswahl.jsp'; |
| 161 | } else { |
| 162 | $lastvalue = $tree->look_downscip-perl cpan Finance-Quote 1.70 HTML/TreeBuilder/look_down().('id'=>'kursdaten') or diescip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/die().("Not found"); |
| 163 | |
| 164 | my $isin = get_utf8_stringscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_utf8_string().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($lastvalue, 'ISIN')); |
| 165 | my $sharename = get_utf8_stringscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_utf8_string().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($lastvalue, 'Bezeichnung')); |
| 166 | my $exchange = get_utf8_stringscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_utf8_string().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($lastvalue, "B\xf6rse/Contributor")); |
| 167 | |
| 168 | my $price = get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($lastvalue, 'Letzter Kurs')); |
| 169 | |
| 170 | my $currency = get_iso_currencyscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_iso_currency().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($lastvalue, "W\xe4hrung")); |
| 171 | |
| 172 | # TODO: per trade or day? |
| 173 | my $volume = get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($lastvalue, 'Volumen/Trade')); |
| 174 | #my $volume = get_de_number(td_search($lastvalue, 'Volumen/Tag')); |
| 175 | |
| 176 | my $table = ($tree->look_downscip-perl cpan Finance-Quote 1.70 HTML/TreeBuilder/look_down().('_tag'=>'table'))[1]; |
| 177 | my ($bid, $ask) = mapscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/map(). { get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().($_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.) } td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($lastvalue, 'Kurs'); |
| 178 | |
| 179 | $table = $tree->look_downscip-perl cpan Finance-Quote 1.70 HTML/TreeBuilder/look_down().('_tag'=>'table', 'id'=>'detailHandelsplatz'); |
| 180 | my %exchanges = (); |
| 181 | foreach ($table->look_downscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/look_down().('_tag'=>'tr', 'class'=>'si_click_nav rowLink')) { |
| 182 | my $a = $_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.->attrscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/attr().('data-dest'); |
| 183 | if ($a and $a =~ /boerse=([^&"]+)/) { |
| 184 | my $code = $1scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$1.; |
| 185 | my $name = encode_utf8scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/encode_utf8().(($_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.->look_downscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/look_down().('_tag'=>'td'))[0]->as_textscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/as_text().); |
| 186 | $exchanges{ $name } = $code; |
| 187 | $name = strip_exchange_namescip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/strip_exchange_name().($name); |
| 188 | $exchanges{ $name } = $code if not existsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/exists(). $exchanges{ $name }; |
| 189 | } |
| 190 | } |
| 191 | if (definedscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/defined().($exchange_code)) { |
| 192 | my $key = strip_exchange_namescip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/strip_exchange_name().($exchange); |
| 193 | unless(existsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/exists().($exchanges{ $key }) and $exchanges{ $key } eq $exchange_code) { |
| 194 | diescip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/die().("$symbol not found on marketplace: $exchange_code"); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | my @searchvalue = $tree->look_downscip-perl cpan Finance-Quote 1.70 HTML/TreeBuilder/look_down().('class'=>'contentBox oneColum'); |
| 199 | my $isFound = 0; |
| 200 | foreach my $t (@searchvalue) |
| 201 | { |
| 202 | if (refscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/ref().(($t->content_listscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/content_list().)[0]) eq "HTML::Element" and ($t->content_listscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/content_list().)[0]{'_content'}[0]{'_content'}[0] eq 'Aktuelle Vergleichszahlen') |
| 203 | { |
| 204 | $isFound = 1; |
| 205 | $info{$symbol, 'success'} = 1; |
| 206 | $info{$symbol, 'method'} = 'Sinvestor'; |
| 207 | $info{$symbol, 'source'} = $url; |
| 208 | $info{$symbol, 'symbol'} = $isin; |
| 209 | $info{$symbol, 'isin'} = $isin; |
| 210 | $info{$symbol, 'name'} = $sharename; |
| 211 | $info{$symbol, 'volume'} = $volume; |
| 212 | $info{$symbol, 'currency'} = $currency; |
| 213 | $info{$symbol, 'ask'} = $ask; |
| 214 | $info{$symbol, 'bid'} = $bid; |
| 215 | $info{$symbol, 'exchange'} = $exchange; |
| 216 | $info{$symbol, 'exchanges'} = [ grepscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/grep(). { existsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/exists(). $exchange2code_uc{ucscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/uc().($_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.)} |
| 217 | and definedscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/defined(). $exchange2code_uc{ucscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/uc().($_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.)} |
| 218 | } sortscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/sort(). keysscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/keys(). %exchanges ]; |
| 219 | $info{$symbol, 'last'} = $price; |
| 220 | $info{$symbol, 'price'} = $price; # TODO: useless label (and not specified in README.md) |
| 221 | $info{$symbol, 'close'} = get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($t, 'VT-Schluss')); |
| 222 | $info{$symbol, 'change'} = get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($t, 'Diff.')); |
| 223 | $info{$symbol, 'p_change'} = get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($t, 'Diff.%')); |
| 224 | $info{$symbol, 'open'} = get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($t, "Er\xf6ffnung")); |
| 225 | $info{$symbol, 'low'} = get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($t, 'Tief')); |
| 226 | $info{$symbol, 'high'} = get_de_numberscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/get_de_number().(td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($t, 'Hoch')); |
| 227 | |
| 228 | my ($child) = td_searchscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/td_search().($t, 'Datum/Zeit'); |
| 229 | my $date = substrscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/substr().(trimscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/trim().($child), 0, 8); |
| 230 | my $time = substrscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/substr().(trimscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/trim().($child), 9, 5); # CE(S)T |
| 231 | $quoter->store_datescip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/store_date().(\%info, $symbol, {eurodate => $date}); |
| 232 | $info{$symbol, 'time'} = $1scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$1. if $time =~ /^([0-9]{2}:[0-9]{2})/; |
| 233 | |
| 234 | if (DEBUG) { |
| 235 | my %unknown_exchanges = mapscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/map(). { $_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_. => $exchanges{$_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.} } |
| 236 | grepscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/grep(). { not existsscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/exists(). $exchange2code_uc{ucscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/uc().($_scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/$_.)} } |
| 237 | sortscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/sort(). keysscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/keys(). %exchanges; |
| 238 | ### unknown_exchanges: %unknown_exchanges |
| 239 | $info{$symbol, '_unknown_exchanges'} = { %unknown_exchanges }; |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | if (!$isFound) |
| 245 | { |
| 246 | $info{$symbol, 'success'} = 0; |
| 247 | $info{$symbol, 'errormsg'} = "Error retreiving $symbol: $@"; |
| 248 | } |
| 249 | } |
| 250 | }; |
| 251 | if ($@scip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/`$@`.) { |
| 252 | $info{$symbol, 'success'} = 0; |
| 253 | $info{$symbol, 'errormsg'} = "Error retreiving $symbol: $@"; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | } |
| 258 | $ua->agentscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/agent().($agent); |
| 259 | |
| 260 | return wantarrayscip-perl cpan Finance-Quote 1.70 Finance/Quote/Sinvestor/wantarray().() ? %info : \%info; |
| 261 | } |
| 262 | |
| 263 | 1; |
| 264 | |
| 265 | =head1 NAME |
| 266 | |
| 267 | Finance::Quote::Sinvestor - Obtain quotes from S-Investor platform. |
| 268 | |
| 269 | =head1 SYNOPSIS |
| 270 | |
| 271 | use Finance::Quote; |
| 272 | |
| 273 | $q = Finance::Quote->new; |
| 274 | or |
| 275 | $q = Finance::Quote->new('Sinvestor', 'sinvestor' => {INST_ID => 'your institute id'}); |
| 276 | or |
| 277 | $q = Finance::Quote->new('Sinvestor', 'sinvestor' => {EXCHANGE => 'Xetra'}); |
| 278 | |
| 279 | %info = Finance::Quote->fetch("Sinvestor", "DE000ENAG999"); # Only query Sinvestor |
| 280 | %info = Finance::Quote->fetch("europe", "brd"); # Failover to other sources OK. |
| 281 | |
| 282 | =head1 DESCRIPTION |
| 283 | |
| 284 | This module fetches information from https://s-investor.de/, the investment platform |
| 285 | of the German Sparkasse banking group. It fetches share prices from various |
| 286 | marketplaces. The marketplace is returned in the "exchange" field. |
| 287 | |
| 288 | Suitable for shares, ETFs and funds that are traded in Germany. |
| 289 | |
| 290 | This module is loaded by default on a Finance::Quote object. It's also possible |
| 291 | to load it explicitly by placing "Sinvestor" in the argument list to |
| 292 | Finance::Quote->new(). |
| 293 | |
| 294 | This module provides "Sinvestor" and "europe" fetch methods. |
| 295 | |
| 296 | Information obtained by this module may be covered by s-investor.de terms and |
| 297 | conditions. |
| 298 | |
| 299 | =head1 EXCHANGE |
| 300 | |
| 301 | https://www.s-investor.de/ supports different market places. A default is not specified. |
| 302 | |
| 303 | "Xetra" alias "GER" |
| 304 | "Tradegate" alias "TDG" |
| 305 | "gettex" alias "GTX" |
| 306 | "Berlin" alias "BER" |
| 307 | ... any many more ... |
| 308 | |
| 309 | The EXCHANGE may be set by providing a module specific hash to |
| 310 | Finance::Quote->new as in the above example (optional). |
| 311 | |
| 312 | =head1 INST_ID |
| 313 | |
| 314 | https://s-investor.de/ supports different institute IDs. The default value "0000057" is |
| 315 | used (Krefeld) if no institute ID is provided. A list of institute IDs is provided here: |
| 316 | https://web.s-investor.de/app/webauswahl.jsp |
| 317 | |
| 318 | The INST_ID may be set by providing a module specific hash to |
| 319 | Finance::Quote->new as in the above example (optional). |
| 320 | |
| 321 | =head1 LABELS RETURNED |
| 322 | |
| 323 | The following labels are returned: |
| 324 | currency |
| 325 | exchange |
| 326 | exchanges |
| 327 | last |
| 328 | method |
| 329 | source |
| 330 | success |
| 331 | symbol |
| 332 | isin |
| 333 | date |
| 334 | time |
| 335 | volume |
| 336 | price |
| 337 | close |
| 338 | open |
| 339 | low |
| 340 | high |
| 341 | change |
| 342 | p_change |
| 343 | ask |
| 344 | bid |