File Coverage

lib/Finance/Robinhood/Equity/Position.pm
Criterion Covered Total %
statement 18 51 35.2
branch 0 8 0.0
condition 5 10 50.0
subroutine 10 15 66.6
pod 4 4 100.0
total 37 88 42.0


line stmt bran cond sub pod time code
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             our $VERSION = '0.92_001';
25 1     1   7 use Mojo::Base-base, -signatures;
  1         2  
  1         7  
26 1     1   183 use Mojo::URL;
  1         2  
  1         5  
27 1     1   24 use Finance::Robinhood::Equity::Instrument;
  1         2  
  1         16  
28              
29             sub _test__init {
30 1     1   14170 my $rh = t::Utility::rh_instance(1);
31 0         0 my $acct = $rh->equity_accounts->current;
32 0         0 my $position = $acct->positions->current;
33 0         0 isa_ok( $position, __PACKAGE__ );
34 0         0 t::Utility::stash( 'POSITION', $position ); # Store it for later
35             }
36 1     1   149 use overload '""' => sub ( $s, @ ) { $s->{url} }, fallback => 1;
  1     0   2  
  1         7  
  0         0  
  0         0  
  0         0  
  0         0  
37              
38             sub _test_stringify {
39 1   50 1   1887 t::Utility::stash('POSITION') // skip_all();
40 0         0 like(
41             +t::Utility::stash('POSITION'), qr'https://api.robinhood.com/accounts/.+/positions/.+/',
42             );
43             }
44             ##
45              
46             =head1 METHODS
47              
48             =cut
49              
50             has _rh => undef => weak => 1;
51              
52             =head2 C
53              
54              
55             =head2 C
56              
57              
58             =head2 C
59              
60              
61             =head2 C
62              
63              
64             =head2 C
65              
66              
67             =head2 C
68              
69              
70             =head2 C
71              
72             Shares held for collateral for a sold call, etc.
73              
74             =head2 C
75              
76              
77             =head2 C
78              
79             Shares that are marked to be sold in outstanding orders.
80              
81             =head2 C
82              
83             Shares that were a reward (referral, etc.) and must be held for a period before
84             they can be sold.
85              
86             =head2 C
87              
88              
89             =cut
90              
91             has [
92             'average_buy_price', 'intraday_average_buy_price',
93             'intraday_quantity', 'pending_average_buy_price',
94             'quantity', 'shares_held_for_buys',
95             'shares_held_for_options_collateral', 'shares_held_for_options_events',
96             'shares_held_for_sells', 'shares_held_for_stock_grants',
97             'shares_pending_from_options_events',
98             ];
99              
100             =head2 C
101              
102             Returns a Time::Moment object.
103              
104             =cut
105              
106 0     0 1 0 sub created_at ($s) {
  0         0  
  0         0  
107 0         0 Time::Moment->from_string( $s->{created_at} );
108             }
109              
110             sub _test_created_at {
111 1   50 1   1895 t::Utility::stash('POSITION') // skip_all('No position object in stash');
112 0         0 isa_ok( t::Utility::stash('POSITION')->created_at, 'Time::Moment' );
113             }
114              
115             =head2 C
116              
117             Returns a Time::Moment object.
118              
119             =cut
120              
121 0     0 1 0 sub updated_at ($s) {
  0         0  
  0         0  
122 0         0 Time::Moment->from_string( $s->{updated_at} );
123             }
124              
125             sub _test_updated_at {
126 1   50 1   1857 t::Utility::stash('POSITION') // skip_all('No position object in stash');
127 0         0 isa_ok( t::Utility::stash('POSITION')->updated_at, 'Time::Moment' );
128             }
129              
130             =head2 C
131              
132             Returns the related Finance::Robinhood::Equity::Instrument object.
133              
134             =cut
135              
136 0     0 1 0 sub instrument ($s) {
  0         0  
  0         0  
137 0         0 my $res = $s->_rh->_get( $s->{instrument} );
138             return $res->is_success
139 0 0       0 ? Finance::Robinhood::Equity::Instrument->new( _rh => $s->_rh, %{ $res->json } )
  0 0       0  
140             : Finance::Robinhood::Error->new(
141             $res->is_server_error ? ( details => $res->message ) : $res->json );
142             }
143              
144             sub _test_instrument {
145 1   50 1   1851 t::Utility::stash('POSITION') // skip_all('No position object in stash');
146 0         0 isa_ok( t::Utility::stash('POSITION')->instrument, 'Finance::Robinhood::Equity::Instrument' );
147             }
148              
149             =head2 C
150              
151             Returns the related Finance::Robinhood::Equity::Account object.
152              
153             =cut
154              
155 0     0 1 0 sub account ($s) {
  0         0  
  0         0  
156 0         0 my $res = $s->_rh->_get( $s->{account} );
157             return $res->is_success
158 0 0       0 ? Finance::Robinhood::Equity::Account->new( _rh => $s->_rh, %{ $res->json } )
  0 0       0  
159             : Finance::Robinhood::Error->new(
160             $res->is_server_error ? ( details => $res->message ) : $res->json );
161             }
162              
163             sub _test_account {
164 1   50 1   1957 t::Utility::stash('POSITION') // skip_all('No position object in stash');
165 0           isa_ok( t::Utility::stash('POSITION')->account, 'Finance::Robinhood::Equity::Account' );
166             }
167              
168             =head1 LEGAL
169              
170             This is a simple wrapper around the API used in the official apps. The author
171             provides no investment, legal, or tax advice and is not responsible for any
172             damages incurred while using this software. This software is not affiliated
173             with Robinhood Financial LLC in any way.
174              
175             For Robinhood's terms and disclosures, please see their website at
176             https://robinhood.com/legal/
177              
178             =head1 LICENSE
179              
180             Copyright (C) Sanko Robinson.
181              
182             This library is free software; you can redistribute it and/or modify it under
183             the terms found in the Artistic License 2. Other copyrights, terms, and
184             conditions may apply to data transmitted through this module. Please refer to
185             the L section.
186              
187             =head1 AUTHOR
188              
189             Sanko Robinson Esanko@cpan.orgE
190              
191             =cut
192              
193             1;