File Coverage

lib/Finance/Robinhood/Equity/Account/Portfolio.pm
Criterion Covered Total %
statement 16 37 43.2
branch 0 4 0.0
condition 3 6 50.0
subroutine 8 11 72.7
pod 2 2 100.0
total 29 60 48.3


line stmt bran cond sub pod time code
1             package Finance::Robinhood::Equity::Account::Portfolio;
2              
3             =encoding utf-8
4              
5             =for stopwords watchlist watchlists untradable urls
6              
7             =head1 NAME
8              
9             Finance::Robinhood::Equity::Account::Portfolio - Represents a Single Portfolio
10             attached to a Robinhood Account
11              
12             =head1 SYNOPSIS
13              
14             use Finance::Robinhood;
15             my $rh = Finance::Robinhood->new->login('user', 'pass');
16             my $portfolios = $rh->equity_portfolios->current();
17              
18             for my $portfolio ($portfolios->all) {
19             CORE::say $portfolio->equity;
20             }
21              
22             =cut
23              
24             our $VERSION = '0.92_002';
25              
26             sub _test__init {
27 1     1   12995 my $rh = t::Utility::rh_instance(1);
28 0         0 my $acct = $rh->equity_accounts->current;
29 0         0 my $portfolio = $acct->portfolio;
30 0         0 isa_ok( $portfolio, __PACKAGE__ );
31 0         0 t::Utility::stash( 'PORTFOLIO', $portfolio ); # Store it for later
32             }
33 1     1   7 use Mojo::Base-base, -signatures;
  1         59  
  1         12  
34 1     1   217 use Mojo::URL;
  1         3  
  1         6  
35 1     1   77 use overload '""' => sub ( $s, @ ) { $s->{url} }, fallback => 1;
  1     0   2  
  1         14  
  0         0  
  0         0  
  0         0  
  0         0  
36 1     1   85 use Finance::Robinhood::Equity::Instrument;
  1         2  
  1         6  
37              
38             sub _test_stringify {
39 1   50 1   2143 t::Utility::stash('PORTFOLIO') // skip_all();
40 0         0 like( +t::Utility::stash('PORTFOLIO'), qr'https://api.robinhood.com/portfolios/.+/' );
41             }
42              
43             =head1 METHODS
44              
45             =cut
46              
47             has _rh => undef => weak => 1;
48              
49             =head2 C
50              
51             =head2 C
52              
53             =head2 C
54              
55             =head2 C
56              
57             =head2 C
58              
59             =head2 C
60              
61             =head2 C
62              
63             =head2 C
64              
65             =head2 C
66              
67             =head2 C
68              
69             =head2 C
70              
71             =head2 C
72              
73             =head2 C
74              
75             =head2 C
76              
77             =head2 C
78              
79              
80             =cut
81              
82             has [
83             'adjusted_equity_previous_close', 'equity',
84             'equity_previous_close', 'excess_maintenance',
85             'excess_maintenance_with_uncleared_deposits', 'excess_margin',
86             'excess_margin_with_uncleared_deposits', 'extended_hours_equity',
87             'extended_hours_market_value', 'last_core_equity',
88             'last_core_market_value', 'market_value',
89             'unwithdrawable_deposits', 'unwithdrawable_grants',
90             'withdrawable_amount'
91             ];
92              
93             =head2 C
94              
95             Returns a Time::Moment object.
96              
97             =cut
98              
99 0     0 1 0 sub start_date ($s) {
  0         0  
  0         0  
100 0         0 Time::Moment->from_string( $s->{start_date} . 'T00:00:00Z' );
101             }
102              
103             sub _test_start_date {
104 1   50 1   2159 t::Utility::stash('PORTFOLIO') // skip_all('No portfolio object in stash');
105 0         0 isa_ok( t::Utility::stash('PORTFOLIO')->start_date, 'Time::Moment' );
106             }
107              
108             =head2 C
109              
110             Returns the related Finance::Robinhood::Equity::Account object.
111              
112             =cut
113              
114 0     0 1 0 sub account ($s) {
  0         0  
  0         0  
115 0         0 my $res = $s->_rh->_get( $s->{account} );
116             return $res->is_success
117 0 0       0 ? Finance::Robinhood::Equity::Account->new( _rh => $s->_rh, %{ $res->json } )
  0 0       0  
118             : Finance::Robinhood::Error->new(
119             $res->is_server_error ? ( details => $res->message ) : $res->json );
120             }
121              
122             sub _test_account {
123 1   50 1   2154 t::Utility::stash('POSITION') // skip_all('No position object in stash');
124 0           isa_ok( t::Utility::stash('POSITION')->account, 'Finance::Robinhood::Equity::Account' );
125             }
126              
127             =head1 LEGAL
128              
129             This is a simple wrapper around the API used in the official apps. The author
130             provides no investment, legal, or tax advice and is not responsible for any
131             damages incurred while using this software. This software is not affiliated
132             with Robinhood Financial LLC in any way.
133              
134             For Robinhood's terms and disclosures, please see their website at
135             https://robinhood.com/legal/
136              
137             =head1 LICENSE
138              
139             Copyright (C) Sanko Robinson.
140              
141             This library is free software; you can redistribute it and/or modify it under
142             the terms found in the Artistic License 2. Other copyrights, terms, and
143             conditions may apply to data transmitted through this module. Please refer to
144             the L section.
145              
146             =head1 AUTHOR
147              
148             Sanko Robinson Esanko@cpan.orgE
149              
150             =cut
151              
152             1;