Finance::Robinhood - Banking, Stock, ETF, Options, and Cryptocurrency Trading Without Fees or Commissions
use Finance::Robinhood;
my $rh = Finance::Robinhood->new();
$rh->equity('MSFT')->buy(2)->limit(187.34)->submit;
Finance::Robinhood wraps several APIs. There are parts of this package that will not apply because your account does not have access to certain features.
Robinhood requires an authorization token for most API calls. To get this token, you must log in with your username and password. But we'll get into that later. For now, let's create a client object...
# You can look up some basic instrument data with this
my $rh = Finance::Robinhood->new();
A new Finance::Robinhood object is created without credentials. Before you can buy or sell or do almost anything else, you must log in.
To log in, you must pass a combination of the following parameters:
Shh!
This is you. Be careful with you.
Private!
To log in manually, you'll need to provide your password.
If you have previously authorized this package to access your account, passing the OAuth2 tokens here will prevent you from having to log in with your user data.
These tokens should be kept private.
If you have previously authorized this package to access your account, passing the assigned device ID here will prevent you from having to authorize it again upon log in.
Like authorization tokens, this UUID should be kept private.
my $rh = Finance::Robinhood->new(username => $user, password => $pass, mfa_callback => sub {
# Do something like pop open an inputbox in TK, read from shell or whatever
} );
If you have MFA enabled, you may (or must) also pass a callback. When the code
is called, a ref will be passed that will contain mfa_required
(a boolean
value) and mfa_type
which might be app
, sms
, etc. Your return value
must be the MFA code.
my $rh = Finance::Robinhood->new(username => $user, password => $pass, mfa_code => 980385);
If you already know the MFA code (for example if you have MFA enabled through an app), you can pass that code directly and log in.
my $rh = Finance::Robinhood->new(username => $user, password => $pass, challenge_callback => sub {
my ($challenge) = @_;
# Do something like pop open an inputbox in TK, read from shell or whatever
$challenge->respond( ... );
$challenge;
} );
When logging in with a new client, you are required to authorize it to access your account.
This callback should should expect a Finance::Robinhood::Device::Challenge object and must return the object after validation.
Optional OAuth scopes as a single string or a list of values. If you don't know
what to pass here, passing nothing will force the client pretend to be an
official app and use the internal
scope with full access.
OAuth2 authorization tokens expire after a defined amount of time (24 hours from login). To continue your session, you must refresh this token by calling this method.
my $results = $rh->search('microsoft');
Returns a set of search results by type. These types are sorted into hash keys:
currency_pairs
- A list of Finance::Robinhood::Currency::Pair objectsequities
- A list of Finance::Robinhood::Equity objectstags
- A list of Finance::Robinhood::Equity::Collection objectslists
- A list of Finance::Robinhood::Equity::List objects
You do not need to be logged in for this to work.
my $news = $rh->news('MSFT');
my $news = $rh->news('1072fc76-1862-41ab-82c2-485837590762'); # Forex - USD
An iterator containing Finance::Robinhood::News objects is returned.
my $feed = $rh->feed();
An iterator containing Finance::Robinhood::News objects is returned. This list will be filled with news related to instruments in your watchlist and portfolio.
You need to be logged in for this to work.
my $cards = $rh->notifications();
An iterator containing Finance::Robinhood::Notification objects is returned.
You need to be logged in for this to work.
my $card = $rh->notification_by_id($id);
Returns a Finance::Robinhood::Notification object. You need to be logged in for this to work and Robinhood has a terrible habit of relocating notifications so that these ids are inconsistent.
my $msft = $rh->equity('MSFT');
Searches for an equity instrument by ticker symbol and returns a Finance::Robinhood::Equity object.
my $instruments = $rh->equities();
Returns an iterator containing equity instruments.
You may restrict, search, or modify the list of instruments returned with the following optional arguments:
-
symbol
- Ticker symbolmy $msft = $rh->equities(symbol => 'MSFT')->next;
By the way,
equity( )
exists as sugar around this and returns the instrument itself rather than an iterator object with a single element. -
query
- Keyword searchmy @solar = $rh->equities(query => 'solar')->all;
-
ids
- List of instrument idsmy ( $msft, $tsla ) = $rh->equities( ids => [ '50810c35-d215-4866-9758-0ada4ac79ffa', 'e39ed23a-7bd1-4587-b060-71988d9ef483' ] ) ->all;
If you happen to know/store instrument ids, quickly get full equity objects this way.
-
active
- Boolean valuemy ($active) = $rh->equities(active => 1)->all;
If you only want active equity instruments, set this to a true value.
my $instrument = $rh->equities_by_id('50810c35-d215-4866-9758-0ada4ac79ffa');
Simple wrapper around equities_by_id( ..., ... )
that expects only a single
ID because I can't remember to use the plural version.
my $instrument = $rh->equities_by_id(
'50810c35-d215-4866-9758-0ada4ac79ffa',
'e39ed23a-7bd1-4587-b060-71988d9ef483'
);
Searches for a list of equity instruments by their instrument ids and returns a list of Finance::Robinhood::Equity objects.
my $positions = $rh->equity_positions( );
Returns an iterator with Finance::Robinhood::Equity::Position objects.
You must be logged in.
my $positions = $rh->equity_positions( nonzero => 1 );
You can filter and modify the results. All options are optional.
nonzero
- true or false. Default is falseordering
- list of equity instruments
Returns an iterator holding hash references which contain the following keys:
-
call
- Hash reference containing the following keys:broadcast_url
- Link to a website to listen to the live earnings calldatetime
- Time::Moment objectreplay_url
- Link to a website to listen to the replay of the earnings call
-
eps
- Hash reference containing the following keys:actual
- Actual reported earningsestimate
- Early estimated earnings
-
instrument
- Instrument ID (UUID) -
quarter
-1
,2
,3
, or4
-
report
- Hash reference with the following values:date
- YYYY-MM-DDtiming
-am
orpm
verified
- Boolean value
-
symbol
- Ticker symbol -
year
- YYYYmy $earnings = $rh->equity_earnings( symbol => 'MSFT' );
Returns an iterator holding hash references by ticker symbol.
my $earnings = $rh->equity_earnings( instrument => $rh->equity('MSFT') );
Returns an iterator holding hash references by instrument object/url.
my $earnings = $rh->equity_earnings( range => 7 );
Returns an iterator holding hash references for all expected earnings report
over the next X
days where X
is between -21...-1, 1...21
. Negative
values are days into the past. Positive are days into the future.
You must be logged in for any of these to work.
my $orders = $rh->equity_orders();
An iterator containing Finance::Robinhood::Equity::Order objects is returned. You need to be logged in for this to work.
my $orders = $rh->equity_orders(instrument => $msft);
If you would only like orders after a certain date, you can do that!
my $orders = $rh->equity_orders(after => Time::Moment->now->minus_days(7));
# Also accepts ISO 8601
If you would only like orders before a certain date, you can do that!
my $orders = $rh->equity_orders(before => Time::Moment->now->minus_years(2));
# Also accepts ISO 8601
my $order = $rh->equity_order_by_id($id);
Returns a Finance::Robinhood::Equity::Order object. You need to be logged in for this to work.
my $account = $rh->equity_account();
Returns the first Finance::Robinhood::Equity::Account objects. This is usually what you want to use. You need to be logged in for this to work.
my $accounts = $rh->equity_accounts();
An iterator containing Finance::Robinhood::Equity::Account objects is returned. There likely isn't more than a single account but Robinhood exposes an iterative endpoint. You need to be logged in for this to work.
my $account = $rh->equity_account_by_account_number($id);
Returns a Finance::Robinhood::Equity::Account object. You need to be logged in for this to work.
Returns the Finance::Robinhood::Equity::Account::Portfolio object related to your primary equity account. You need to be logged in for this to work.
my $equity_portfolios = $rh->equity_portfolios();
An iterator containing Finance::Robinhood::Equity::Account::Portfolio objects is returned. You need to be logged in for this to work.
my $watchlist = $rh->equity_watchlist;
Returns the default Finance::Robinhood::Equity::Watchlist object. You need to be logged in for this to work.
my $watchlists = $rh->equity_watchlists();
An iterator containing Finance::Robinhood::Equity::Watchlist objects is returned. You need to be logged in for this to work.
my $watchlist = $rh->equity_watchlist_by_name('Default');
Returns a Finance::Robinhood::Equity::Watchlist object. You need to be logged in for this to work.
my $fundamentals = $rh->equity_fundamentals('MSFT', 'TSLA');
An iterator containing Finance::Robinhood::Equity::Fundamentals objects is returned.
You do not need to be logged in for this to work.
my $markets = $rh->equity_markets()->all;
Returns an iterator containing Finance::Robinhood::Equity::Market objects.
my $markets = $rh->equity_market_by_mic('XNAS'); # NASDAQ
Locates an exchange by its Market Identifier Code and returns a Finance::Robinhood::Equity::Market object.
See also https://en.wikipedia.org/wiki/Market\_Identifier\_Code
my $instruments = $rh->top_movers( );
Returns an iterator containing members of the S&P 500 with large price changes during market hours as Finance::Robinhood::Equity::Movers objects.
You may define whether or not you want the best or worst performing instruments with the following option:
-
direction
-up
ordown
$rh->top_movers( direction => 'up' );
Returns the best performing members. This is the default.
$rh->top_movers( direction => 'down' );
Returns the worst performing members.
my $tags = $rh->collections( 'food', 'oil' );
Returns a list of Finance::Robinhood::Equity::Collection objects.
my $tags = $rh->discover_collections( );
Returns an iterator containing Finance::Robinhood::Equity::Collection objects.
my $tags = $rh->popular_collections( );
Returns an iterator containing Finance::Robinhood::Equity::Collection objects.
my $tag = $rh->collection('food');
Locates a collection by its slug and returns a Finance::Robinhood::Equity::Collection object.
my $chains = $rh->options;
Returns an iterator containing chain elements.
$rh->options($rh->equity('MSFT'))->all;
You may limit the call by passing a list of Finance::Robinhood::Equity or Finance::Robinhood::Options::Contract objects.
my $options = $rh->options_contracts();
Returns an iterator containing Finance::Robinhood::Options::Contract objects.
my $options = $rh->options_contracts( state => 'active', type => 'put' );
You can filter the results several ways. All of them are optional.
state
-active
,inactive
, orexpired
type
-call
orput
expiration_dates
- list of days; format is YYYY-M-DDids
- list of contract IDstradability
- eithertradable
oruntradable
chain_id
- the options chain idstate
-active
,inactive
, orexpired
my $positions = $rh->options_positions( );
Returns the related paginated list object filled with Finance::Robinhood::Options::Position objects.
You must be logged in.
my $positions = $rh->options_positions( nonzero => 1 );
You can filter and modify the results. All options are optional.
nonzero
- true or false. Default is falsechains
- list of options chain IDs or Finance::Robinhood::Options objects
my $position = $rh->options_position_by_id('b5ad00c0-7861-4582-8e5e-48f635178cb9');
Searches for a single of options position by its id and returns a Finance::Robinhood::Options::Position object.
$rh->options_contract_by_id('3b8f5513-600f-49b8-a4de-db56b52a82cf');
Searches for a single of options instrument by its instrument id and returns a Finance::Robinhood::Options::Contract object.
my $chain = $rh->options_by_id('55d7e31c-9105-488b-983c-93e09dd7ff35');
Searches for a single of options chain by its id and returns a Finance::Robinhood::Options object.
my $events = $rh->options_events();
Returns an iterator containing Finance::Robinhood::Options::Event objects.
my $orders = $rh->options_orders();
An iterator containing Finance::Robinhood::Options::Order objects is returned. You need to be logged in for this to work.
my $orders = $rh->options_orders(contract => $msft_call_130_Jun_2020);
If you would only like orders after a certain date, you can do that!
my $orders = $rh->options_orders(after => Time::Moment->now->minus_days(7));
# Also accepts ISO 8601
If you would only like orders before a certain date, you can do that!
my $orders = $rh->options_orders(before => Time::Moment->now->minus_years(2));
# Also accepts ISO 8601
my $order = $rh->options_order_by_id($id);
Returns a Finance::Robinhood::Options::Order object. You need to be logged in for this to work.
my $me = $rh->user();
Returns a Finance::Robinhood::User object. You need to be logged in for this to work.
Depending on your jurisdiction, your account may have access to Robinhood Crypto. See https://crypto.robinhood.com/ for more.
my $acct = $rh->currency_account;
Returns a Finance::Robinhood::Currency::Account object.
You need to be logged in and have access to Robinhood Crypto for this to work.
my $accts = $rh->currency_accounts;
Returns an iterator full of Finance::Robinhood::Currency::Account objects.
You need to be logged in and have access to Robinhood Crypto for this to work.
my $account = $rh->currency_account_by_id($id);
Returns a hash reference. You need to be logged in for this to work.
my $halts = $rh->currency_halts;
# or
$halts = $rh->currency_halts( active => 1 );
Returns an iterator full of Finance::Robinhood::Currency::Halt objects.
If you pass a true value to a key named active
, only active halts will be
returned.
You need to be logged in and have access to Robinhood Crypto for this to work.
my $halts = $rh->currency_halt_by_id( '6a2a026a-e391-43cf-aadf-25826ea5432b' );
Returns an Finance::Robinhood::Currency::Halt object if a halt with this ID exits.
If you pass a true value to a key named active
, only active halts will be
returned.
You need to be logged in and have access to Robinhood Crypto for this to work.
my $currecies = $rh->currencies();
An iterator containing Finance::Robinhood::Forex::Currency objects is returned. You need to be logged in for this to work.
my $currency = $rh->currency_by_id($id);
Returns a Finance::Robinhood::Currency object. You need to be logged in for this to work.
my $pairs = $rh->currency_pairs( );
An iterator containing Finance::Robinhood::Currency::Pair objects is returned. You need to be logged in for this to work.
my $watchlist = $rh->currency_pair_by_id($id);
Returns a Finance::Robinhood::Currency::Pair object. You need to be logged in for this to work.
my $bitcoin = $rh->currency_pair_by_name('Bitcoin');
$bitcoin = $rh->currency_pair_by_name('BTC');
Returns a Finance::Robinhood::Currency::Pair object. You need to be logged in for this to work.
my $watchlists = $rh->currency_watchlists();
Returns an iterator containing Finance::Robinhood::Currency::Watchlist objects.
You need to be logged in for this to work.
my $watchlist = $rh->currency_watchlist_by_id($id);
Returns a Finance::Robinhood::Currency::Watchlist object.
my $activations = $rh->currency_activations();
Returns an iterator containing Finance::Robinhood::Currency::Activation objects.
my $activation = $rh->currency_activation_by_id($id);
Returns a Finance::Robinhood::Currency::Activation object.
my $portfolios = $rh->currency_portfolios();
Returns an iterator containing Finance::Robinhood::Currency::Portfolio objects.
You need to be logged in for this to work.
my $portfolio = $rh->currency_portfolio_by_id($id);
Returns a Finance::Robinhood::Currency::Portfolio object.
You need to be logged in for this to work.
my $activation = $rh->new_currency_application( type => 'new_account' );
Submits an application to activate a new cryptocurrency account. You need to be logged in for this to work.
The following options are accepted:
-
type
This is required and must be one of the following:
new_account
reactivation
-
speculative
This is an optional boolean value.
my $orders = $rh->currency_orders( );
An iterator containing Finance::Robinhood::Forex::Order objects is returned. You need to be logged in for this to work.
my $order = $rh->forex_order_by_id($id);
Returns a Finance::Robinhood::Currency::Order object. You need to be logged in for this to work.
my $holdings = $rh->currency_positions( );
Returns an iterator filled with Finance::Robinhood::Currency::Position objects.
You must be logged in.
my $holding = $rh->currency_position_by_id($id);
Returns a Finance::Robinhood::Currency::Position object.
You need to be logged in for this to work.
Move money in and out of your brokerage account.
At some point, you might need to move assets from one firm to another.
my $acats = $rh->acats_transfers();
An iterator containing Finance::Robinhood::ACATS::Transfer objects is returned.
You need to be logged in for this to work.
my $done = $rh->request_acats_transfer(
account => $rh->equity_account,
)
Request an ACATS transfer. You may pass the following options:
account
- Finance::Robinhood::Equity::Account object (optional; defaults toequity_account( )
)contra_account_number
- Account number at the other end of the transfer (required)contra_account_title
- String used to identify the account in UI (optional)contra_brokerage_name
- String used to identify the other firm (optional)contra_correspondent_number
- String used (required)
@retrofit2.http.GET("inbox/threads/{threadId}/")
io.reactivex.Single<com.robinhood.models.api.ApiThread> getThread(@retrofit2.http.Path("threadId") java.lang.String str);
@retrofit2.http.GET("inbox/threads/{threadId}/messages/")
io.reactivex.Single<com.robinhood.models.api.ApiMessageResult> getThreadMessages(@retrofit2.http.Path("threadId") java.lang.String str, @retrofit2.http.Query("before") java.lang.String str2, @retrofit2.http.Query("after") java.lang.String str3);
@retrofit2.http.GET("inbox/settings/thread/{threadId}/")
io.reactivex.Single<com.robinhood.models.api.ApiNotificationThreadSettingsItem> getThreadNotificationSettingsV4(@retrofit2.http.Path("threadId") java.lang.String str);
@retrofit2.http.GET("inbox/settings/{threadId}/")
io.reactivex.Single<com.robinhood.models.api.ApiNotificationSettingsV3> getThreadSettings(@retrofit2.http.Path("threadId") java.lang.String str);
@retrofit2.http.GET("inbox/threads/")
io.reactivex.Single<com.robinhood.models.PaginatedResult<com.robinhood.models.api.ApiThread>> getThreads();
Returns an iterator filled with Finance::Robinhood::Cash
objects.
Returns the related Finance::Robinhood::Cash object.
Returns an iterator filled with Finance::Robinhood::Cash::ATM objects.
$latitude
and $longitude
coordinates must be in decimal degrees.
$rh->atm_by_id('2fb3fac0-96ef-4154-830f-21d4b8affbca');
Returns a Finance::Robinhood::Cash::ATM object.
Returns a hash reference with two keys: cash_in
and cash_out
. They both
contain these keys:
amount
- This is a dollar amount.currency_code
- Currency type (USD
)currency_id
- UUID
Returns an iterator filled with Finance::Robinhood::Cash::Card
objects.
Returns a Finance::Robinhood::Cash::Card
object.
This is a simple wrapper around the API used in the official apps. The author provides no investment, legal, or tax advice and is not responsible for any damages incurred while using this software. This software is not affiliated with Robinhood Financial LLC in any way.
For Robinhood's terms and disclosures, please see their website at https://robinhood.com/legal/
Copyright (C) Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted through this module. Please refer to the LEGAL section.
Sanko Robinson [email protected]