line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Quote::IEX; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: (DEPRECATED) Retrieve stock quotes using the IEX API |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
150732
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
7
|
1
|
|
|
1
|
|
795
|
use DateTime; |
|
1
|
|
|
|
|
454663
|
|
|
1
|
|
|
|
|
60
|
|
8
|
1
|
|
|
1
|
|
761
|
use JSON qw(decode_json); |
|
1
|
|
|
|
|
10218
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
780
|
use HTTP::Status qw(status_message); |
|
1
|
|
|
|
|
5726
|
|
|
1
|
|
|
|
|
613
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
warnings::warnif( 'deprecated', |
12
|
|
|
|
|
|
|
'Finance::Quote::IEX is deprecated and should no longer be used' ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.002000'; # VERSION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub methods { |
17
|
|
|
|
|
|
|
return ( |
18
|
0
|
|
|
0
|
0
|
|
iex => \&iex, |
19
|
|
|
|
|
|
|
usa => \&iex, |
20
|
|
|
|
|
|
|
nasdaq => \&iex, |
21
|
|
|
|
|
|
|
nyse => \&iex, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub labels { |
26
|
0
|
|
|
0
|
0
|
|
my @labels = qw/ |
27
|
|
|
|
|
|
|
name |
28
|
|
|
|
|
|
|
last |
29
|
|
|
|
|
|
|
date |
30
|
|
|
|
|
|
|
isodate |
31
|
|
|
|
|
|
|
time |
32
|
|
|
|
|
|
|
net |
33
|
|
|
|
|
|
|
p_change |
34
|
|
|
|
|
|
|
volume |
35
|
|
|
|
|
|
|
close |
36
|
|
|
|
|
|
|
open |
37
|
|
|
|
|
|
|
year_range |
38
|
|
|
|
|
|
|
pe |
39
|
|
|
|
|
|
|
cap |
40
|
|
|
|
|
|
|
exchange |
41
|
|
|
|
|
|
|
method |
42
|
|
|
|
|
|
|
price |
43
|
|
|
|
|
|
|
currency |
44
|
|
|
|
|
|
|
/; |
45
|
|
|
|
|
|
|
return ( |
46
|
0
|
|
|
|
|
|
iex => \@labels, |
47
|
|
|
|
|
|
|
usa => \@labels, |
48
|
|
|
|
|
|
|
nasdaq => \@labels, |
49
|
|
|
|
|
|
|
nyse => \@labels, |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub iex { |
54
|
0
|
|
|
0
|
0
|
|
my $quoter = shift; |
55
|
0
|
|
|
|
|
|
my @stocks = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $iex_url = 'https://api.iextrading.com/1.0/stock/%s/quote'; |
58
|
0
|
|
|
|
|
|
my $errormsg = 'Error retrieving quote for "%s": GET "%s" resulted in' |
59
|
|
|
|
|
|
|
. ' HTTP response %d (%s)'; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $ua = $quoter->user_agent(); |
62
|
0
|
|
|
|
|
|
my %info; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
foreach my $symbol (@stocks) { |
65
|
0
|
|
|
|
|
|
my $url = sprintf( $iex_url, $symbol ); |
66
|
0
|
|
|
|
|
|
my $response = $ua->get($url); |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ( !$response->is_success ) { |
69
|
0
|
|
|
|
|
|
my $code = $response->code; |
70
|
0
|
|
|
|
|
|
my $desc = status_message($code); |
71
|
0
|
|
|
|
|
|
$info{ $symbol, 'success' } = 0; |
72
|
0
|
|
|
|
|
|
$info{ $symbol, 'errormsg' } |
73
|
|
|
|
|
|
|
= sprintf( $errormsg, $symbol, $url, $code, $desc ); |
74
|
0
|
|
|
|
|
|
next; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $data = decode_json( $response->decoded_content ); |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
|
if ( !defined $data->{latestPrice} ) { |
80
|
0
|
|
|
|
|
|
my $code = $response->code; |
81
|
0
|
|
|
|
|
|
my $desc = status_message($code); |
82
|
0
|
|
|
|
|
|
$info{ $symbol, 'success' } = 0; |
83
|
0
|
|
|
|
|
|
$info{ $symbol, 'errormsg' } = sprintf( |
84
|
|
|
|
|
|
|
'Error retrieving quote for "%s":' |
85
|
|
|
|
|
|
|
. ' no price found in response data', |
86
|
|
|
|
|
|
|
$symbol |
87
|
|
|
|
|
|
|
); |
88
|
0
|
|
|
|
|
|
next; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
|
if ( !defined $data->{latestUpdate} ) { |
92
|
0
|
|
|
|
|
|
my $code = $response->code; |
93
|
0
|
|
|
|
|
|
my $desc = status_message($code); |
94
|
0
|
|
|
|
|
|
$info{ $symbol, 'success' } = 0; |
95
|
0
|
|
|
|
|
|
$info{ $symbol, 'errormsg' } = sprintf( |
96
|
|
|
|
|
|
|
'Error retrieving quote for "%s":' |
97
|
|
|
|
|
|
|
. ' no date found in response data', |
98
|
|
|
|
|
|
|
$symbol |
99
|
|
|
|
|
|
|
); |
100
|
0
|
|
|
|
|
|
next; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
$info{ $symbol, 'success' } = 1; |
104
|
0
|
|
|
|
|
|
$info{ $symbol, 'method' } = 'iex'; |
105
|
0
|
|
|
|
|
|
$info{ $symbol, 'source' } = 'Finance::Quote::IEX'; |
106
|
0
|
|
|
|
|
|
$info{ $symbol, 'currency' } = 'USD'; |
107
|
0
|
|
|
|
|
|
$info{ $symbol, 'symbol' } = $data->{symbol}; |
108
|
|
|
|
|
|
|
$info{ $symbol, 'name' } |
109
|
0
|
|
|
|
|
|
= $symbol . ' (' . $data->{companyName} . ')'; |
110
|
0
|
|
|
|
|
|
$info{ $symbol, 'last' } = $data->{latestPrice}; |
111
|
0
|
|
|
|
|
|
$info{ $symbol, 'price' } = $data->{latestPrice}; |
112
|
0
|
|
|
|
|
|
$info{ $symbol, 'net' } = $data->{change}; |
113
|
0
|
|
|
|
|
|
$info{ $symbol, 'p_change' } = $data->{changePercent}; |
114
|
0
|
|
|
|
|
|
$info{ $symbol, 'volume' } = $data->{latestVolume}; |
115
|
0
|
|
|
|
|
|
$info{ $symbol, 'close' } = $data->{close}; |
116
|
0
|
|
|
|
|
|
$info{ $symbol, 'open' } = $data->{open}; |
117
|
|
|
|
|
|
|
$info{ $symbol, 'year_range' } |
118
|
0
|
|
|
|
|
|
= $data->{week52Low} . ' - ' . $data->{week52High}; |
119
|
0
|
|
|
|
|
|
$info{ $symbol, 'pe' } = $data->{peRatio}; |
120
|
0
|
|
|
|
|
|
$info{ $symbol, 'cap' } = $data->{marketCap}; |
121
|
0
|
|
|
|
|
|
$info{ $symbol, 'exchange' } = $data->{exchange}; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# The Finance::Quote documentation indicates that the date shouldn't |
124
|
|
|
|
|
|
|
# be parsed, but store_date does not support epoch time. |
125
|
|
|
|
|
|
|
my $dt |
126
|
0
|
|
|
|
|
|
= DateTime->from_epoch( epoch => $data->{latestUpdate} / 1000 ); |
127
|
0
|
|
|
|
|
|
$info{ $symbol, 'time' } = $dt->hms; |
128
|
0
|
|
|
|
|
|
$info{ $symbol, 'date' } = $dt->strftime('%m/%d/%y'); |
129
|
0
|
|
|
|
|
|
$info{ $symbol, 'isodate' } = $dt->ymd; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
return wantarray() ? %info : \%info; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
__END__ |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=pod |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=encoding UTF-8 |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 NAME |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Finance::Quote::IEX - (DEPRECATED) Retrieve stock quotes using the IEX API |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 VERSION |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
version 0.002000 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 SYNOPSIS |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
use Finance::Quote; |
154
|
|
|
|
|
|
|
my $q = Finance::Quote->new('IEX'); |
155
|
|
|
|
|
|
|
my %info = Finance::Quote->fetch( 'iex', 'AAPL' ); |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 DESCRIPTION |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
This module fetches information from the IEX API. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This module is not loaded by default on a Finance::Quote object. It |
162
|
|
|
|
|
|
|
must be loaded explicitly by placing C<'IEX'> in the argument list to |
163
|
|
|
|
|
|
|
C<< Finance::Quote->new() >>. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
This module provides the C<iex> fetch method. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 DEPRECATED |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
B<This module is deprecated. Use L<Finance::Quote::IEXCloud> instead.> |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
B<The IEX API removed all non-IEX data in June 2019.> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 ATTRIBUTION |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
If you redistribute IEX API data: |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over 4 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item * |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Cite IEX using the following text and link: "Data provided for free by |
182
|
|
|
|
|
|
|
L<IEX|https://iextrading.com/developer>." |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Provide a link to L<https://iextrading.com/api-exhibit-a> in your terms of |
187
|
|
|
|
|
|
|
service. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=back |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Additionally, if you display our TOPS price data, cite |
192
|
|
|
|
|
|
|
"L<IEX Real-Time Price|https://iextrading.com/developer>" near the price. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 LABELS RETURNED |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
The following labels may be returned by C<Finance::Quote::IEX>: name, last, date, |
197
|
|
|
|
|
|
|
time, net, p_change, volume, close, open, year_range, pe, cap, exchange, method |
198
|
|
|
|
|
|
|
and price. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 SEE ALSO |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=over 4 |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item * L<Finance::Quote> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * L<Finance::Quote::IEXCloud> |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item * L<https://iextrading.com/developer/docs/> |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=back |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head1 AUTHOR |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Jeffrey T. Palmer <jtpalmer@cpan.org> |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
This software is Copyright (c) 2019 by Jeffrey T. Palmer. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
This is free software, licensed under: |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
The MIT (X11) License |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |