| 1 | package Finance::Robinhood::Equity::Account::MarginBalances; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | =for stopwords watchlist watchlists untradable urls | ||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | Finance::Robinhood::Equity::Account - Robinhood Account's Instant or Gold | ||||||||||||||||||
| 10 | Margin Account Balances | ||||||||||||||||||
| 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 | CORE::say 'How much can I borrow? ' . $account->margin_balances->margin_limit; | ||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | =cut | ||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | 1 | our $VERSION = '0.92_003'; | |||||||||||||||||
| 23 | 1 | ▶ | use Mojo::Base-base, -signatures; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 24 | 1 | ▶ | use Mojo::URL; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 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 $margin_balances = $acct->margin_balances; | |||||||||||||||||
| 30 | 0 | isa_ok($margin_balances, __PACKAGE__); | |||||||||||||||||
| 31 | 0 | t::Utility::stash('MARGIN', $margin_balances); # Store it for later | |||||||||||||||||
| 32 | } | ||||||||||||||||||
| 33 | 0 | ▶ | use overload '""' => sub ($s, @) { +$s->{created_at} }, fallback => 1; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
__ANON__: not called CC=1 SCAR=0.2
| |||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 1 | ▶ | sub _test_stringify { | ||||||||||||||||
|
Subroutine
_test_stringify: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 36 | 1 | ▶ | t::Utility::stash('MARGIN') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("MARGIN") // skip_all()
MC/DC0%0/2
t::Utility::stash("MARGIN") // skip_all()
t::Utility::stash("MARGIN")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MARGIN")B= skip_all()
| |||||||||||||||||||
| 37 | 0 | like(+t::Utility::stash('MARGIN'), | |||||||||||||||||
| 38 | qr'^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+Z$'); | ||||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | =head1 METHODS | ||||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | =cut | ||||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | 1 | has _rh => undef => weak => 1; | |||||||||||||||||
| 46 | |||||||||||||||||||
| 47 | =head2 C<cash( )> | ||||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | =head2 C<cash_available_for_withdrawal( )> | ||||||||||||||||||
| 50 | |||||||||||||||||||
| 51 | =head2 C<cash_held_for_dividends( )> | ||||||||||||||||||
| 52 | |||||||||||||||||||
| 53 | =head2 C<cash_held_for_nummus_restrictions( )> | ||||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | =head2 C<cash_held_for_options_collateral( )> | ||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | =head2 C<cash_held_for_orders( )> | ||||||||||||||||||
| 58 | |||||||||||||||||||
| 59 | =head2 C<cash_pending_from_options_events( )> | ||||||||||||||||||
| 60 | |||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | =head2 C<day_trade_buying_power( )> | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | =head2 C<day_trade_buying_power_held_for_orders( )> | ||||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | =head2 C<day_trade_ratio( )> | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | =head2 C<gold_equity_requirement( )> | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | =head2 C<margin_limit( )> | ||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | =head2 C<outstanding_interest( )> | ||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | =head2 C<overnight_buying_power( )> | ||||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | =head2 C<overnight_buying_power_held_for_orders( )> | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | =head2 C<overnight_ratio( )> | ||||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | =head2 C<sma( )> | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | =head2 C<start_of_day_dtbp( )> | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | =head2 C<start_of_day_overnight_buying_power( )> | ||||||||||||||||||
| 86 | |||||||||||||||||||
| 87 | =head2 C<unallocated_margin_cash( )> | ||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | =head2 C<uncleared_deposits( )> | ||||||||||||||||||
| 90 | |||||||||||||||||||
| 91 | =head2 C<uncleared_nummus_deposits( )> | ||||||||||||||||||
| 92 | |||||||||||||||||||
| 93 | =head2 C<unsettled_debit( )> | ||||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | =head2 C<unsettled_funds( )> | ||||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | |||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | =cut | ||||||||||||||||||
| 100 | |||||||||||||||||||
| 101 | 1 | has ['cash', | |||||||||||||||||
| 102 | 'cash_available_for_withdrawal', | ||||||||||||||||||
| 103 | 'cash_held_for_dividends', | ||||||||||||||||||
| 104 | 'cash_held_for_nummus_restrictions', | ||||||||||||||||||
| 105 | 'cash_held_for_options_collateral', | ||||||||||||||||||
| 106 | 'cash_held_for_orders', | ||||||||||||||||||
| 107 | 'cash_pending_from_options_events', | ||||||||||||||||||
| 108 | 'day_trade_buying_power', | ||||||||||||||||||
| 109 | 'day_trade_buying_power_held_for_orders', | ||||||||||||||||||
| 110 | 'day_trade_ratio', | ||||||||||||||||||
| 111 | 'gold_equity_requirement', | ||||||||||||||||||
| 112 | 'margin_limit', | ||||||||||||||||||
| 113 | 'outstanding_interest', | ||||||||||||||||||
| 114 | 'overnight_buying_power', | ||||||||||||||||||
| 115 | 'overnight_buying_power_held_for_orders', | ||||||||||||||||||
| 116 | 'overnight_ratio', | ||||||||||||||||||
| 117 | 'sma', | ||||||||||||||||||
| 118 | 'start_of_day_dtbp', | ||||||||||||||||||
| 119 | 'start_of_day_overnight_buying_power', | ||||||||||||||||||
| 120 | 'unallocated_margin_cash', | ||||||||||||||||||
| 121 | 'uncleared_deposits', | ||||||||||||||||||
| 122 | 'uncleared_nummus_deposits', | ||||||||||||||||||
| 123 | 'unsettled_debit', | ||||||||||||||||||
| 124 | 'unsettled_funds', | ||||||||||||||||||
| 125 | ]; | ||||||||||||||||||
| 126 | |||||||||||||||||||
| 127 | =head2 C<marked_pattern_day_trader_date( )> | ||||||||||||||||||
| 128 | |||||||||||||||||||
| 129 | Returns a Time::Moment object if applicable. | ||||||||||||||||||
| 130 | |||||||||||||||||||
| 131 | =cut | ||||||||||||||||||
| 132 | |||||||||||||||||||
| 133 | 0 | ▶ | sub marked_pattern_day_trader_date ($s) { | ||||||||||||||||
|
Subroutine
marked_pattern_day_trader_date: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||
| 134 | defined $s->{marked_pattern_day_trader_date} | ||||||||||||||||||
| 135 | ? Time::Moment->from_string($s->{marked_pattern_day_trader_date}) | ||||||||||||||||||
| 136 | 0 | ▶ | : (); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 137 | } | ||||||||||||||||||
| 138 | |||||||||||||||||||
| 139 | 1 | ▶ | sub _test_marked_pattern_day_trader_date { | ||||||||||||||||
|
Subroutine
_test_marked_pattern_day_trader_date: called CC=3 SCAR=18.4
| |||||||||||||||||||
| 140 | 1 | ▶ | t::Utility::stash('MARGIN') | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("MARGIN") // skip_all("No margin balances object in stash")
MC/DC0%0/2
t::Utility::stash("MARGIN") // skip_all("No margin balances object in stash")
t::Utility::stash("MARGIN")
skip_all("No margin balances object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("MARGIN")B= skip_all("No margin balances object in stash")
| |||||||||||||||||||
| 141 | // skip_all('No margin balances object in stash'); | ||||||||||||||||||
| 142 | 0 | ▶ | skip_all('Not marked as a PDT') | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 143 | if ! | ||||||||||||||||||
| 144 | defined t::Utility::stash('MARGIN')->marked_pattern_day_trader_date; | ||||||||||||||||||
| 145 | 0 | isa_ok(t::Utility::stash('MARGIN')->marked_pattern_day_trader_date, | |||||||||||||||||
| 146 | 'Time::Moment'); | ||||||||||||||||||
| 147 | } | ||||||||||||||||||
| 148 | |||||||||||||||||||
| 149 | =head2 C<created_at( )> | ||||||||||||||||||
| 150 | |||||||||||||||||||
| 151 | Returns a Time::Moment object. | ||||||||||||||||||
| 152 | |||||||||||||||||||
| 153 | =cut | ||||||||||||||||||
| 154 | |||||||||||||||||||
| 155 | 0 | ▶ | sub created_at ($s) { | ||||||||||||||||
|
Subroutine
created_at: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 156 | 0 | Time::Moment->from_string($s->{created_at}); | |||||||||||||||||
| 157 | } | ||||||||||||||||||
| 158 | |||||||||||||||||||
| 159 | 1 | ▶ | sub _test_created_at { | ||||||||||||||||
|
Subroutine
_test_created_at: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 160 | 1 | ▶ | t::Utility::stash('MARGIN') | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("MARGIN") // skip_all("No margin balances object in stash")
MC/DC0%0/2
t::Utility::stash("MARGIN") // skip_all("No margin balances object in stash")
t::Utility::stash("MARGIN")
skip_all("No margin balances object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("MARGIN")B= skip_all("No margin balances object in stash")
| |||||||||||||||||||
| 161 | // skip_all('No margin balances object in stash'); | ||||||||||||||||||
| 162 | 0 | isa_ok(t::Utility::stash('MARGIN')->created_at, 'Time::Moment'); | |||||||||||||||||
| 163 | } | ||||||||||||||||||
| 164 | |||||||||||||||||||
| 165 | =head2 C<updated_at( )> | ||||||||||||||||||
| 166 | |||||||||||||||||||
| 167 | Returns a Time::Moment object if applicable. | ||||||||||||||||||
| 168 | |||||||||||||||||||
| 169 | =cut | ||||||||||||||||||
| 170 | |||||||||||||||||||
| 171 | 0 | ▶ | sub updated_at ($s) { | ||||||||||||||||
|
Subroutine
updated_at: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 172 | 0 | Time::Moment->from_string($s->{updated_at}); | |||||||||||||||||
| 173 | } | ||||||||||||||||||
| 174 | |||||||||||||||||||
| 175 | 1 | ▶ | sub _test_updated_at { | ||||||||||||||||
|
Subroutine
_test_updated_at: called CC=2 SCAR=9.2
| |||||||||||||||||||
| 176 | 1 | ▶ | t::Utility::stash('MARGIN') | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("MARGIN") // skip_all("No margin balances object in stash")
MC/DC0%0/2
t::Utility::stash("MARGIN") // skip_all("No margin balances object in stash")
t::Utility::stash("MARGIN")
skip_all("No margin balances object in stash")
Truth table33%1/3
A // B
A= t::Utility::stash("MARGIN")B= skip_all("No margin balances object in stash")
| |||||||||||||||||||
| 177 | // skip_all('No margin balances object in stash'); | ||||||||||||||||||
| 178 | 0 | isa_ok(t::Utility::stash('MARGIN')->updated_at, 'Time::Moment'); | |||||||||||||||||
| 179 | } | ||||||||||||||||||
| 180 | |||||||||||||||||||
| 181 | =head1 LEGAL | ||||||||||||||||||
| 182 | |||||||||||||||||||
| 183 | This is a simple wrapper around the API used in the official apps. The author | ||||||||||||||||||
| 184 | provides no investment, legal, or tax advice and is not responsible for any | ||||||||||||||||||
| 185 | damages incurred while using this software. This software is not affiliated | ||||||||||||||||||
| 186 | with Robinhood Financial LLC in any way. | ||||||||||||||||||
| 187 | |||||||||||||||||||
| 188 | For Robinhood's terms and disclosures, please see their website at | ||||||||||||||||||
| 189 | https://robinhood.com/legal/ | ||||||||||||||||||
| 190 | |||||||||||||||||||
| 191 | =head1 LICENSE | ||||||||||||||||||
| 192 | |||||||||||||||||||
| 193 | Copyright (C) Sanko Robinson. | ||||||||||||||||||
| 194 | |||||||||||||||||||
| 195 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||
| 196 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||||||||||||||||||
| 197 | conditions may apply to data transmitted through this module. Please refer to | ||||||||||||||||||
| 198 | the L<LEGAL> section. | ||||||||||||||||||
| 199 | |||||||||||||||||||
| 200 | =head1 AUTHOR | ||||||||||||||||||
| 201 | |||||||||||||||||||
| 202 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||
| 203 | |||||||||||||||||||
| 204 | =cut | ||||||||||||||||||
| 205 | |||||||||||||||||||
| 206 | 1 | 1; | |||||||||||||||||