| 1 | package Finance::Robinhood::Options::Chain; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | =for stopwords watchlist watchlists untradable urls | ||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | Finance::Robinhood::Options::Chain - Represents a Single Options Chain | ||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | use Finance::Robinhood; | ||||||||||||||||||
| 14 | my $rh = Finance::Robinhood->new->login('user', 'pass'); | ||||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | # TODO | ||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | =head1 METHODS | ||||||||||||||||||
| 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 | 1 | ▶ | use Time::Moment; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 26 | 1 | ▶ | use Finance::Robinhood::Options::Chain::Ticks; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 27 | 1 | ▶ | use Finance::Robinhood::Options::Chain::Underlying; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | 1 | ▶ | sub _test__init { | ||||||||||||||||
|
Subroutine
_test__init: called CC=3 SCAR=11.0
| |||||||||||||||||||
| 30 | 1 | my $rh = t::Utility::rh_instance(0); | |||||||||||||||||
| 31 | 1 | my $chains = $rh->options_chains; | |||||||||||||||||
| 32 | 1 | my $chain; | |||||||||||||||||
| 33 | 1 | ▶ | while ($chains->has_next) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 34 | 2 | my @dates = $chains->next->expiration_dates; | |||||||||||||||||
| 35 | 2 | ▶ | if (@dates) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 36 | 1 | $chain = $chains->current; | |||||||||||||||||
| 37 | 1 | last; | |||||||||||||||||
| 38 | } | ||||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | 1 | isa_ok($chain, __PACKAGE__); | |||||||||||||||||
| 41 | 1 | t::Utility::stash('CHAIN', $chain); # Store it for later | |||||||||||||||||
| 42 | } | ||||||||||||||||||
| 43 | 1 | ▶ | use overload '""' => sub ($s, @) { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 44 | 1 | 'https://api.robinhood.com/options/chains/' . $s->{id} . '/'; | |||||||||||||||||
| 45 | }, | ||||||||||||||||||
| 46 | 1 | fallback => 1; | |||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | 1 | ▶ | sub _test_stringify { | ||||||||||||||||
|
Subroutine
_test_stringify: called CC=2 SCAR=7.2
| |||||||||||||||||||
| 49 | 1 | ▶ | t::Utility::stash('CHAIN') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("CHAIN") // skip_all()
MC/DC0%0/2
t::Utility::stash("CHAIN") // skip_all()
t::Utility::stash("CHAIN")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("CHAIN")B= skip_all()
| |||||||||||||||||||
| 50 | 1 | like(+t::Utility::stash('CHAIN'), | |||||||||||||||||
| 51 | qr'^https://api.robinhood.com/options/chains/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/$'i | ||||||||||||||||||
| 52 | ); | ||||||||||||||||||
| 53 | } | ||||||||||||||||||
| 54 | 1 | has _rh => undef => weak => 1; | |||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | =head2 C<can_open_position( )> | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | Returns a boolean value. True if you may open a new position. | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | =head2 C<cash_compenent( )> | ||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | If defined, a dollar amount. | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | =head2 C<id( )> | ||||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | Returns a UUID. | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | =head2 C<symbol( )> | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | Chain's ticker symbol. | ||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | =head2 C<trade_value_multiplier( )> | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | =cut | ||||||||||||||||||
| 77 | |||||||||||||||||||
| 78 | 1 | has ['can_open_position', 'cash_component', | |||||||||||||||||
| 79 | 'id', 'symbol', | ||||||||||||||||||
| 80 | 'trade_value_multiplier' | ||||||||||||||||||
| 81 | ]; | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | =head2 C<expiration_dates( )> | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | Returns a list of Time::Moment objects. | ||||||||||||||||||
| 86 | |||||||||||||||||||
| 87 | =cut | ||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | 3 | ▶ | sub expiration_dates($s) { | ||||||||||||||||
|
Subroutine
expiration_dates: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 90 | 14 | map { Time::Moment->from_string($_ . 'T00:00:00Z') } | |||||||||||||||||
| 91 | 3 | @{$s->{expiration_dates}}; | |||||||||||||||||
| 92 | } | ||||||||||||||||||
| 93 | |||||||||||||||||||
| 94 | 1 | ▶ | sub _test_expiration_dates { | ||||||||||||||||
|
Subroutine
_test_expiration_dates: called CC=2 SCAR=7.1
| |||||||||||||||||||
| 95 | 1 | ▶ | t::Utility::stash('CHAIN') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("CHAIN") // skip_all()
MC/DC0%0/2
t::Utility::stash("CHAIN") // skip_all()
t::Utility::stash("CHAIN")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("CHAIN")B= skip_all()
| |||||||||||||||||||
| 96 | 1 | my ($date) = t::Utility::stash('CHAIN')->expiration_dates; | |||||||||||||||||
| 97 | 1 | isa_ok($date, 'Time::Moment'); | |||||||||||||||||
| 98 | } | ||||||||||||||||||
| 99 | |||||||||||||||||||
| 100 | =head2 C<underlying_instruments( )> | ||||||||||||||||||
| 101 | |||||||||||||||||||
| 102 | Returns a list of Finance::Robinhood::Options::Chain::Underlying objects. | ||||||||||||||||||
| 103 | |||||||||||||||||||
| 104 | =cut | ||||||||||||||||||
| 105 | |||||||||||||||||||
| 106 | 1 | ▶ | sub underlying_instruments($s) { | ||||||||||||||||
|
Subroutine
underlying_instruments: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 107 | map { | ||||||||||||||||||
| 108 | 1 | Finance::Robinhood::Options::Chain::Underlying->new(_rh => $s->_rh, | |||||||||||||||||
| 109 | %$_) | ||||||||||||||||||
| 110 | 1 | } @{$s->{underlying_instruments}}; | |||||||||||||||||
| 111 | } | ||||||||||||||||||
| 112 | |||||||||||||||||||
| 113 | 1 | ▶ | sub _test_underlying_instruments { | ||||||||||||||||
|
Subroutine
_test_underlying_instruments: called CC=2 SCAR=7.1
| |||||||||||||||||||
| 114 | 1 | ▶ | t::Utility::stash('CHAIN') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("CHAIN") // skip_all()
MC/DC0%0/2
t::Utility::stash("CHAIN") // skip_all()
t::Utility::stash("CHAIN")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("CHAIN")B= skip_all()
| |||||||||||||||||||
| 115 | 1 | my ($underlying) = t::Utility::stash('CHAIN')->underlying_instruments; | |||||||||||||||||
| 116 | 1 | isa_ok($underlying, 'Finance::Robinhood::Options::Chain::Underlying'); | |||||||||||||||||
| 117 | } | ||||||||||||||||||
| 118 | |||||||||||||||||||
| 119 | =head2 C<min_ticks( )> | ||||||||||||||||||
| 120 | |||||||||||||||||||
| 121 | Returns a Finance::Robinhood::Options::Chain::Ticks object. | ||||||||||||||||||
| 122 | |||||||||||||||||||
| 123 | =cut | ||||||||||||||||||
| 124 | |||||||||||||||||||
| 125 | 2 | ▶ | sub min_ticks ($s) { | ||||||||||||||||
|
Subroutine
min_ticks: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 126 | Finance::Robinhood::Options::Chain::Ticks->new(_rh => $s->_rh, | ||||||||||||||||||
| 127 | 2 | %{$s->{min_ticks}}); | |||||||||||||||||
| 128 | } | ||||||||||||||||||
| 129 | |||||||||||||||||||
| 130 | 1 | ▶ | sub _test_min_ticks { | ||||||||||||||||
|
Subroutine
_test_min_ticks: called CC=2 SCAR=7.2
| |||||||||||||||||||
| 131 | 1 | ▶ | t::Utility::stash('CHAIN') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("CHAIN") // skip_all()
MC/DC0%0/2
t::Utility::stash("CHAIN") // skip_all()
t::Utility::stash("CHAIN")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("CHAIN")B= skip_all()
| |||||||||||||||||||
| 132 | 1 | isa_ok(t::Utility::stash('CHAIN')->min_ticks, | |||||||||||||||||
| 133 | 'Finance::Robinhood::Options::Chain::Ticks'); | ||||||||||||||||||
| 134 | } | ||||||||||||||||||
| 135 | |||||||||||||||||||
| 136 | =head1 LEGAL | ||||||||||||||||||
| 137 | |||||||||||||||||||
| 138 | This is a simple wrapper around the API used in the official apps. The author | ||||||||||||||||||
| 139 | provides no investment, legal, or tax advice and is not responsible for any | ||||||||||||||||||
| 140 | damages incurred while using this software. This software is not affiliated | ||||||||||||||||||
| 141 | with Robinhood Financial LLC in any way. | ||||||||||||||||||
| 142 | |||||||||||||||||||
| 143 | For Robinhood's terms and disclosures, please see their website at | ||||||||||||||||||
| 144 | https://robinhood.com/legal/ | ||||||||||||||||||
| 145 | |||||||||||||||||||
| 146 | =head1 LICENSE | ||||||||||||||||||
| 147 | |||||||||||||||||||
| 148 | Copyright (C) Sanko Robinson. | ||||||||||||||||||
| 149 | |||||||||||||||||||
| 150 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||
| 151 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||||||||||||||||||
| 152 | conditions may apply to data transmitted through this module. Please refer to | ||||||||||||||||||
| 153 | the L<LEGAL> section. | ||||||||||||||||||
| 154 | |||||||||||||||||||
| 155 | =head1 AUTHOR | ||||||||||||||||||
| 156 | |||||||||||||||||||
| 157 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||
| 158 | |||||||||||||||||||
| 159 | =cut | ||||||||||||||||||
| 160 | |||||||||||||||||||
| 161 | 1 | 1; | |||||||||||||||||