« lib/Finance/Robinhood/Equity/Quote.pm
↑ Summary
lib/Finance/Robinhood/Equity/Watchlist/Element.pm »
| 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 | 1 | our $VERSION = '0.92_003'; | |||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | 1 | ▶ | sub _test__init { | ||||||||||||||||
|
Subroutine
_test__init: called CC=1 SCAR=4.1
| |||||||||||||||||||
| 27 | 1 | my $rh = t::Utility::rh_instance(1); | |||||||||||||||||
| 28 | 0 | my $acct = $rh->equity_accounts->current; | |||||||||||||||||
| 29 | 0 | my $portfolio = $acct->portfolio; | |||||||||||||||||
| 30 | 0 | isa_ok($portfolio, __PACKAGE__); | |||||||||||||||||
| 31 | 0 | t::Utility::stash('PORTFOLIO', $portfolio); # Store it for later | |||||||||||||||||
| 32 | } | ||||||||||||||||||
| 33 | 1 | ▶ | use Mojo::Base-base, -signatures; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 34 | 1 | ▶ | use Mojo::URL; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 35 | 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
| |||||||||||||||||||
| 36 | 1 | ▶ | use Finance::Robinhood::Equity::Instrument; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | 1 | ▶ | sub _test_stringify { | ||||||||||||||||
|
Subroutine
_test_stringify: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 39 | 1 | ▶ | t::Utility::stash('PORTFOLIO') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("PORTFOLIO") // skip_all()
MC/DC0%0/2
t::Utility::stash("PORTFOLIO") // skip_all()
t::Utility::stash("PORTFOLIO")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("PORTFOLIO")B= skip_all()
| |||||||||||||||||||
| 40 | 0 | like(+t::Utility::stash('PORTFOLIO'), | |||||||||||||||||
| 41 | qr'https://api.robinhood.com/portfolios/.+/'); | ||||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | |||||||||||||||||||
| 44 | =head1 METHODS | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | =cut | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | 1 | has _rh => undef => weak => 1; | |||||||||||||||||
| 49 | |||||||||||||||||||
| 50 | =head2 C<adjusted_equity_previous_close( )> | ||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | =head2 C<equity( )> | ||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | =head2 C<equity_previous_close( )> | ||||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | =head2 C<excess_maintenance( )> | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | =head2 C<excess_maintenance_with_uncleared_deposits( )> | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | =head2 C<excess_margin( )> | ||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | =head2 C<excess_margin_with_uncleared_deposits( )> | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | =head2 C<extended_hours_equity( )> | ||||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | =head2 C<extended_hours_market_value( )> | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | =head2 C<last_core_equity( )> | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | =head2 C<last_core_market_value( )> | ||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | =head2 C<market_value( )> | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | =head2 C<unwithdrawable_deposits( )> | ||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | =head2 C<unwithdrawable_grants( )> | ||||||||||||||||||
| 77 | |||||||||||||||||||
| 78 | =head2 C<withdrawable_amount( )> | ||||||||||||||||||
| 79 | |||||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | =cut | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | 1 | has ['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<start_date( )> | ||||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | Returns a Time::Moment object. | ||||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | =cut | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | 0 | ▶ | sub start_date ($s) { | ||||||||||||||||
|
Subroutine
start_date: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 100 | 0 | Time::Moment->from_string($s->{start_date} . 'T00:00:00Z'); | |||||||||||||||||
| 101 | } | ||||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | 1 | ▶ | sub _test_start_date { | ||||||||||||||||
|
Subroutine
_test_start_date: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 104 | 1 | ▶ | t::Utility::stash('PORTFOLIO') | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("PORTFOLIO") // skip_all("No portfolio object in stash")
MC/DC0%0/2
t::Utility::stash("PORTFOLIO") // skip_all("No portfolio object in stash")
t::Utility::stash("PORTFOLIO")
skip_all("No portfolio object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("PORTFOLIO")B= skip_all("No portfolio object in stash")
| |||||||||||||||||||
| 105 | // skip_all('No portfolio object in stash'); | ||||||||||||||||||
| 106 | 0 | isa_ok(t::Utility::stash('PORTFOLIO')->start_date, 'Time::Moment'); | |||||||||||||||||
| 107 | } | ||||||||||||||||||
| 108 | |||||||||||||||||||
| 109 | =head2 C<account( )> | ||||||||||||||||||
| 110 | |||||||||||||||||||
| 111 | Returns the related Finance::Robinhood::Equity::Account object. | ||||||||||||||||||
| 112 | |||||||||||||||||||
| 113 | =cut | ||||||||||||||||||
| 114 | |||||||||||||||||||
| 115 | 0 | ▶ | sub account ($s) { | ||||||||||||||||
|
Subroutine
account: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||
| 116 | 0 | my $res = $s->_rh->_get($s->{account}); | |||||||||||||||||
| 117 | return $res->is_success | ||||||||||||||||||
| 118 | ? Finance::Robinhood::Equity::Account->new(_rh => $s->_rh, | ||||||||||||||||||
| 119 | 0 | ▶ | %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 120 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 121 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 122 | } | ||||||||||||||||||
| 123 | |||||||||||||||||||
| 124 | 1 | ▶ | sub _test_account { | ||||||||||||||||
|
Subroutine
_test_account: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 125 | 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")
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")
| |||||||||||||||||||
| 126 | 0 | isa_ok(t::Utility::stash('POSITION')->account, | |||||||||||||||||
| 127 | 'Finance::Robinhood::Equity::Account'); | ||||||||||||||||||
| 128 | } | ||||||||||||||||||
| 129 | |||||||||||||||||||
| 130 | =head1 LEGAL | ||||||||||||||||||
| 131 | |||||||||||||||||||
| 132 | This is a simple wrapper around the API used in the official apps. The author | ||||||||||||||||||
| 133 | provides no investment, legal, or tax advice and is not responsible for any | ||||||||||||||||||
| 134 | damages incurred while using this software. This software is not affiliated | ||||||||||||||||||
| 135 | with Robinhood Financial LLC in any way. | ||||||||||||||||||
| 136 | |||||||||||||||||||
| 137 | For Robinhood's terms and disclosures, please see their website at | ||||||||||||||||||
| 138 | https://robinhood.com/legal/ | ||||||||||||||||||
| 139 | |||||||||||||||||||
| 140 | =head1 LICENSE | ||||||||||||||||||
| 141 | |||||||||||||||||||
| 142 | Copyright (C) Sanko Robinson. | ||||||||||||||||||
| 143 | |||||||||||||||||||
| 144 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||
| 145 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||||||||||||||||||
| 146 | conditions may apply to data transmitted through this module. Please refer to | ||||||||||||||||||
| 147 | the L<LEGAL> section. | ||||||||||||||||||
| 148 | |||||||||||||||||||
| 149 | =head1 AUTHOR | ||||||||||||||||||
| 150 | |||||||||||||||||||
| 151 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||
| 152 | |||||||||||||||||||
| 153 | =cut | ||||||||||||||||||
| 154 | |||||||||||||||||||
| 155 | 1 | 1; | |||||||||||||||||