line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::GeniusTrader::DB; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Copyright 2000-2004 Raphaël Hertzog, Fabien Fulhaber |
4
|
|
|
|
|
|
|
# This file is distributed under the terms of the General Public License |
5
|
|
|
|
|
|
|
# version 2 or (at your option) any later version. |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
551
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $loaded_sharenames = 0; |
10
|
|
|
|
|
|
|
our %sharenames; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Finance::GeniusTrader::DB - Database to retrieve (an history of) prices of various shares |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
No documentation available. Look at the DB::* modules for |
19
|
|
|
|
|
|
|
real exemples. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub has_code { |
24
|
0
|
|
|
0
|
0
|
|
my ($self, $code) = @_; |
25
|
|
|
|
|
|
|
# Default implementation is a kludge. |
26
|
|
|
|
|
|
|
# We have no way to know if the underlying database has the code |
27
|
|
|
|
|
|
|
# without trying to retrieve the prices |
28
|
0
|
|
|
|
|
|
my $name = $self->get_name($code); |
29
|
0
|
0
|
0
|
|
|
|
if (defined($name) && $name ne "") { |
30
|
0
|
|
|
|
|
|
return 1; |
31
|
|
|
|
|
|
|
} else { |
32
|
0
|
|
|
|
|
|
return 0; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=over |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item C<< get_name ($code) >> |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Returns the long name of the market (if defined). |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
See also ~/.gt/sharenames which contains lines of the form |
43
|
|
|
|
|
|
|
\t |
44
|
|
|
|
|
|
|
mapping a market code to its long name. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=back |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub get_name { |
51
|
0
|
|
|
0
|
1
|
|
my ($self, $code) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $name = $self->get_db_name($code); |
54
|
0
|
0
|
0
|
|
|
|
return $name if (defined($name) && $name); |
55
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
if (! $loaded_sharenames) { |
57
|
0
|
|
|
|
|
|
my $file = Finance::GeniusTrader::Conf::_get_home_path()."/.gt/sharenames"; |
58
|
0
|
0
|
|
|
|
|
if (-e $file) { |
59
|
0
|
0
|
|
|
|
|
open(NAMES, "<", "$file") || die "Can't open $file : $!\n"; |
60
|
0
|
|
|
|
|
|
foreach () { |
61
|
0
|
|
|
|
|
|
chomp; |
62
|
0
|
0
|
|
|
|
|
next unless $_; |
63
|
0
|
|
|
|
|
|
my ($c, $d) = split /\t/; |
64
|
0
|
0
|
|
|
|
|
if ($c) { |
65
|
0
|
|
|
|
|
|
$sharenames{$c} = $d; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
close NAMES; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
$loaded_sharenames = 1; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
0
|
|
|
|
|
( exists $sharenames{$code} ) |
73
|
|
|
|
|
|
|
? return $sharenames{$code} |
74
|
|
|
|
|
|
|
: return ""; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub get_db_name { |
78
|
0
|
|
|
0
|
0
|
|
return undef; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |