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_003';
25 1     1   6 use Mojo::Base-base, -signatures;
  1         2  
  1         6  
26 1     1   160 use Mojo::URL;
  1         2  
  1         20  
27 1     1   28 use Finance::Robinhood::Equity::Instrument;
  1         2  
  1         4  
28              
29             sub _test__init {
30 1     1   14125 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   136 use overload '""' => sub ($s, @) { $s->{url} }, fallback => 1;
  1     0   3  
  1         6  
  0         0  
  0         0  
  0         0  
  0         0  
37              
38             sub _test_stringify {
39 1   50 1   1941 t::Utility::stash('POSITION') // skip_all();
40 0         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             has _rh => undef => weak => 1;
50              
51             =head2 C
52              
53              
54             =head2 C
55              
56              
57             =head2 C
58              
59              
60             =head2 C
61              
62              
63             =head2 C
64              
65              
66             =head2 C
67              
68              
69             =head2 C
70              
71             Shares held for collateral for a sold call, etc.
72              
73             =head2 C
74              
75              
76             =head2 C
77              
78             Shares that are marked to be sold in outstanding orders.
79              
80             =head2 C
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
86              
87              
88             =cut
89              
90             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
99              
100             Returns a Time::Moment object.
101              
102             =cut
103              
104 0     0 1 0 sub created_at ($s) {
  0         0  
  0         0  
105 0         0 Time::Moment->from_string($s->{created_at});
106             }
107              
108             sub _test_created_at {
109 1   50 1   2008 t::Utility::stash('POSITION') // skip_all('No position object in stash');
110 0         0 isa_ok(t::Utility::stash('POSITION')->created_at, 'Time::Moment');
111             }
112              
113             =head2 C
114              
115             Returns a Time::Moment object.
116              
117             =cut
118              
119 0     0 1 0 sub updated_at ($s) {
  0         0  
  0         0  
120 0         0 Time::Moment->from_string($s->{updated_at});
121             }
122              
123             sub _test_updated_at {
124 1   50 1   1862 t::Utility::stash('POSITION') // skip_all('No position object in stash');
125 0         0 isa_ok(t::Utility::stash('POSITION')->updated_at, 'Time::Moment');
126             }
127              
128             =head2 C
129              
130             Returns the related Finance::Robinhood::Equity::Instrument object.
131              
132             =cut
133              
134 0     0 1 0 sub instrument ($s) {
  0         0  
  0         0  
135 0         0 my $res = $s->_rh->_get($s->{instrument});
136             return $res->is_success
137             ? Finance::Robinhood::Equity::Instrument->new(_rh => $s->_rh,
138 0 0       0 %{$res->json})
  0 0       0  
139             : Finance::Robinhood::Error->new(
140             $res->is_server_error ? (details => $res->message) : $res->json);
141             }
142              
143             sub _test_instrument {
144 1   50 1   1888 t::Utility::stash('POSITION') // skip_all('No position object in stash');
145 0         0 isa_ok(t::Utility::stash('POSITION')->instrument,
146             '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             ? Finance::Robinhood::Equity::Account->new(_rh => $s->_rh,
159 0 0       0 %{$res->json})
  0 0       0  
160             : Finance::Robinhood::Error->new(
161             $res->is_server_error ? (details => $res->message) : $res->json);
162             }
163              
164             sub _test_account {
165 1   50 1   2059 t::Utility::stash('POSITION') // skip_all('No position object in stash');
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 section.
188              
189             =head1 AUTHOR
190              
191             Sanko Robinson Esanko@cpan.orgE
192              
193             =cut
194              
195             1;