line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Quote::Bloomberg; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
2844
|
use strict; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
163
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
35
|
use LWP::UserAgent; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
50
|
|
6
|
5
|
|
|
5
|
|
115
|
use HTTP::Request::Common; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
326
|
|
7
|
5
|
|
|
5
|
|
37
|
use HTML::TreeBuilder; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
120
|
|
8
|
5
|
|
|
5
|
|
194
|
use Encode; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
588
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.57_03'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
37
|
use vars qw($BLOOMBERG_URL); |
|
5
|
|
|
|
|
20
|
|
|
5
|
|
|
|
|
3124
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$BLOOMBERG_URL = 'https://www.bloomberg.com/quote/'; |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
0
|
22
|
sub methods { return (bloomberg => \&bloomberg); } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
{ |
19
|
|
|
|
|
|
|
my @labels = qw/method last currency symbol isodate/; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
5
|
0
|
19
|
sub labels { return (bloomberg => \@labels); } |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub bloomberg { |
25
|
0
|
|
|
0
|
0
|
|
my $quoter = shift; |
26
|
0
|
|
|
|
|
|
my @symbols = @_; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
return unless @symbols; |
29
|
0
|
|
|
|
|
|
my ($ua, $reply, $url, %funds, $te, $table, $row, @value_currency, $name); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
foreach my $symbol (@symbols) { |
32
|
0
|
|
|
|
|
|
$name = $symbol; |
33
|
0
|
|
|
|
|
|
$url = $BLOOMBERG_URL; |
34
|
0
|
|
|
|
|
|
$url = $url . $name; |
35
|
0
|
|
|
|
|
|
$ua = LWP::UserAgent->new; |
36
|
0
|
|
|
|
|
|
my @ns_headers = ( |
37
|
|
|
|
|
|
|
'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:67.0) Gecko/20100101 Firefox/67.0', |
38
|
|
|
|
|
|
|
'Referer' => 'https://www.bloomberg.com/', |
39
|
|
|
|
|
|
|
'Accept' => '*/*', |
40
|
|
|
|
|
|
|
'Accept-Encoding' => 'br', |
41
|
|
|
|
|
|
|
'Accept-Language' => 'en-US,en;q=0.5', |
42
|
|
|
|
|
|
|
'Pragma' => 'no-cache', ); |
43
|
0
|
|
|
|
|
|
$reply = $ua->get($url, @ns_headers); |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
unless ($reply->is_success) { |
46
|
0
|
|
|
|
|
|
$funds{$symbol, "success"} = 0; |
47
|
0
|
|
|
|
|
|
$funds{$symbol, "errormsg"} = "HTTP failure"; |
48
|
0
|
|
|
|
|
|
next; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
eval { |
52
|
0
|
|
|
|
|
|
my $tree = HTML::TreeBuilder->new_from_content(decode_utf8 $reply->content); |
53
|
0
|
|
|
|
|
|
my $price = $tree->look_down(_tag=>'span', 'class'=>qr/^priceText_/)->as_text(); |
54
|
0
|
|
|
|
|
|
my $curr = $tree->look_down(_tag=>'span', 'class'=>qr/^currency_/)->as_text(); |
55
|
0
|
0
|
|
0
|
|
|
my $date = $tree->look_down(_tag=>'div', sub {defined($_[0]->attr('class')) and $_[0]->attr('class') =~ /time__/})->as_text(); |
|
0
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
$price =~ s/,//g; |
58
|
0
|
0
|
|
|
|
|
$date = $1 if $date =~ m|([0-9]{1,2}/[0-9]{1,2}/[0-9]{4})|; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$funds{$name, 'method'} = 'bloomberg'; |
61
|
0
|
|
|
|
|
|
$funds{$name, 'last'} = $price; |
62
|
0
|
|
|
|
|
|
$funds{$name, 'currency'} = $curr; |
63
|
0
|
|
|
|
|
|
$funds{$name, 'symbol'} = $name; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$quoter->store_date(\%funds, $name, {usdate => $date}); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$funds{$name, 'success'} = 1; |
68
|
|
|
|
|
|
|
}; |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if ($@) { |
71
|
0
|
|
|
|
|
|
$funds{$symbol, "success"} = 0; |
72
|
0
|
|
|
|
|
|
$funds{$symbol, "errormsg"} = "parse error"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
return %funds if wantarray; |
77
|
0
|
|
|
|
|
|
return \%funds; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Finance::Quote::Bloomberg - Obtain fund prices from Bloomberg.com |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
use Finance::Quote; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$q = Finance::Quote->new; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
%fundinfo = $q->fetch("bloomberg", "security"); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
This module obtains information about fund prices from www.bloomberg.com. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SECURITY NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
The security string must match the format expected by the site, such as |
101
|
|
|
|
|
|
|
'AAPL:US' not 'AAPL'. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 LABELS RETURNED |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Labels returned by this module include: last, currency, symbol, isodate |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 SEE ALSO |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Finance::Quote |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |