blib/lib/Finance/Robinhood.pm

filter: Statementstmt 46.0% 64 / 139 Branchbran 15.2% 7 / 46 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 48.7% 19 / 39 Podpod 100% 21 / 21 totaltotal 42.5% 111 / 261 CC 29 SCAR 24.2
CC
29
Cov
36%
place_options_order
56.0
login
20.0
options_orders
20.0
CRAP 11.3
« blib/lib/Finance/Robinhood/Utils/Client.pm ↑ Summary blib/lib/Finance/Robinhood/Utils/Paginated.pm »
1 package Finance::Robinhood;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Finance::Robinhood - Trade Stocks, ETFs, Options, and Cryptocurrency without Commission
8  
9 =head1 SYNOPSIS
10  
11 use Finance::Robinhood;
12  
13 my $rh = Finance::Robinhood->new();
14  
15 $rh->login($user, $password); # Store it for later
16  
17 =cut
18  
19 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 our $VERSION = '0.9.0_001';
23 3 ▶use Finance::Robinhood::Account;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use Finance::Robinhood::Equity::Instrument;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use Finance::Robinhood::Equity::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use Finance::Robinhood::Options::Chain;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 ▶use Finance::Robinhood::Options::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use Finance::Robinhood::Options::Instrument;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use Finance::Robinhood::Options::Order;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 ▶use Finance::Robinhood::Options::Position;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 ▶use Finance::Robinhood::Utils 'v4_uuid' => { -as => 'uuid' };
Subroutine BEGIN: called CC=1 SCAR=0.0
32 3 ▶use Finance::Robinhood::Utils::Client;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 3 ▶use Finance::Robinhood::Utils::Credentials;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 ▶use Finance::Robinhood::Utils::Paginated;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use Finance::Robinhood::ACH;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 #
37 3 our %Endpoints = (
38 'api-token-auth' => 'https://api.robinhood.com/api-token-auth/',
39 'api-token-logout' => 'https://api.robinhood.com/api-token-logout/',
40 'accounts' => 'https://api.robinhood.com/accounts/',
41 'ach/deposit_schedules' => 'https://api.robinhood.com/ach/deposit_schedules/',
42 'ach/relationships' => 'https://api.robinhood.com/ach/relationships/',
43 'instruments' => 'https://api.robinhood.com/instruments/',
44 'instruments/{id}' => 'https://api.robinhood.com/instruments/%s/',
45 'password_reset/request' => 'https://api.robinhood.com/password_reset/request/',
46 'password_reset' => 'https://api.robinhood.com/password_reset/',
47 'marketdata/quotes' => 'https://api.robinhood.com/marketdata/quotes/',
48 'marketdata/quotes/{symbol}' => 'https://api.robinhood.com/marketdata/quotes/%s/',
49 'oauth2/migrate_token' => 'https://api.robinhood.com/oauth2/migrate_token/',
50 'options/chains' => 'https://api.robinhood.com/options/chains/',
51 'options/instruments' => 'https://api.robinhood.com/options/instruments/',
52 'options/orders' => 'https://api.robinhood.com/options/orders/',
53 'options/orders/{id}' => 'https://api.robinhood.com/options/orders/%s/',
54 'options/orders/day_trade_checks' =>
55 'https://api.robinhood.com/options/orders/day_trade_checks/',
56 'marketdata/options' => 'https://api.robinhood.com/marketdata/options/',
57 'marketdata/options/{id}' => 'https://api.robinhood.com/marketdata/options/%s/',
58 'options/orders/{id}/cancel' => 'https://api.robinhood.com/api/options/orders/%s/cancel/',
59 'marketdata/options/historicals/{id}/' =>
60 'https://api.robinhood.com/marketdata/options/historicals/%s/',
61 'options/suitability' => 'https://api.robinhood.com/options/suitability/',
62 'options/events' => 'https://api.robinhood.com/options/events/',
63 'options/positions' => 'https://api.robinhood.com/options/positions/',
64 'options/positions/{id}' => 'https://api.robinhood.com/options/positions/%s/',
65 );
66  
67 =head1 METHODS
68  
69 Finance::Robinhood wraps a several APIs. There are parts of this package that
70 are object oriented (because they require persistant login information) and
71 others which may also be used functionally (because they do not require login
72 information). I've attempted to organize everything according to how and when
73 they are used... Let's start at the very beginning: let's log in!
74  
75 =head1 Logging In
76  
77 Robinhood requires an authorization token for most API calls. To get this
78 token, you must either pass it as an argument to C<new( ... )> or log in with
79 your username and password.
80  
81 =head2 C<new( )>
82  
83 # Requires ->login(...) call :(
84 my $rh = Finance::Robinhood->new( );
85  
86 A new Finance::Robinhood object is created without credentials. Before you can
87 buy or sell or do almost anything else, you must L<log in manually|/"login( ... )">.
88  
89 =cut
90  
91 #
92 has 'credentials' => (
93 is => 'rw',
94 0 ▶ builder => sub { Finance::Robinhood::Utils::Credentials->instance },
Subroutine __ANON__: not called CC=1 SCAR=6.9
95 3 handles => [qw[token]],
96 lazy => 1
97 );
98 has 'client' => (
99 is => 'ro',
100 1 ▶ builder => sub { Finance::Robinhood::Utils::Client->instance },
Subroutine __ANON__: called CC=1 SCAR=0.0
101 3 handles => [qw[get post account]],
102 lazy => 1
103 );
104  
105 =head2 C<login( ... )>
106  
107 my $token = $rh->login($user, $password);
108 # Save the token somewhere
109  
110 Logging in allows you to buy and sell securities with your Robinhood account.
111  
112 =cut
113  
114 #
115 sub login {
116 0 ▶ my ( $s, $user, $password, $mfa_cb ) = @_;
Subroutine login: not called CC=4 SCAR=30.0
Pod documented
117 my ( $status, $auth )
118 0 = $s->post( $Endpoints{'api-token-auth'}, { username => $user, password => $password } );
119 0 ▶ if ( $auth->{mfa_required} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth->{"mfa_required"}) 0 0 0
120 0 ▶ return !warn 'Login requires a MFA callback.' if !$mfa_cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $mfa_cb 0 0 0
121 0 ( $status, $auth ) = $s->post( $Endpoints{'api-token-auth'},
122 { username => $user, password => $password, mfa_code => $mfa_cb->($auth) } );
123 }
124 0 ▶ $status == 200 ? !!$s->credentials->old_skool( $auth->{token} ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$status == 200 ? : 0 0 0
125 }
126  
127 =head2 C<logout( )>
128  
129 my $token = $rh->login($user, $password);
130 # ...do some stuff... buy... sell... idk... stuff... and then...
131 $rh->logout( ); # Goodbye!
132  
133 This method logs you out of Robinhood by forcing the old skool token to expire.
134  
135 I<Note>: This will log you out I<everywhere> that uses the old skool token because
136 Robinhood generated a single authorization token per account at a time! All logged in
137 clients will be logged out. This is good in rare case your device or the token itself is
138 stolen.
139  
140 =cut
141  
142 sub logout {
143 0 ▶ my ($s) = @_;
Subroutine logout: not called CC=2 SCAR=17.9
Pod documented
144 0 my ( $status, $auth ) = $s->post( $Endpoints{'api-token-logout'} );
145 0 ▶ $status == 200 ? !!$s->credentials->clear_old_skool() : 0;
Branch: 1 branch
BranchTrueFalseTotal
$status == 200 ? : 0 0 0
146 }
147  
148 =head2 C<recover_password( ... )>
149  
150 my $token = $rh->recover_password('rh@example.com', sub {...});
151  
152 Start the password recovery process. If everything goes as planned, this returns a true value.
153  
154 The token callback should expect a string to display in your
155 application and return a list with the following data:
156  
157 =over
158  
159 =item * C<username> - Username attached to the email address
160  
161 =item * C<password> - New password
162  
163 =item * C<token> - Reset token provided by Robinhood in the reset link
164  
165 =back
166  
167 =cut
168  
169 #
170 sub recover_password {
171 0 ▶ my ( $s, $email, $reset_cb ) = @_;
Subroutine recover_password: not called CC=3 SCAR=24.8
Pod documented
172 0 my ( $status, $resp ) = $s->post( $Endpoints{'password_reset/request'}, { email => $email } );
173 0 ▶ if ( $resp->{link} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"link"}) 0 0 0
174 0 ▶ return !warn 'Password reset requires a token callback.' if !$reset_cb;
Branch: 1 branch
BranchTrueFalseTotal
unless $reset_cb 0 0 0
175 0 my ( $user, $pass, $token ) = $reset_cb->( $resp->{detail} );
176 0 ( $status, $resp ) = $s->post( $Endpoints{'password_reset'},
177 { username => $user, password => $pass, token => $token } );
178 }
179 0 $status == 200;
180 }
181  
182 =head2 C<migrate_token( ... )>
183  
184 my $ok = $rh->migrate_token();
185  
186 Convert your old skool token to an OAuth2 token.
187  
188 =cut
189  
190 sub migrate_token {
191 0 ▶ my ($s) = @_;
Subroutine migrate_token: not called CC=1 SCAR=6.9
Pod documented
192 0 Finance::Robinhood::Utils::Credentials->instance->migrate();
193 }
194  
195 =head2 C<equity_quote( ... )>
196  
197 my $msft_quote = $rh->quote('MSFT');
198  
199 Gather quote data as a L<Finance::Robinhood::Equity::Quote> object.
200  
201 my $msft_quote = $rh->quote('MSFT', bounds => 'extended');
202  
203 An argument called C<bounds> is also supported when you want a certain range of quote data.
204 This value must be C<extended>, C<regular>, or C<trading> which is the default.
205  
206 =cut
207  
208 sub equity_quote {
209 2 ▶ my ( $s, $symbol, %args ) = @_;
Subroutine equity_quote: called CC=2 SCAR=6.9
Pod documented
210 my ( $status, $data )
211 2 = $s->get( sprintf( $Endpoints{'marketdata/quotes/{symbol}'}, $symbol ), \%args );
212 2 ▶ $status == 200 ? Finance::Robinhood::Equity::Quote->new($data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
$status == 200 ? : 1 1 2
213 }
214  
215 =head2 C<equity_quotes( ... )>
216  
217 my $inst = $rh->equity_quotes( symbols => ['MSFT', 'X'] );
218 my $all = $inst->all;
219  
220 Gather info about multiple equities by symbol. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
221  
222 my $inst = $rh->instruments( instruments => ['50810c35-d215-4866-9758-0ada4ac79ffa', 'b060f19f-0d24-4bf2-bf8c-d57ba33993e5'] );
223 my $all = $inst->all;
224  
225 Gather info about a several instruments by their ids; data is returned as a C<Finance::Robinhood::Utils::Paginated> object.
226  
227 Request either by symbol or by instrument id! Other arguments are also supported:
228  
229 =over
230  
231 =item C<bounds> - which must be C<extended>, C<regular>, or C<trading> which is the default
232  
233 =back
234  
235 =cut
236  
237 sub equity_quotes {
238 4 ▶ my ( $s, %args ) = @_;
Subroutine equity_quotes: called CC=5 SCAR=16.5
Pod documented
239 map {
240 $_
241 = ref $_ ? $_->url :
242 $_ =~ $Endpoints{'instruments'} ? $_ :
243 5 ▶ sprintf $Endpoints{'instruments/{id}'}, $_
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 0 5 5
$_ =~ /$Finance::Robinhood::Endpoints{'instruments'}/ ? : 0 5 5
244 4 ▶ } @{ $args{'instruments'} } if $args{'instruments'};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"instruments"} 2 2 4
245 Finance::Robinhood::Utils::Paginated->new(
246 class => 'Finance::Robinhood::Equity::Quote',
247 next => join '?',
248 $Endpoints{'marketdata/quotes'}, (
249 join '&',
250 map {
251 4 $_ . '=' .
252 4 ▶ ( ref $args{$_} eq 'ARRAY' ? ( join ',', @{ $args{$_} } ) : $args{$_} )
Branch: 1 branch
BranchTrueFalseTotal
ref $args{$_} eq 'ARRAY' ? : 4 0 4
253 } keys %args
254 )
255 );
256 }
257  
258 =head2 C<equity_instruments( ... )>
259  
260 my $ok = $rh->equity_instruments();
261 my $all = $ok->all;
262  
263 Gather info about listed stocks and etfs. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
264  
265 my $inst = $rh->equity_instruments( symbol => 'MSFT' );
266 my $all = $inst->all;
267  
268 Gather info about a single instrument returned as a C<Finance::Robinhood::Utils::Paginated> object.
269  
270 my $minstsft = $rh->equity_instruments( query => 'oil' );
271 my $all = $inst->all;
272  
273 Gather info about a single instrument returned as a C<Finance::Robinhood::Utils::Paginated> object.
274  
275 my $inst = $rh->equity_instruments( ids => ['50810c35-d215-4866-9758-0ada4ac79ffa', 'b060f19f-0d24-4bf2-bf8c-d57ba33993e5'] );
276 my $all = $inst->all;
277  
278 Gather info about a several instruments by their ids; data is returned as a C<Finance::Robinhood::Utils::Paginated> object.
279  
280 Other arguments such as the boolean values for C<nocache> and C<active_instruments_only> are also supported.
281  
282 =cut
283  
284 sub equity_instruments {
285 0 ▶ my ( $s, %args ) = @_;
Subroutine equity_instruments: not called CC=2 SCAR=17.9
Pod documented
286 Finance::Robinhood::Utils::Paginated->new(
287 class => 'Finance::Robinhood::Equity::Instrument',
288 next => join '?',
289 $Endpoints{'instruments'}, (
290 join '&',
291 map {
292 0 $_ . '=' .
293 0 ▶ ( ref $args{$_} eq 'ARRAY' ? ( join ',', @{ $args{$_} } ) : $args{$_} )
Branch: 1 branch
BranchTrueFalseTotal
ref $args{$_} eq 'ARRAY' ? : 0 0 0
294 } keys %args
295 )
296 );
297 }
298  
299 =head2 C<equity_instrument( ... )>
300  
301 my $labu = $rh->equity_instrument('6a17083e-2867-4a20-9b78-a0a46b422279');
302  
303 Gather data as a L<Finance::Robinhood::Instrument> object.
304  
305 =cut
306  
307 sub equity_instrument {
308 0 ▶ my ( $s, $id ) = @_;
Subroutine equity_instrument: not called CC=2 SCAR=17.9
Pod documented
309 0 warn $id;
310 0 my ( $status, $data ) = $s->get( sprintf $Endpoints{'instruments/{id}'}, $id );
311 0 ▶ $status == 200 ? Finance::Robinhood::Equity::Instrument->new($data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
$status == 200 ? : 0 0 0
312 }
313  
314 =head2 C<options_chains( ... )>
315  
316 my $ok = $rh->options_chains();
317  
318 Gather info about all supported options chains. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
319  
320 my $inst = $rh->options_chains( ids => ['0c0959c2-eb3a-4e3b-8310-04d7eda4b35c'] );
321 my $all = $inst->all;
322  
323 Gather info about several options chains at once by id. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
324  
325 my $inst = $rh->options_chains( equity_instrument_ids => ['6a17083e-2867-4a20-9b78-a0a46b422279'] );
326 my $all = $inst->all;
327  
328 Gather options chains related to a security by the security's id. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
329  
330 =cut
331  
332 sub options_chains {
333 0 ▶ my ( $s, %args ) = @_;
Subroutine options_chains: not called CC=2 SCAR=17.9
Pod documented
334 Finance::Robinhood::Utils::Paginated->new(
335 class => 'Finance::Robinhood::Options::Chain',
336 next => join '?',
337 $Endpoints{'options/chains'}, (
338 join '&',
339 map {
340 0 $_ . '=' .
341 0 ▶ ( ref $args{$_} eq 'ARRAY' ? ( join ',', @{ $args{$_} } ) : $args{$_} )
Branch: 1 branch
BranchTrueFalseTotal
ref $args{$_} eq 'ARRAY' ? : 0 0 0
342 } keys %args
343 )
344 );
345 }
346  
347 =head2 C<options_instruments( ... )>
348  
349 my $ok = $rh->options_instruments();
350  
351 Gather info about all supported options instruments. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
352  
353 my $inst = $rh->options_instruments( ids => ['73f75306-ad07-4734-972b-22ab9dec6693'] );
354 my $all = $inst->all;
355  
356 Gather info about several options chains at once by instrument id. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
357  
358 my $inst = $rh->options_instruments( tradability => 'tradable' );
359 my $all = $inst->all;
360  
361 Gather info about several options chains at once but only those that are currently 'tradable' or 'untradable'.
362 This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
363  
364 my $inst = $rh->options_instruments( state => 'active' );
365 my $all = $inst->all;
366  
367 Gather info about several options chains at once but only those that are currently 'active', 'inactive', or 'expired'.
368 This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
369  
370 Other supported arguments include:
371  
372 =over
373  
374 =item C<type> - 'call' or 'put'
375  
376 =item C<expiration_dates> - an array ref of dates in the form 'YYYY-MM-DD'
377  
378 =item C<chain_id> - options chain's UUID
379  
380 =back
381  
382 =cut
383  
384 sub options_instruments {
385 0 ▶ my ( $s, %args ) = @_;
Subroutine options_instruments: not called CC=2 SCAR=17.9
Pod documented
386 Finance::Robinhood::Utils::Paginated->new(
387 class => 'Finance::Robinhood::Options::Instrument',
388 next => join '?',
389 $Endpoints{'options/instruments'}, (
390 join '&',
391 map {
392 0 $_ . '=' .
393 0 ▶ ( ref $args{$_} eq 'ARRAY' ? ( join ',', @{ $args{$_} } ) : $args{$_} )
Branch: 1 branch
BranchTrueFalseTotal
ref $args{$_} eq 'ARRAY' ? : 0 0 0
394 } keys %args
395 )
396 );
397 }
398  
399 =head2 C<options_suitability( ... )>
400  
401 my $account = $rh->options_suitability();
402  
403 Find out if your account is eligible to move to any of the supported options levels.
404  
405 The returned data is a hash containing the max level and any changes to your profile that needs to be updated.
406  
407 =cut
408  
409 sub options_suitability {
410 0 ▶ my ( $s, %args ) = @_;
Subroutine options_suitability: not called CC=1 SCAR=6.9
Pod documented
411 0 $s->get( $Endpoints{'options/suitability'} );
412 }
413  
414 =head2 C<place_options_order( ... )>
415  
416  
417 =cut
418  
419 sub place_options_order {
420 0 ▶ my ( $s, %args ) = @_;
Subroutine place_options_order: not called CC=7 SCAR=40.3
Pod documented
421 $args{'account'}
422 0 ▶ = ( $args{'account'} // Finance::Robinhood::Utils::Client->instance->account )->url;
Condition0%0/3
$args{"account"} // "Finance::Robinhood::Utils::Client"->instance->account
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"account"} // "Finance::Robinhood::Utils::Client"->instance->account
$args{"account"} "Finance::Robinhood::Utils::Client"->instance->account
Truth table0%0/3
A // B
A= $args{"account"}B= "Finance::Robinhood::Utils::Client"->instance->account
ABresult
1X1
011
000
423 0 $_->{'option'} = $_->{'option'}->url for @{ $args{'legs'} };
424 0 ▶ $args{'override_day_trade_checks'} //= \0;
Condition0%0/2
$args{"override_day_trade_checks"} //= \0
l!l
00
MC/DC0%0/1
$args{"override_day_trade_checks"} //= \0
$args{"override_day_trade_checks"}
Truth table0%0/2
A
A= $args{"override_day_trade_checks"}
Aresult
11
00
425 0 ▶ $args{'override_dtbp_checks'} //= \0;
Condition0%0/2
$args{"override_dtbp_checks"} //= \0
l!l
00
MC/DC0%0/1
$args{"override_dtbp_checks"} //= \0
$args{"override_dtbp_checks"}
Truth table0%0/2
A
A= $args{"override_dtbp_checks"}
Aresult
11
00
426 0 ▶ $args{'ref_id'} //= uuid(); # Random
Condition0%0/3
$args{"ref_id"} //= uuid()
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"ref_id"} //= uuid()
$args{"ref_id"} uuid()
Truth table0%0/3
A //= B
A= $args{"ref_id"}B= uuid()
ABresult
1X1
011
000
427  
428  
429 #my $post = {
430 # account => Finance::Robinhood::Utils::Client->instance->account->url,
431 # direction => 'debit', # credit or 'debit'
432 # legs => [
433 # {
434 # option => $s->url,
435 # position_effect => 'open', # open or close
436 # ratio_quantity=> 1,
437 # side=> 'buy' # buy or sell
438 # }
439 # ],
440 # override_day_trade_checks => \0,
441 # override_dtbp_checks => \0,
442 # price => .05,
443 # quantity=> 1,
444 # ref_id => uuid(), # Random
445 # time_in_force => 'gfd',
446 # type => 'limit',
447 # #
448 # trigger => 'immediate'
449 #};
450  
451 #ddx \%args;
452 0 my ( $status, $data ) = $s->post( $Endpoints{'options/orders'}, \%args );
453 0 ▶ $status == 201 ? Finance::Robinhood::Options::Order->new($data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
$status == 201 ? : 0 0 0
454 }
455  
456 =head2 C<options_order( ... )>
457  
458 my $order = $rh->options_order('0adf9278-095d-ef93-eac37a8199fe');
459 $order->cancel;
460  
461 Gather a single order by id. This is returned as a new C<Finance::Robinhood::Options::Order> object.
462  
463 =cut
464  
465 sub options_order {
466 0 ▶ my ( $s, $id ) = @_;
Subroutine options_order: not called CC=2 SCAR=17.9
Pod documented
467 0 my ( $status, $data ) = $s->get( sprintf $Endpoints{'options/orders/{id}'}, $id );
468 0 ▶ $status == 200 ? Finance::Robinhood::Options::Order->new($data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
$status == 200 ? : 0 0 0
469 }
470  
471 =head2 C<options_orders( ... )>
472  
473 my $ok = $rh->options_orders();
474  
475 Gather info about all options orders. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
476  
477 my $inst = $rh->options_chains( 'since' => '2018-10-01' );
478 my $all = $inst->all;
479  
480 Gather info about options orders after a certain date. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
481  
482 =cut
483  
484 sub options_orders {
485 0 ▶ my ( $s, %args ) = @_;
Subroutine options_orders: not called CC=4 SCAR=30.0
Pod documented
486 0 ▶ $args{'updated_at[gte]'} = delete $args{'since'} if defined $args{'since'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"since"} 0 0 0
487 0 ▶ $args{'updated_at[lte]'} = delete $args{'before'} if defined $args{'before'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"before"} 0 0 0
488 Finance::Robinhood::Utils::Paginated->new(
489 class => 'Finance::Robinhood::Options::Order',
490 next => join '?',
491 $Endpoints{'options/orders'}, (
492 join '&',
493 map {
494 0 $_ . '=' .
495 0 ▶ ( ref $args{$_} eq 'ARRAY' ? ( join ',', @{ $args{$_} } ) : $args{$_} )
Branch: 1 branch
BranchTrueFalseTotal
ref $args{$_} eq 'ARRAY' ? : 0 0 0
496 } keys %args
497 )
498 );
499 }
500  
501 =head2 C<options_positions( ... )>
502  
503 my $ok = $rh->options_positions();
504  
505 Gather info about all options orders. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
506  
507 Possible parameters are:
508  
509 =over
510  
511 =item C<chain_ids> - list of ids
512  
513 =item C<type> - 'long' or 'short'
514  
515 =back
516  
517 =cut
518  
519 sub options_positions {
520 0 ▶ my ( $s, %args ) = @_;
Subroutine options_positions: not called CC=2 SCAR=17.9
Pod documented
521 Finance::Robinhood::Utils::Paginated->new(
522 class => 'Finance::Robinhood::Options::Position',
523 next => join '?',
524 $Endpoints{'options/positions'}, (
525 join '&',
526 map {
527 0 $_ . '=' .
528 0 ▶ ( ref $args{$_} eq 'ARRAY' ? ( join ',', @{ $args{$_} } ) : $args{$_} )
Branch: 1 branch
BranchTrueFalseTotal
ref $args{$_} eq 'ARRAY' ? : 0 0 0
529 } keys %args
530 )
531 );
532 }
533  
534 =head2 C<options_position( ... )>
535  
536 my $labu = $rh->options_position('6a17083e-2867-4a20-9b78-a0a46b422279');
537  
538 Gather data as a L<Finance::Robinhood::Options::Position> object.
539  
540 =cut
541  
542 sub options_position {
543 0 ▶ my ( $s, $id ) = @_;
Subroutine options_position: not called CC=2 SCAR=17.9
Pod documented
544 0 warn $id;
545 0 my ( $status, $data ) = $s->get( sprintf $Endpoints{'options/positions/{id}'}, $id );
546 0 ▶ $status == 200 ? Finance::Robinhood::Options::Position->new($data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
$status == 200 ? : 0 0 0
547 }
548  
549 =head2 C<options_events( ... )>
550  
551 my $ok = $rh->options_events();
552  
553 Gather info about recent options events. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
554  
555 =cut
556  
557 sub options_events {
558 0 ▶ my ($s) = @_;
Subroutine options_events: not called CC=1 SCAR=6.9
Pod documented
559 Finance::Robinhood::Utils::Paginated->new(
560 class => 'Finance::Robinhood::Options::Event',
561 0 next => $Endpoints{'options/events'}
562 );
563 }
564  
565 =head2 C<account( ... )>
566  
567 my $account = $rh->accounts();
568  
569 Gather info about all brokerage accounts.
570  
571 Please note that this will be a cached value. If you need updated information, use C<accounts( )>.
572  
573 =head2 C<accounts( ... )>
574  
575 my $account = $rh->accounts()->next;
576  
577 Gather info about all brokerage accounts. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
578  
579 This is rather useless seeing as we're only allowed a single account per signup.
580  
581 =cut
582  
583 sub accounts {
584 0 ▶ my ( $s, %args ) = @_;
Subroutine accounts: not called CC=1 SCAR=6.9
Pod documented
585 Finance::Robinhood::Utils::Paginated->new(
586 class => 'Finance::Robinhood::Account',
587 0 next => $Endpoints{'accounts'}
588 );
589 }
590  
591 =head2 C<ach_relationships( ... )>
592  
593 my $ok = $rh->ach_relationships();
594  
595 Gather info about all attached bank accounts. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
596  
597 =cut
598  
599 sub ach_relationships {
600 0 ▶ my ( $s, %args ) = @_;
Subroutine ach_relationships: not called CC=1 SCAR=6.9
Pod documented
601 Finance::Robinhood::Utils::Paginated->new(
602 class => 'Finance::Robinhood::ACH',
603 0 next => $Endpoints{'ach/relationships'}
604 );
605 }
606  
607 =head2 C<create_ach_relationship( ... )>
608  
609 my $ok = $rh->create_ach_relationship(
610 bank_routing_number => '026009593',
611 bank_account_number => '009872784317963',
612 bank_account_type => 'checking',
613 bank_account_holder_name => 'John Smith
614 );
615  
616 Attach a bank accounts to your Robinhood account. This is returned as a C<Finance::Robinhood::ACH> object if everything goes well.
617  
618 All arguments are required. C<bank_account_type> is either C<'checking'> or C<'savings'>.
619  
620 =cut
621  
622 sub create_ach_relationship {
623 0 ▶ my ( $s, %args ) = @_;
Subroutine create_ach_relationship: not called CC=2 SCAR=17.9
Pod documented
624 0 $args{account} = $s->accounts->next->url;
625 0 my ( $status, $data ) = $s->post( sprintf $Endpoints{'ach/relationships'}, \%args );
626 0 ▶ $status == 201 ? Finance::Robinhood::ACH->new($data) : $data;
Branch: 1 branch
BranchTrueFalseTotal
$status == 201 ? : 0 0 0
627 }
628  
629 =head2 C<ach_deposit_schedules( ... )>
630  
631 my $ok = $rh->ach_deposit_schedules();
632 my $all = $ok->all;
633  
634 Gather info about scheduled ACH deposits. This is returned as a C<Finance::Robinhood::Utils::Paginated> object.
635  
636 =cut
637  
638 sub ach_deposit_schedules {
639 0 ▶ my ( $s, %args ) = @_;
Subroutine ach_deposit_schedules: not called CC=1 SCAR=6.9
Pod documented
640 Finance::Robinhood::Utils::Paginated->new(
641 class => 'Finance::Robinhood::ACH::ScheduledDeposit',
642 0 next => $Endpoints{'ach/deposit_schedules'}
643 );
644 }
645  
646 =head1 LEGAL
647  
648 This is a simple wrapper around the API used in the official apps. The author
649 provides no investment, legal, or tax advice and is not responsible for any
650 damages incurred while using this software. Neither this software nor its
651 author are affiliated with Robinhood Financial LLC in any way.
652  
653 For Robinhood's terms and disclosures, please see their website at http://robinhood.com/
654  
655 =head1 LICENSE
656  
657 Copyright (C) Sanko Robinson.
658  
659 This library is free software; you can redistribute it and/or modify
660 it under the terms found in the Artistic License 2.
661 Other copyrights, terms, and conditions may apply to data transmitted through
662 this module. Please refer to the L<LEGAL> section.
663  
664 =head1 AUTHOR
665  
666 Sanko Robinson E<lt>sanko@cpan.orgE<gt>
667  
668 =cut
669  
670 3 1;
« blib/lib/Finance/Robinhood/Utils/Client.pm ↑ Summary blib/lib/Finance/Robinhood/Utils/Paginated.pm »