File Coverage

lib/Finance/Robinhood/Equity/Account/MarginBalances.pm
Criterion Covered Total %
statement 14 39 35.9
branch 0 4 0.0
condition 4 8 50.0
subroutine 8 12 66.6
pod 3 3 100.0
total 29 66 43.9


line stmt bran cond sub pod time code
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             our $VERSION = '0.92_002';
23 1     1   7 use Mojo::Base-base, -signatures;
  1         2  
  1         12  
24 1     1   180 use Mojo::URL;
  1         18  
  1         9  
25              
26             sub _test__init {
27 1     1   16859 my $rh = t::Utility::rh_instance(1);
28 0         0 my $acct = $rh->equity_accounts->current;
29 0         0 my $margin_balances = $acct->margin_balances;
30 0         0 isa_ok( $margin_balances, __PACKAGE__ );
31 0         0 t::Utility::stash( 'MARGIN', $margin_balances ); # Store it for later
32             }
33 1     1   165 use overload '""' => sub ( $s, @ ) { +$s->{created_at} }, fallback => 1;
  1     0   2  
  1         7  
  0         0  
  0         0  
  0         0  
  0         0  
34              
35             sub _test_stringify {
36 1   50 1   1902 t::Utility::stash('MARGIN') // skip_all();
37 0         0 like( +t::Utility::stash('MARGIN'), qr'^\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d+Z$' );
38             }
39              
40             =head1 METHODS
41              
42             =cut
43              
44             has _rh => undef => weak => 1;
45              
46             =head2 C
47              
48             =head2 C
49              
50             =head2 C
51              
52             =head2 C
53              
54             =head2 C
55              
56             =head2 C
57              
58             =head2 C
59              
60            
61             =head2 C
62              
63             =head2 C
64              
65             =head2 C
66              
67             =head2 C
68              
69             =head2 C
70              
71            
72             =head2 C
73              
74             =head2 C
75              
76             =head2 C
77              
78             =head2 C
79              
80             =head2 C
81              
82             =head2 C
83              
84             =head2 C
85              
86             =head2 C
87              
88             =head2 C
89              
90             =head2 C
91              
92             =head2 C
93              
94             =head2 C
95              
96              
97              
98             =cut
99              
100             has [
101             'cash', 'cash_available_for_withdrawal',
102             'cash_held_for_dividends', 'cash_held_for_nummus_restrictions',
103             'cash_held_for_options_collateral', 'cash_held_for_orders',
104             'cash_pending_from_options_events', 'day_trade_buying_power',
105             'day_trade_buying_power_held_for_orders', 'day_trade_ratio',
106             'gold_equity_requirement', 'margin_limit',
107             'outstanding_interest', 'overnight_buying_power',
108             'overnight_buying_power_held_for_orders', 'overnight_ratio',
109             'sma', 'start_of_day_dtbp',
110             'start_of_day_overnight_buying_power', 'unallocated_margin_cash',
111             'uncleared_deposits', 'uncleared_nummus_deposits',
112             'unsettled_debit', 'unsettled_funds',
113             ];
114              
115             =head2 C
116              
117             Returns a Time::Moment object if applicable.
118              
119             =cut
120              
121 0     0 1 0 sub marked_pattern_day_trader_date ($s) {
  0         0  
  0         0  
122             defined $s->{marked_pattern_day_trader_date}
123             ? Time::Moment->from_string( $s->{marked_pattern_day_trader_date} )
124 0 0       0 : ();
125             }
126              
127             sub _test_marked_pattern_day_trader_date {
128 1   50 1   1949 t::Utility::stash('MARGIN') // skip_all('No margin balances object in stash');
129 0 0       0 skip_all('Not marked as a PDT')
130             if !defined t::Utility::stash('MARGIN')->marked_pattern_day_trader_date;
131 0         0 isa_ok( t::Utility::stash('MARGIN')->marked_pattern_day_trader_date, 'Time::Moment' );
132             }
133              
134             =head2 C
135              
136             Returns a Time::Moment object.
137              
138             =cut
139              
140 0     0 1 0 sub created_at ($s) {
  0         0  
  0         0  
141 0         0 Time::Moment->from_string( $s->{created_at} );
142             }
143              
144             sub _test_created_at {
145 1   50 1   2287 t::Utility::stash('MARGIN') // skip_all('No margin balances object in stash');
146 0         0 isa_ok( t::Utility::stash('MARGIN')->created_at, 'Time::Moment' );
147             }
148              
149             =head2 C
150              
151             Returns a Time::Moment object if applicable.
152              
153             =cut
154              
155 0     0 1 0 sub updated_at ($s) {
  0         0  
  0         0  
156 0         0 Time::Moment->from_string( $s->{updated_at} );
157             }
158              
159             sub _test_updated_at {
160 1   50 1   2023 t::Utility::stash('MARGIN') // skip_all('No margin balances object in stash');
161 0           isa_ok( t::Utility::stash('MARGIN')->updated_at, 'Time::Moment' );
162             }
163              
164             =head1 LEGAL
165              
166             This is a simple wrapper around the API used in the official apps. The author
167             provides no investment, legal, or tax advice and is not responsible for any
168             damages incurred while using this software. This software is not affiliated
169             with Robinhood Financial LLC in any way.
170              
171             For Robinhood's terms and disclosures, please see their website at
172             https://robinhood.com/legal/
173              
174             =head1 LICENSE
175              
176             Copyright (C) Sanko Robinson.
177              
178             This library is free software; you can redistribute it and/or modify it under
179             the terms found in the Artistic License 2. Other copyrights, terms, and
180             conditions may apply to data transmitted through this module. Please refer to
181             the L section.
182              
183             =head1 AUTHOR
184              
185             Sanko Robinson Esanko@cpan.orgE
186              
187             =cut
188              
189             1;