Debian Codegraph @

lib/Finance/Quote/Deka.pm

raw
1 #!/usr/bin/perl -w
2 #
3 # Deka import modul based on Union.pm
4 # Version 2016-01-12
5 # vi: set ts=2 sw=2 noai ic showmode showmatch:
6
7 package Finance::Quote::Deka;
8
9 use strict;
10 use LWP::UserAgent;
11 use HTTP::Request::Common;
12
13 our $VERSION = '1.71'; # VERSION
14
15 our $DISPLAY = 'Deka Investments, DE';
16 our @LABELS = qw/exchange name date isodate price method/;
17 our $METHODHASH = {subroutine => \&deka,
18 display => $DISPLAY,
19 labels => \@LABELS};
20
21 sub methodinfo {
22 return (
23 deka => $METHODHASH,
24 );
25 }
26
27 sub labels { my %m = methodinfo(); return map {$_ => [@{$m{$_}{labels}}] } keys %m; }
28
29 sub methods {
30 my %m = methodinfo(); return map {$_ => $m{$_}{subroutine} } keys %m;
31 }
32
33 # =======================================================================
34 # The deka routine gets quotes of DEKA funds (Deka Investments)
35 # On their website DEKA provides a csv file in the format
36 # label1;label2;...
37 # symbol1;name1;date1;date_before1;bid1;...
38 # symbol2;name2;date2;date_before2,bid2,...
39 # ...
40 #
41 # This subroutine was written by Andre Joost <[email protected]>
42
43 # Convert number separators to US values
44 sub convert_price {
45 $_ = shift;
46 tr/.,/,./ ;
47 return $_;
48 }
49
50 sub deka
51 {
52 my $quoter = shift;
53 my @funds = @_;
54 return unless @funds;
55 my $ua = $quoter->user_agent;
56 my (%fundhash, @q, %info, $tempdate);
57
58 # create hash of all funds requested
59 foreach my $fund (@funds)
60 {
61 $fundhash{$fund} = 0;
62 }
63
64 # get csv data
65 my $response = $ua->request(GET &dekaurl);
66
67
68 if ($response->is_success)
69 {
70
71 # process csv data
72 foreach (split('\015?\012',$response->content))
73 {
74 # @q = $quoter->parse_csv($_) or next;
75 @q = split(/;/) or next;
76 next unless (defined $q[0]);
77 if (exists $fundhash{$q[0]})
78 {
79 $fundhash{$q[0]} = 1;
80
81
82 $info{$q[0], "exchange"} = "DEKA";
83 $info{$q[0], "name"} = $q[1];
84 $info{$q[0], "symbol"} = $q[0];
85 $tempdate = $q[2];
86 $quoter->store_date(\%info, $q[0], {eurodate => $tempdate});
87 $info{$q[0], "price"} = convert_price($q[4]);
88 $info{$q[0], "last"} = convert_price($q[4]);
89
90 $info{$q[0], "method"} = "deka";
91 $info{$q[0], "currency"} = $q[8];
92 $info{$q[0], "success"} = 1;
93 }
94 }
95
96 # check to make sure a value was returned for every fund requested
97 foreach my $fund (keys %fundhash)
98 {
99 if ($fundhash{$fund} == 0)
100 {
101 $info{$fund, "success"} = 0;
102 $info{$fund, "errormsg"} = "No data returned";
103 }
104 }
105 }
106 else
107 {
108 foreach my $fund (@funds)
109 {
110 $info{$fund, "success"} = 0;
111 $info{$fund, "errormsg"} = "HTTP error";
112 }
113 }
114
115 return wantarray() ? %info : \%info;
116 }
117
118 # DEKA provides a csv file named fondspreise.csv containing the prices of all
119 # their funds for the most recent business day.
120
121 sub dekaurl
122 {
123 return "https://www.deka.de/privatkunden/pflichtseiten/fondspreise?service=fondspreislisteExportController&action=exportCsv&typ=inVertrieb";
124 }
125
126 1;
127
128 =head1 NAME
129
130 Finance::Quote::Deka - Obtain quotes from DEKA (Wertpapierhaus der Sparkassen).
131
132 =head1 SYNOPSIS
133
134 use Finance::Quote;
135
136 $q = Finance::Quote->new;
137
138 %stockinfo = $q->fetch("deka","DE0008474503");
139
140 =head1 DESCRIPTION
141
142 This module obtains information about DEKA managed funds.
143
144 Information returned by this module is governed by DEKA's terms
145 and conditions.
146
147 =head1 LABELS RETURNED
148
149 The following labels may be returned by Finance::Quote::DEKA:
150 exchange, name, date, price, last.
151
152 =head1 SEE ALSO
153
154 DEKA (Deka Investments), http://www.deka.de/
155
156 =cut