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