lib/Finance/Robinhood/Equity/Position.pm

filter: Statementstmt 55.0% 22 / 40 Branchbran 0.0% 0 / 8 Conditioncond 50.0% 5 / 10 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 66.6% 10 / 15 Podpod 100% 4 / 4 totaltotal 47.1% 41 / 87 CC 10 SCAR 15.0
CC
10
Cov
47%
instrument
12.0
account
12.0
_test_stringify
2.5
CRAP 4.5
« lib/Finance/Robinhood/Equity/Prices.pm ↑ Summary lib/Finance/Robinhood/User/AdditionalInfo.pm »
1 package Finance::Robinhood::Equity::Position;
2  
3 =encoding utf-8
4  
5 =for stopwords watchlist watchlists untradable urls
6  
7 =head1 NAME
8  
9 Finance::Robinhood::Equity::Position - Represents a Single Equity Position on a
10 Robinhood Account
11  
12 =head1 SYNOPSIS
13  
14 use Finance::Robinhood;
15 my $rh = Finance::Robinhood->new->login('user', 'pass');
16 my $account = $rh->equity_accounts->current();
17  
18 for my $position ($account->equity_positions) {
19 CORE::say $position->instrument->symbol;
20 }
21  
22 =cut
23  
24 1 our $VERSION = '0.92_003';
25 1 ▶use Mojo::Base-base, -signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Finance::Robinhood::Equity::Instrument;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶sub _test__init {
Subroutine _test__init: called CC=1 SCAR=4.1
30 1 my $rh = t::Utility::rh_instance(1);
31 0 my $acct = $rh->equity_accounts->current;
32 0 my $position = $acct->positions->current;
33 0 isa_ok($position, __PACKAGE__);
34 0 t::Utility::stash('POSITION', $position); # Store it for later
35 }
36 0 ▶use overload '""' => sub ($s, @) { $s->{url} }, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
37  
38 1 ▶sub _test_stringify {
Subroutine _test_stringify: called CC=2 SCAR=9.2
39 1 ▶ t::Utility::stash('POSITION') // skip_all();
Condition50%1/2
t::Utility::stash("POSITION") // skip_all()
l!l
01
MC/DC0%0/2
t::Utility::stash("POSITION") // skip_all()
t::Utility::stash("POSITION") skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("POSITION")B= skip_all()
ABresult
1X1
011
000
40 0 like(+t::Utility::stash('POSITION'),
41 qr'https://api.robinhood.com/accounts/.+/positions/.+/',);
42 }
43 ##
44  
45 =head1 METHODS
46  
47 =cut
48  
49 1 has _rh => undef => weak => 1;
50  
51 =head2 C<average_buy_price( )>
52  
53  
54 =head2 C<intraday_average_buy_price( )>
55  
56  
57 =head2 C<intraday_quantity( )>
58  
59  
60 =head2 C<pending_average_buy_price( )>
61  
62  
63 =head2 C<quantity( )>
64  
65  
66 =head2 C<shares_held_for_buys( )>
67  
68  
69 =head2 C<shares_held_for_options_collateral( )>
70  
71 Shares held for collateral for a sold call, etc.
72  
73 =head2 C<shares_held_for_options_events( )>
74  
75  
76 =head2 C<shares_held_for_sells( )>
77  
78 Shares that are marked to be sold in outstanding orders.
79  
80 =head2 C<shares_held_for_stock_grants( )>
81  
82 Shares that were a reward (referral, etc.) and must be held for a period before
83 they can be sold.
84  
85 =head2 C<shares_pending_from_options_events( )>
86  
87  
88 =cut
89  
90 1 has ['average_buy_price', 'intraday_average_buy_price',
91 'intraday_quantity', 'pending_average_buy_price',
92 'quantity', 'shares_held_for_buys',
93 'shares_held_for_options_collateral', 'shares_held_for_options_events',
94 'shares_held_for_sells', 'shares_held_for_stock_grants',
95 'shares_pending_from_options_events',
96 ];
97  
98 =head2 C<created_at( )>
99  
100 Returns a Time::Moment object.
101  
102 =cut
103  
104 0 ▶sub created_at ($s) {
Subroutine created_at: not called CC=1 SCAR=6.9
Pod documented
105 0 Time::Moment->from_string($s->{created_at});
106 }
107  
108 1 ▶sub _test_created_at {
Subroutine _test_created_at: called CC=2 SCAR=9.2
109 1 ▶ t::Utility::stash('POSITION') // skip_all('No position object in stash');
Condition50%1/2
t::Utility::stash("POSITION") // skip_all("No position object in stash")
l!l
01
MC/DC0%0/2
t::Utility::stash("POSITION") // skip_all("No position object in stash")
t::Utility::stash("POSITION") skip_all("No position object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("POSITION")B= skip_all("No position object in stash")
ABresult
1X1
011
000
110 0 isa_ok(t::Utility::stash('POSITION')->created_at, 'Time::Moment');
111 }
112  
113 =head2 C<updated_at( )>
114  
115 Returns a Time::Moment object.
116  
117 =cut
118  
119 0 ▶sub updated_at ($s) {
Subroutine updated_at: not called CC=1 SCAR=6.9
Pod documented
120 0 Time::Moment->from_string($s->{updated_at});
121 }
122  
123 1 ▶sub _test_updated_at {
Subroutine _test_updated_at: called CC=2 SCAR=9.2
124 1 ▶ t::Utility::stash('POSITION') // skip_all('No position object in stash');
Condition50%1/2
t::Utility::stash("POSITION") // skip_all("No position object in stash")
l!l
01
MC/DC0%0/2
t::Utility::stash("POSITION") // skip_all("No position object in stash")
t::Utility::stash("POSITION") skip_all("No position object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("POSITION")B= skip_all("No position object in stash")
ABresult
1X1
011
000
125 0 isa_ok(t::Utility::stash('POSITION')->updated_at, 'Time::Moment');
126 }
127  
128 =head2 C<instrument( )>
129  
130 Returns the related Finance::Robinhood::Equity::Instrument object.
131  
132 =cut
133  
134 0 ▶sub instrument ($s) {
Subroutine instrument: not called CC=3 SCAR=24.8
Pod documented
135 0 my $res = $s->_rh->_get($s->{instrument});
136 return $res->is_success
137 ? Finance::Robinhood::Equity::Instrument->new(_rh => $s->_rh,
138 0 ▶ %{$res->json})
Branch: 2 branches
BranchTrueFalseTotal
$res->is_success ? : 0 0 0
$res->is_server_error ? : 0 0 0
139 : Finance::Robinhood::Error->new(
140 $res->is_server_error ? (details => $res->message) : $res->json);
141 }
142  
143 1 ▶sub _test_instrument {
Subroutine _test_instrument: called CC=2 SCAR=9.2
144 1 ▶ t::Utility::stash('POSITION') // skip_all('No position object in stash');
Condition50%1/2
t::Utility::stash("POSITION") // skip_all("No position object in stash")
l!l
01
MC/DC0%0/2
t::Utility::stash("POSITION") // skip_all("No position object in stash")
t::Utility::stash("POSITION") skip_all("No position object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("POSITION")B= skip_all("No position object in stash")
ABresult
1X1
011
000
145 0 isa_ok(t::Utility::stash('POSITION')->instrument,
146 'Finance::Robinhood::Equity::Instrument');
147 }
148  
149 =head2 C<account( )>
150  
151 Returns the related Finance::Robinhood::Equity::Account object.
152  
153 =cut
154  
155 0 ▶sub account ($s) {
Subroutine account: not called CC=3 SCAR=24.8
Pod documented
156 0 my $res = $s->_rh->_get($s->{account});
157 return $res->is_success
158 ? Finance::Robinhood::Equity::Account->new(_rh => $s->_rh,
159 0 ▶ %{$res->json})
Branch: 2 branches
BranchTrueFalseTotal
$res->is_success ? : 0 0 0
$res->is_server_error ? : 0 0 0
160 : Finance::Robinhood::Error->new(
161 $res->is_server_error ? (details => $res->message) : $res->json);
162 }
163  
164 1 ▶sub _test_account {
Subroutine _test_account: called CC=2 SCAR=9.2
165 1 ▶ t::Utility::stash('POSITION') // skip_all('No position object in stash');
Condition50%1/2
t::Utility::stash("POSITION") // skip_all("No position object in stash")
l!l
01
MC/DC0%0/2
t::Utility::stash("POSITION") // skip_all("No position object in stash")
t::Utility::stash("POSITION") skip_all("No position object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("POSITION")B= skip_all("No position object in stash")
ABresult
1X1
011
000
166 0 isa_ok(t::Utility::stash('POSITION')->account,
167 'Finance::Robinhood::Equity::Account');
168 }
169  
170 =head1 LEGAL
171  
172 This is a simple wrapper around the API used in the official apps. The author
173 provides no investment, legal, or tax advice and is not responsible for any
174 damages incurred while using this software. This software is not affiliated
175 with Robinhood Financial LLC in any way.
176  
177 For Robinhood's terms and disclosures, please see their website at
178 https://robinhood.com/legal/
179  
180 =head1 LICENSE
181  
182 Copyright (C) Sanko Robinson.
183  
184 This library is free software; you can redistribute it and/or modify it under
185 the terms found in the Artistic License 2. Other copyrights, terms, and
186 conditions may apply to data transmitted through this module. Please refer to
187 the L<LEGAL> section.
188  
189 =head1 AUTHOR
190  
191 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
192  
193 =cut
194  
195 1 1;
« lib/Finance/Robinhood/Equity/Prices.pm ↑ Summary lib/Finance/Robinhood/User/AdditionalInfo.pm »