line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Instrument::Domain; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
254591
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
229
|
|
4
|
6
|
|
|
6
|
|
183
|
use 5.008_001; |
|
6
|
|
|
|
|
23
|
|
|
6
|
|
|
|
|
316
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
2032
|
use Moose; |
|
6
|
|
|
|
|
1060608
|
|
|
6
|
|
|
|
|
46
|
|
8
|
6
|
|
|
6
|
|
46609
|
use methods; |
|
6
|
|
|
|
|
81730
|
|
|
6
|
|
|
|
|
50
|
|
9
|
6
|
|
|
6
|
|
24268
|
use File::ShareDir (); |
|
6
|
|
|
|
|
44038
|
|
|
6
|
|
|
|
|
199
|
|
10
|
6
|
|
|
6
|
|
5730
|
use YAML::Syck qw(LoadFile); |
|
6
|
|
|
|
|
16045
|
|
|
6
|
|
|
|
|
489
|
|
11
|
6
|
|
|
6
|
|
8060
|
use Text::CSV; |
|
6
|
|
|
|
|
89259
|
|
|
6
|
|
|
|
|
46
|
|
12
|
6
|
|
|
6
|
|
4712
|
use Finance::Instrument::Exchange; |
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
1047
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has instruments => (is => "rw", isa => "HashRef", default => sub { {} }); |
15
|
|
|
|
|
|
|
has exchanges => (is => "rw", isa => "HashRef", |
16
|
|
|
|
|
|
|
traits => ['Hash'], |
17
|
|
|
|
|
|
|
default => sub { {} }, |
18
|
|
|
|
|
|
|
handles => { |
19
|
|
|
|
|
|
|
get_exchange => 'get' |
20
|
|
|
|
|
|
|
}); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $GLOBAL; |
23
|
|
|
|
|
|
|
|
24
|
6
|
|
|
6
|
|
2220
|
method global { |
|
14
|
|
|
14
|
|
43
|
|
|
14
|
|
|
|
|
30
|
|
25
|
14
|
|
66
|
|
|
464
|
$GLOBAL ||= __PACKAGE__->new; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
6
|
|
|
6
|
|
2060
|
method load_default_exchanges { |
|
2
|
|
|
2
|
|
1061
|
|
|
2
|
|
|
|
|
6
|
|
29
|
2
|
|
|
|
|
17
|
my $file = File::ShareDir::dist_file('Finance-Instrument', 'iso10383_mic.csv'); |
30
|
2
|
50
|
|
2
|
|
669
|
open my $fh, '<:encoding(utf8)', $file or die "$file: $!"; |
|
2
|
|
|
|
|
20
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
25
|
|
31
|
2
|
|
|
|
|
29917
|
my $csv = Text::CSV->new; |
32
|
2
|
|
|
|
|
220
|
my $header = $csv->getline( $fh ); |
33
|
2
|
|
|
|
|
27802
|
my %header_map = ( |
34
|
|
|
|
|
|
|
'MIC' => 'code', |
35
|
|
|
|
|
|
|
'INSTITUTION DESCRIPTION' => 'name', |
36
|
|
|
|
|
|
|
'CC' => 'country', |
37
|
|
|
|
|
|
|
'ACR' => 'abbr', |
38
|
|
|
|
|
|
|
); |
39
|
2
|
|
|
|
|
17
|
while ( my $row = $csv->getline( $fh ) ) { |
40
|
1606
|
|
|
|
|
773995
|
my $entry = {}; |
41
|
1606
|
|
|
|
|
2741
|
@{$entry}{@$header} = @$row; |
|
1606
|
|
|
|
|
12525
|
|
42
|
6424
|
|
|
|
|
88031
|
Finance::Instrument::Exchange->new( |
43
|
|
|
|
|
|
|
domain => $self, |
44
|
1606
|
|
|
|
|
5246
|
map { $header_map{$_} => $entry->{$_} } keys %header_map |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
6
|
|
|
6
|
|
3449
|
method add_exchange($ex) { |
|
1609
|
|
|
1609
|
|
2043
|
|
|
1609
|
|
|
|
|
1875
|
|
|
1609
|
|
|
|
|
1512
|
|
51
|
1609
|
|
|
|
|
61737
|
$self->exchanges->{ $ex->code } = $ex; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
6
|
|
|
6
|
|
2113
|
method load_instrument($args) { |
|
1
|
|
|
1
|
|
920
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
55
|
1
|
|
|
|
|
3
|
my $type = delete $args->{type}; |
56
|
1
|
50
|
|
|
|
8
|
$type = 'Finance::Instrument::'.$type |
57
|
|
|
|
|
|
|
unless $type =~ s/^\+//; |
58
|
1
|
|
|
|
|
9
|
Class::Load::load_class($type); |
59
|
|
|
|
|
|
|
|
60
|
1
|
50
|
|
|
|
46
|
unless (ref $args->{exchange}) { |
61
|
1
|
|
|
|
|
4
|
my $exchange_name = delete $args->{exchange}; |
62
|
1
|
|
33
|
|
|
44
|
$args->{exchange} = $self->exchanges->{$exchange_name} |
63
|
|
|
|
|
|
|
||= Finance::Instrument::Exchange->new( name => $exchange_name, |
64
|
|
|
|
|
|
|
code => $exchange_name, |
65
|
|
|
|
|
|
|
domain => $self); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
48
|
$type->new(%$args, domain => $self); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
6
|
|
|
6
|
|
2749
|
method load_instrument_from_yml($file) { |
|
1
|
|
|
1
|
|
317
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
72
|
1
|
|
|
|
|
6
|
$self->load_instrument(LoadFile($file)); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
6
|
|
|
6
|
|
2211
|
method load_default_instrument($name) { |
|
1
|
|
|
1
|
|
190
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
76
|
1
|
|
|
|
|
10
|
$self->load_instrument_from_yml(File::ShareDir::dist_file('Finance-Instrument', $name.'.yml')); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
6
|
|
|
6
|
|
2108
|
method add($i) { |
|
9
|
|
|
9
|
|
22
|
|
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
18
|
|
80
|
9
|
|
|
|
|
398
|
$self->instruments->{ $i->exchange->code.'.'.$i->code } = $i; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
6
|
|
|
6
|
|
2173
|
method get($name) { |
|
4
|
|
|
4
|
|
16
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
7
|
|
84
|
4
|
|
|
|
|
166
|
$self->instruments->{ $name }; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
__END__ |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=encoding utf-8 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=for stopwords |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 NAME |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Finance::Instrument - |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SYNOPSIS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use Finance::Instrument; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 DESCRIPTION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Finance::Instrument is |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 AUTHOR |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Chia-liang Kao E<lt>clkao@clkao.orgE<gt> |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 LICENSE |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
113
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 SEE ALSO |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |