« lib/Finance/Robinhood/Forex/Historicals.pm
↑ Summary
lib/Finance/Robinhood/Options/Instrument.pm »
| 1 | package Finance::Robinhood::Equity::Market; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | =encoding utf-8 | ||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | =for stopwords watchlist watchlists untradable urls | ||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | Finance::Robinhood::Equity::Market - Represents a Single Equity Market | ||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | use Finance::Robinhood; | ||||||||||||||||||
| 14 | my $rh = Finance::Robinhood->new; | ||||||||||||||||||
| 15 | my $msft = $rh->equity_instrument_by_symbol('MSFT'); | ||||||||||||||||||
| 16 | |||||||||||||||||||
| 17 | CORE::say $msft->symbol . ' is traded on ' . $msft->market->name; | ||||||||||||||||||
| 18 | |||||||||||||||||||
| 19 | =cut | ||||||||||||||||||
| 20 | |||||||||||||||||||
| 21 | 1 | our $VERSION = '0.92_003'; | |||||||||||||||||
| 22 | 1 | ▶ | use Mojo::Base-base, -signatures; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 23 | 1 | ▶ | use Mojo::URL; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 24 | 1 | ▶ | use Time::Moment; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 25 | 1 | ▶ | use Finance::Robinhood::Equity::Market::Hours; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 26 | |||||||||||||||||||
| 27 | 1 | ▶ | sub _test__init { | ||||||||||||||||
|
Subroutine
_test__init: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 28 | 1 | my $rh = t::Utility::rh_instance(0); | |||||||||||||||||
| 29 | 1 | my $market = $rh->equity_market_by_mic('XNAS'); # NASDAQ | |||||||||||||||||
| 30 | 1 | isa_ok($market, __PACKAGE__); | |||||||||||||||||
| 31 | 1 | t::Utility::stash('MARKET', $market); # Store it for later | |||||||||||||||||
| 32 | } | ||||||||||||||||||
| 33 | 1 | ▶ | use overload '""' => sub ($s, @) { $s->{url} }, fallback => 1; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 1 | ▶ | sub _test_stringify { | ||||||||||||||||
|
Subroutine
_test_stringify: called CC=2 SCAR=7.2
| |||||||||||||||||||
| 36 | 1 | ▶ | t::Utility::stash('MARKET') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("MARKET") // skip_all()
MC/DC0%0/2
t::Utility::stash("MARKET") // skip_all()
t::Utility::stash("MARKET")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MARKET")B= skip_all()
| |||||||||||||||||||
| 37 | 1 | is(+t::Utility::stash('MARKET'), | |||||||||||||||||
| 38 | 'https://api.robinhood.com/markets/XNAS/'); | ||||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | # | ||||||||||||||||||
| 41 | 1 | has _rh => undef => weak => 1; | |||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | =head1 METHODS | ||||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | =head2 C<acronym( )> | ||||||||||||||||||
| 46 | |||||||||||||||||||
| 47 | Simple acronym typically used to identify the exchange. Note that the same | ||||||||||||||||||
| 48 | acronym may be used for more than one venue. | ||||||||||||||||||
| 49 | |||||||||||||||||||
| 50 | =head2 C<city( )> | ||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | Location of the exchange/market. | ||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | =head2 C<country( )> | ||||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | Location of the exchange/market. | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | =head2 C<mic( )> | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | Returns the ISO 10383 Market Identifier Code. | ||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | =head2 C<name( )> | ||||||||||||||||||
| 63 | |||||||||||||||||||
| 64 | Name of the exchange/market. Suited for display. | ||||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | =head2 C<operating_mic( )> | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | Returns the ISO 20022 Operating Market Identifier Code. | ||||||||||||||||||
| 69 | |||||||||||||||||||
| 70 | =head2 C<timezone( )> | ||||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | Timezone of the exchange/market. | ||||||||||||||||||
| 73 | |||||||||||||||||||
| 74 | =cut | ||||||||||||||||||
| 75 | |||||||||||||||||||
| 76 | 1 | has ['acronym', 'city', 'country', 'mic', 'name', 'operating_mic', | |||||||||||||||||
| 77 | 'timezone']; | ||||||||||||||||||
| 78 | |||||||||||||||||||
| 79 | =head2 C<website()> | ||||||||||||||||||
| 80 | |||||||||||||||||||
| 81 | Website of the exchange in a Mojo::URL object. | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | =cut | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | 2 | ▶ | sub website ($s) { | ||||||||||||||||
|
Subroutine
website: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 86 | 2 | Mojo::URL->new($s->{website}); | |||||||||||||||||
| 87 | } | ||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | 1 | ▶ | sub _test_website { | ||||||||||||||||
|
Subroutine
_test_website: called CC=2 SCAR=7.1
| |||||||||||||||||||
| 90 | 1 | ▶ | t::Utility::stash('MARKET') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("MARKET") // skip_all()
MC/DC0%0/2
t::Utility::stash("MARKET") // skip_all()
t::Utility::stash("MARKET")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MARKET")B= skip_all()
| |||||||||||||||||||
| 91 | 1 | isa_ok(t::Utility::stash('MARKET')->website, 'Mojo::URL'); | |||||||||||||||||
| 92 | 1 | is(+t::Utility::stash('MARKET')->website, 'www.nasdaq.com'); | |||||||||||||||||
| 93 | } | ||||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | =head2 C<todays_hours( )> | ||||||||||||||||||
| 96 | |||||||||||||||||||
| 97 | my $hours = $market->todays_hours( ); | ||||||||||||||||||
| 98 | |||||||||||||||||||
| 99 | Return a Finance::Robinhood::Equity::Market::Hours object with today's data. | ||||||||||||||||||
| 100 | |||||||||||||||||||
| 101 | =cut | ||||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | 1 | ▶ | sub todays_hours ( $s ) { | ||||||||||||||||
|
Subroutine
todays_hours: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||
| 104 | 1 | my $res = $s->_rh->_get($s->{todays_hours}); | |||||||||||||||||
| 105 | $res->is_success | ||||||||||||||||||
| 106 | ? Finance::Robinhood::Equity::Market::Hours->new(_rh => $s->_rh, | ||||||||||||||||||
| 107 | 1 | ▶ | %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 108 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 109 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 110 | } | ||||||||||||||||||
| 111 | |||||||||||||||||||
| 112 | 1 | ▶ | sub _test_todays_hours { | ||||||||||||||||
|
Subroutine
_test_todays_hours: called CC=2 SCAR=7.0
| |||||||||||||||||||
| 113 | 1 | ▶ | t::Utility::stash('MARKET') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("MARKET") // skip_all()
MC/DC0%0/2
t::Utility::stash("MARKET") // skip_all()
t::Utility::stash("MARKET")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MARKET")B= skip_all()
| |||||||||||||||||||
| 114 | 1 | my $hours = t::Utility::stash('MARKET')->todays_hours(); | |||||||||||||||||
| 115 | 1 | isa_ok($hours, 'Finance::Robinhood::Equity::Market::Hours'); | |||||||||||||||||
| 116 | 1 | ok($hours->date <= Time::Moment->now_utc); | |||||||||||||||||
| 117 | } | ||||||||||||||||||
| 118 | |||||||||||||||||||
| 119 | =head2 C<hours( ... )> | ||||||||||||||||||
| 120 | |||||||||||||||||||
| 121 | my $hours = $market->hours( $date ); | ||||||||||||||||||
| 122 | |||||||||||||||||||
| 123 | Returns the Finance::Robinhood::Equity::Market::Hours object for the given | ||||||||||||||||||
| 124 | date. This method expects C<$date> to be a Time::Moment object. | ||||||||||||||||||
| 125 | |||||||||||||||||||
| 126 | =cut | ||||||||||||||||||
| 127 | |||||||||||||||||||
| 128 | 3 | ▶ | sub hours ($s, $date) { | ||||||||||||||||
|
Subroutine
hours: called CC=3 SCAR=13.1
Pod
documented
| |||||||||||||||||||
| 129 | my $res = $s->_rh->_get( | ||||||||||||||||||
| 130 | 3 | $s->{url} . 'hours/' . $date->strftime('%Y-%m-%d') . '/'); | |||||||||||||||||
| 131 | $res->is_success | ||||||||||||||||||
| 132 | ? Finance::Robinhood::Equity::Market::Hours->new(_rh => $s->_rh, | ||||||||||||||||||
| 133 | 3 | ▶ | %{$res->json}) | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 134 | : Finance::Robinhood::Error->new( | ||||||||||||||||||
| 135 | $res->is_server_error ? (details => $res->message) : $res->json); | ||||||||||||||||||
| 136 | } | ||||||||||||||||||
| 137 | |||||||||||||||||||
| 138 | 1 | ▶ | sub _test_hours { | ||||||||||||||||
|
Subroutine
_test_hours: called CC=2 SCAR=7.0
| |||||||||||||||||||
| 139 | 1 | ▶ | t::Utility::stash('MARKET') // skip_all(); | ||||||||||||||||
|
Condition50%1/2
t::Utility::stash("MARKET") // skip_all()
MC/DC0%0/2
t::Utility::stash("MARKET") // skip_all()
t::Utility::stash("MARKET")
skip_all()
Truth table33%1/3
A // B
A= t::Utility::stash("MARKET")B= skip_all()
| |||||||||||||||||||
| 140 | 1 | my $hours = t::Utility::stash('MARKET')->hours(Time::Moment->now); | |||||||||||||||||
| 141 | 1 | isa_ok($hours, 'Finance::Robinhood::Equity::Market::Hours'); | |||||||||||||||||
| 142 | 1 | is($hours->date->strftime('%Y-%m-%d'), | |||||||||||||||||
| 143 | Time::Moment->now->strftime('%Y-%m-%d')); | ||||||||||||||||||
| 144 | } | ||||||||||||||||||
| 145 | |||||||||||||||||||
| 146 | =head1 LEGAL | ||||||||||||||||||
| 147 | |||||||||||||||||||
| 148 | This is a simple wrapper around the API used in the official apps. The author | ||||||||||||||||||
| 149 | provides no investment, legal, or tax advice and is not responsible for any | ||||||||||||||||||
| 150 | damages incurred while using this software. This software is not affiliated | ||||||||||||||||||
| 151 | with Robinhood Financial LLC in any way. | ||||||||||||||||||
| 152 | |||||||||||||||||||
| 153 | For Robinhood's terms and disclosures, please see their website at | ||||||||||||||||||
| 154 | https://robinhood.com/legal/ | ||||||||||||||||||
| 155 | |||||||||||||||||||
| 156 | =head1 LICENSE | ||||||||||||||||||
| 157 | |||||||||||||||||||
| 158 | Copyright (C) Sanko Robinson. | ||||||||||||||||||
| 159 | |||||||||||||||||||
| 160 | This library is free software; you can redistribute it and/or modify it under | ||||||||||||||||||
| 161 | the terms found in the Artistic License 2. Other copyrights, terms, and | ||||||||||||||||||
| 162 | conditions may apply to data transmitted through this module. Please refer to | ||||||||||||||||||
| 163 | the L<LEGAL> section. | ||||||||||||||||||
| 164 | |||||||||||||||||||
| 165 | =head1 AUTHOR | ||||||||||||||||||
| 166 | |||||||||||||||||||
| 167 | Sanko Robinson E<lt>sanko@cpan.orgE<gt> | ||||||||||||||||||
| 168 | |||||||||||||||||||
| 169 | =cut | ||||||||||||||||||
| 170 | |||||||||||||||||||
| 171 | 1 | 1; | |||||||||||||||||