lib/Finance/Robinhood/Equity/Market/Hours.pm

filter: Statementstmt 100% 67 / 67 Branchbran 62.5% 10 / 16 Conditioncond 50.0% 16 / 32 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 100% 21 / 21 Podpod 100% 7 / 7 totaltotal 69.1% 121 / 175 CC 25 SCAR 9.9
CC
25
Cov
81%
next_open_hours
3.7
previous_open_hours
3.7
_test_stringify
3.1
CRAP 2.7
« lib/Finance/Robinhood/User/InternationalInfo.pm ↑ Summary lib/Finance/Robinhood/Forex/Holding.pm »
1 package Finance::Robinhood::Equity::Market::Hours;
2  
3 =encoding utf-8
4  
5 =for stopwords watchlist watchlists untradable urls
6  
7 =head1 NAME
8  
9 Finance::Robinhood::Equity::Market::Hours - Represents an Equity Market's
10 Operating Hours
11  
12 =head1 SYNOPSIS
13  
14 use Finance::Robinhood;
15 my $rh = Finance::Robinhood->new;
16 my $nyse = $rh->equity_market_by_mic('XNAS');
17  
18 CORE::say 'The Nasdaq is ' . ($nyse->hours->is_open ? '' : 'not ' ) . 'open today';
19  
20 =cut
21  
22 1 our $VERSION = '0.92_003';
23 1 ▶use Mojo::Base-base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Time::Moment;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶sub _test__init {
Subroutine _test__init: called CC=1 SCAR=0.0
28 1 my $rh = t::Utility::rh_instance(0);
29 1 my $open = $rh->equity_market_by_mic('XNAS')
30 ->hours(Time::Moment->from_epoch(1552613507))
31 ; # NASDAQ - March 15th, 2019
32 1 isa_ok($open, __PACKAGE__);
33 1 t::Utility::stash('HOURS_OPEN', $open); # Store it for later
34 1 my $closed = $rh->equity_market_by_mic('XNAS')
35 ->hours(Time::Moment->from_epoch(1552699907))
36 ; # NASDAQ - March 16th, 2019
37 1 isa_ok($closed, __PACKAGE__);
38 1 t::Utility::stash('HOURS_CLOSED', $closed); # Store it for later
39 }
40 1 ▶use overload '""' => sub ($s, @) { $s->{date} }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
41  
42 1 ▶sub _test_stringify {
Subroutine _test_stringify: called CC=3 SCAR=11.4
43 1 ▶ t::Utility::stash('HOURS_OPEN') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_OPEN") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_OPEN") // skip_all()
t::Utility::stash("HOURS_OPEN") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_OPEN")B= skip_all()
ABresult
1X1
011
000
44 1 is(+t::Utility::stash('HOURS_OPEN'), '2019-03-15');
45 1 ▶ t::Utility::stash('HOURS_CLOSED') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
t::Utility::stash("HOURS_CLOSED") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_CLOSED")B= skip_all()
ABresult
1X1
011
000
46 1 is(+t::Utility::stash('HOURS_CLOSED'), '2019-03-16');
47 }
48 #
49 1 has _rh => undef => weak => 1;
50  
51 =head1 METHODS
52  
53 =head2 C<is_open( )>
54  
55 Returns a true value if opens for trading on this date.
56  
57 =cut
58  
59 1 has ['is_open'];
60  
61 =head2 C<opens_at( )>
62  
63 $hours->opens_at;
64  
65 If the market opens today, this returns a Time::Moment object.
66  
67 =cut
68  
69 2 ▶sub opens_at ($s) {
Subroutine opens_at: called CC=2 SCAR=6.9
Pod documented
70 2 ▶ $s->{closes_at} ? Time::Moment->from_string($s->{opens_at}) : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'closes_at'} ? : 1 1 2
71 }
72  
73 1 ▶sub _test_opens_at {
Subroutine _test_opens_at: called CC=3 SCAR=11.4
74 1 ▶ t::Utility::stash('HOURS_OPEN') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_OPEN") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_OPEN") // skip_all()
t::Utility::stash("HOURS_OPEN") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_OPEN")B= skip_all()
ABresult
1X1
011
000
75 1 is(t::Utility::stash('HOURS_OPEN')->opens_at->to_string,
76 '2019-03-15T13:30:00Z');
77 1 ▶ t::Utility::stash('HOURS_CLOSED') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
t::Utility::stash("HOURS_CLOSED") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_CLOSED")B= skip_all()
ABresult
1X1
011
000
78 1 is(t::Utility::stash('HOURS_CLOSED')->opens_at, ());
79 }
80  
81 =head2 C<closes_at( )>
82  
83 $hours->closes_at;
84  
85 If the market was open, this returns a Time::Moment object.
86  
87 =cut
88  
89 2 ▶sub closes_at ($s) {
Subroutine closes_at: called CC=2 SCAR=6.9
Pod documented
90 2 ▶ $s->{closes_at} ? Time::Moment->from_string($s->{closes_at}) : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'closes_at'} ? : 1 1 2
91 }
92  
93 1 ▶sub _test_closes_at {
Subroutine _test_closes_at: called CC=3 SCAR=11.4
94 1 ▶ t::Utility::stash('HOURS_OPEN') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_OPEN") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_OPEN") // skip_all()
t::Utility::stash("HOURS_OPEN") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_OPEN")B= skip_all()
ABresult
1X1
011
000
95 1 is(t::Utility::stash('HOURS_OPEN')->closes_at->to_string,
96 '2019-03-15T20:00:00Z');
97 1 ▶ t::Utility::stash('HOURS_CLOSED') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
t::Utility::stash("HOURS_CLOSED") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_CLOSED")B= skip_all()
ABresult
1X1
011
000
98 1 is(t::Utility::stash('HOURS_CLOSED')->closes_at, ());
99 }
100  
101 =head2 C<extended_opens_at( )>
102  
103 $hours->extended_opens_at;
104  
105 If the market was open and had an extended hours trading session, this returns
106 a Time::Moment object.
107  
108 =cut
109  
110 2 ▶sub extended_opens_at ($s) {
Subroutine extended_opens_at: called CC=2 SCAR=6.9
Pod documented
111 $s->{extended_opens_at}
112 ? Time::Moment->from_string($s->{extended_opens_at})
113 2 ▶ : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'extended_opens_at'} ? : 1 1 2
114 }
115  
116 1 ▶sub _test_extended_opens_at {
Subroutine _test_extended_opens_at: called CC=3 SCAR=11.4
117 1 ▶ t::Utility::stash('HOURS_OPEN') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_OPEN") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_OPEN") // skip_all()
t::Utility::stash("HOURS_OPEN") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_OPEN")B= skip_all()
ABresult
1X1
011
000
118 1 is(t::Utility::stash('HOURS_OPEN')->extended_opens_at->to_string,
119 '2019-03-15T13:00:00Z');
120 1 ▶ t::Utility::stash('HOURS_CLOSED') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
t::Utility::stash("HOURS_CLOSED") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_CLOSED")B= skip_all()
ABresult
1X1
011
000
121 1 is(t::Utility::stash('HOURS_CLOSED')->extended_opens_at, ());
122 }
123  
124 =head2 C<extended_closes_at( )>
125  
126 $hours->extended_closes_at;
127  
128 If the market was open and had an extended hours trading session, this returns
129 a Time::Moment object.
130  
131 =cut
132  
133 2 ▶sub extended_closes_at ($s) {
Subroutine extended_closes_at: called CC=2 SCAR=6.9
Pod documented
134 $s->{extended_closes_at}
135 ? Time::Moment->from_string($s->{extended_closes_at})
136 2 ▶ : ();
Branch: 1 branch
BranchTrueFalseTotal
$s->{'extended_closes_at'} ? : 1 1 2
137 }
138  
139 1 ▶sub _test_extended_closes_at {
Subroutine _test_extended_closes_at: called CC=3 SCAR=11.4
140 1 ▶ t::Utility::stash('HOURS_OPEN') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_OPEN") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_OPEN") // skip_all()
t::Utility::stash("HOURS_OPEN") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_OPEN")B= skip_all()
ABresult
1X1
011
000
141 1 is(t::Utility::stash('HOURS_OPEN')->extended_closes_at->to_string,
142 '2019-03-15T22:00:00Z');
143 1 ▶ t::Utility::stash('HOURS_CLOSED') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
t::Utility::stash("HOURS_CLOSED") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_CLOSED")B= skip_all()
ABresult
1X1
011
000
144 1 is(t::Utility::stash('HOURS_CLOSED')->extended_closes_at, ());
145 }
146  
147 =head2 C<date( )>
148  
149 $hours->date;
150  
151 Returns a Time::Moment object.
152  
153 =cut
154  
155 8 ▶sub date ($s) {
Subroutine date: called CC=1 SCAR=0.0
Pod documented
156 8 Time::Moment->from_string($s->{date} . 'T00:00:00Z');
157 }
158  
159 1 ▶sub _test_date {
Subroutine _test_date: called CC=3 SCAR=11.4
160 1 ▶ t::Utility::stash('HOURS_OPEN') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_OPEN") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_OPEN") // skip_all()
t::Utility::stash("HOURS_OPEN") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_OPEN")B= skip_all()
ABresult
1X1
011
000
161 1 is(t::Utility::stash('HOURS_OPEN')->date->to_string,
162 '2019-03-15T00:00:00Z');
163 1 ▶ t::Utility::stash('HOURS_CLOSED') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
t::Utility::stash("HOURS_CLOSED") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_CLOSED")B= skip_all()
ABresult
1X1
011
000
164 1 is(t::Utility::stash('HOURS_CLOSED')->date->to_string,
165 '2019-03-16T00:00:00Z');
166 }
167  
168 =head2 C<next_open_hours( )>
169  
170 This returns a Finance::Robinhood::Equity::Market::Hours object for the next
171 day the market is open.
172  
173 =cut
174  
175 2 ▶sub next_open_hours( $s ) {
Subroutine next_open_hours: called CC=3 SCAR=13.1
Pod documented
176 2 my $res = $s->_rh->_get($s->{next_open_hours});
177 $res->is_success
178 ? Finance::Robinhood::Equity::Market::Hours->new(_rh => $s->_rh,
179 2 ▶ %{$res->json})
Branch: 2 branches
BranchTrueFalseTotal
$res->is_success ? : 2 0 2
$res->is_server_error ? : 0 0 0
180 : Finance::Robinhood::Error->new(
181 $res->is_server_error ? (details => $res->message) : $res->json);
182 }
183  
184 1 ▶sub _test_next_open_hours {
Subroutine _test_next_open_hours: called CC=3 SCAR=11.4
185 1 ▶ t::Utility::stash('HOURS_OPEN') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_OPEN") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_OPEN") // skip_all()
t::Utility::stash("HOURS_OPEN") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_OPEN")B= skip_all()
ABresult
1X1
011
000
186 1 is(t::Utility::stash('HOURS_OPEN')->next_open_hours->date->to_string,
187 '2019-03-18T00:00:00Z');
188 1 ▶ t::Utility::stash('HOURS_CLOSED') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
t::Utility::stash("HOURS_CLOSED") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_CLOSED")B= skip_all()
ABresult
1X1
011
000
189 1 is(t::Utility::stash('HOURS_CLOSED')->next_open_hours->date->to_string,
190 '2019-03-18T00:00:00Z');
191 }
192  
193 =head2 C<previous_open_hours( )>
194  
195 This returns a Finance::Robinhood::Equity::Market::Hours object for the
196 previous day the market was open.
197  
198 =cut
199  
200 2 ▶sub previous_open_hours( $s ) {
Subroutine previous_open_hours: called CC=3 SCAR=13.1
Pod documented
201 2 my $res = $s->_rh->_get($s->{previous_open_hours});
202 $res->is_success
203 ? Finance::Robinhood::Equity::Market::Hours->new(_rh => $s->_rh,
204 2 ▶ %{$res->json})
Branch: 2 branches
BranchTrueFalseTotal
$res->is_success ? : 2 0 2
$res->is_server_error ? : 0 0 0
205 : Finance::Robinhood::Error->new(
206 $res->is_server_error ? (details => $res->message) : $res->json);
207 }
208  
209 1 ▶sub _test_previous_open_hours {
Subroutine _test_previous_open_hours: called CC=3 SCAR=11.4
210 1 ▶ t::Utility::stash('HOURS_OPEN') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_OPEN") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_OPEN") // skip_all()
t::Utility::stash("HOURS_OPEN") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_OPEN")B= skip_all()
ABresult
1X1
011
000
211 1 is(t::Utility::stash('HOURS_OPEN')->previous_open_hours->date->to_string,
212 '2019-03-14T00:00:00Z');
213 1 ▶ t::Utility::stash('HOURS_CLOSED') // skip_all();
Condition50%1/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
l!l
10
MC/DC0%0/2
t::Utility::stash("HOURS_CLOSED") // skip_all()
t::Utility::stash("HOURS_CLOSED") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("HOURS_CLOSED")B= skip_all()
ABresult
1X1
011
000
214 1 is( t::Utility::stash('HOURS_CLOSED')
215 ->previous_open_hours->date->to_string,
216 '2019-03-15T00:00:00Z'
217 );
218 }
219  
220 =head1 LEGAL
221  
222 This is a simple wrapper around the API used in the official apps. The author
223 provides no investment, legal, or tax advice and is not responsible for any
224 damages incurred while using this software. This software is not affiliated
225 with Robinhood Financial LLC in any way.
226  
227 For Robinhood's terms and disclosures, please see their website at
228 https://robinhood.com/legal/
229  
230 =head1 LICENSE
231  
232 Copyright (C) Sanko Robinson.
233  
234 This library is free software; you can redistribute it and/or modify it under
235 the terms found in the Artistic License 2. Other copyrights, terms, and
236 conditions may apply to data transmitted through this module. Please refer to
237 the L<LEGAL> section.
238  
239 =head1 AUTHOR
240  
241 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
242  
243 =cut
244  
245 1 1;
« lib/Finance/Robinhood/User/InternationalInfo.pm ↑ Summary lib/Finance/Robinhood/Forex/Holding.pm »