public class RobinhoodApi
extends java.lang.Object
RobinhoodApi
instance is used as an intermediary between the
Robinhood servers and your java/kotlin/whatever application.
Configuration
Configuration
which contains
information about account tokens and urls (if the API has been logged
in).Modifier and Type | Field and Description |
---|---|
static java.util.logging.Logger |
log
The Logger object used for the custom error handling
|
Constructor and Description |
---|
RobinhoodApi()
Constructor which creates all of the access points to use the API.
|
RobinhoodApi(java.lang.String username,
java.lang.String password)
Constructor which creates all of the access points to use the API.
|
Modifier and Type | Method and Description |
---|---|
<E extends ApiElement> |
buildIterable(ApiElementList<E> elementList)
Build an
Iterable based off a PaginatedIterator . |
SecurityOrder |
cancelOrder(SecurityOrder order)
Deprecated.
|
Account |
getAccountData()
Method returning a
Account using the currently logged in
user |
AccountHolderAffiliation |
getAccountHolderAffiliation()
Method returning a
AccountHolderAffiliation for the currently
logged in user |
AccountHolderEmployment |
getAccountHolderEmployment()
Method returning a
AccountHolderEmployment for the currently
logged in user |
BasicAccountHolderInfo |
getAccountHolderInfo()
Method returning a
BasicAccountHolderInfo for the currently logged
in user |
AccountHolderInvestmentProfile |
getAccountInvestmentProfile()
Method returning a
AccountHolderInvestmentProfile for the
currently logged in user |
java.util.List<Position> |
getAccountPositions()
Method which gets all of the account positions a user actually has shares in.
|
java.util.List<Position> |
getAccountWatchlist()
Returns a list of
Position for each entry on the account's
watchlist. |
java.util.List<Instrument> |
getAllInstruments()
Get's every
Instrument tracked by Robinhood. |
BasicUserInfo |
getBasicUserInfo()
Method returning a
BasicUserInfo for the currently logged in user |
InstrumentCollectionList |
getCollectionData(java.lang.String collectionName)
Gets the collection data from Robinhood based on the given Collection
Name.
|
Configuration |
getConfig() |
TickerFundamental |
getFundamental(java.lang.String ticker)
Method returning a
TickerFundamental for the supplied ticker name |
java.util.List<TickerFundamental> |
getFundamentalList(java.util.Collection<java.lang.String> tickers)
Get a
List of TickerFundamental . |
Instrument |
getInstrumentByTicker(java.lang.String ticker) |
java.util.List<Instrument> |
getInstrumentsByKeyword(java.lang.String keyword)
Gets a list of instruments by searching with the given keyword.
|
java.util.List<Option> |
getOptions()
TODO DOCS
|
java.util.List<SecurityOrder> |
getOrders() |
TickerQuote |
getQuoteByTicker(java.lang.String ticker)
Method returning a
TickerQuote for the supplied ticker. |
java.util.List<TickerQuote> |
getQuoteListByTickers(java.util.Collection<java.lang.String> tickers)
Get a list of security quotes by their tickers.
|
RatingList |
getRatingsByInstrumentIds(java.lang.String... ids)
Gets the ratings by instrument ids.
|
RatingList |
getRatingsByTickers(java.lang.String... tickers)
Gets the ratings by tickers.
|
boolean |
isLoggedIn() |
AuthorizationData |
loadAuthData(java.lang.String email,
java.lang.String password)
Request
AuthorizationData from Robinhood and adds it to the
Configuration . |
LoginStatus |
login(java.lang.String email,
java.lang.String password)
Method which logs a user in given a email and password.
|
LoginStatus |
login(java.lang.String email,
java.lang.String password,
boolean clean)
Method which logs a user in given a email and password.
|
LoginStatus |
loginMfa(java.lang.String email,
java.lang.String password,
java.lang.String code)
Login with a Multifactor/Two-factor authorization code.
|
LoginStatus |
logUserOut()
Method which forces the authorization token to expire, logging the user
out if the user is currently logged in.
|
SecurityOrder |
makeLimitOrder(java.lang.String ticker,
TimeInForce timeInForce,
float limitPrice,
int quantity,
OrderTransactionType orderType)
Method which returns a
SecurityOrder after running a LIMIT order
given the supplied parameters. |
SecurityOrder |
makeLimitStopOrder(java.lang.String ticker,
TimeInForce timeInForce,
float limitPrice,
int quantity,
OrderTransactionType orderType,
float stopPrice) |
SecurityOrder |
makeMarketOrder(java.lang.String ticker,
int quantity,
OrderTransactionType orderType,
TimeInForce time) |
SecurityOrder |
makeMarketStopOrder(java.lang.String ticker,
int quantity,
OrderTransactionType orderType,
TimeInForce time,
float stopPrice) |
void |
setAuthToken(java.lang.String token)
Deprecated.
|
public static final java.util.logging.Logger log
public RobinhoodApi()
public RobinhoodApi(java.lang.String username, java.lang.String password) throws RobinhoodApiException
AuthorizationData
will be stored in the Configuration
instance to be retrieved elsewhere. On failure, an error will be thrown.
username
- The user's email (that they use with robinhood)password
- The user's passwordRobinhoodApiException
- If the login failedpublic AuthorizationData loadAuthData(java.lang.String email, java.lang.String password)
AuthorizationData
from Robinhood and adds it to the
Configuration
. If MFA is not required, this will save the Token
and account number into the config (just like
login(String, String)
).email
- The email to login withpassword
- The passwordAuthorizationData
returned or null if failed.
This will wither contain a token or multifactor details.public LoginStatus login(java.lang.String email, java.lang.String password)
email
- The user's emailpassword
- The user's passwordLoginStatus.FAILURE
if the user could not be logged in.
LoginStatus.SUCCESS
otherwisepublic LoginStatus login(java.lang.String email, java.lang.String password, boolean clean)
email
- The emailpassword
- The passwordclean
- Whether to re-load the previous AuthorizationData
LoginStatus.FAILURE
if the user could not be logged in.
LoginStatus.SUCCESS
otherwisepublic LoginStatus loginMfa(java.lang.String email, java.lang.String password, java.lang.String code)
Configuration's
AuthorizationData
to be set with loadAuthData(String, String)
email
- The user's emailpassword
- The user's passwordcode
- The mfa codeLoginStatus.FAILURE
if the user could not be logged in.
LoginStatus.SUCCESS
otherwisepublic LoginStatus logUserOut()
public Account getAccountData()
Account
using the currently logged in
userAccount
NotLoggedInException
- if the user is not logged inpublic BasicUserInfo getBasicUserInfo()
BasicUserInfo
for the currently logged in userNotLoggedInException
- if the user is not logged inpublic BasicAccountHolderInfo getAccountHolderInfo()
BasicAccountHolderInfo
for the currently logged
in userBasicAccountHolderInfo
NotLoggedInException
- if the user is not logged inpublic AccountHolderAffiliation getAccountHolderAffiliation()
AccountHolderAffiliation
for the currently
logged in userAccountHolderAffiliation
NotLoggedInException
- if the user is not logged inpublic AccountHolderEmployment getAccountHolderEmployment()
AccountHolderEmployment
for the currently
logged in userAccountHolderEmployment
NotLoggedInException
- if the user is not logged inpublic AccountHolderInvestmentProfile getAccountInvestmentProfile()
AccountHolderInvestmentProfile
for the
currently logged in userNotLoggedInException
- if the user is not logged inpublic java.util.List<Position> getAccountWatchlist()
Position
for each entry on the account's
watchlist. If the quantity of the Position
is above 0,
that means that you have an active position in that stock.Position
, both held and only watched entitiesNotLoggedInException
- If not logged inpublic java.util.List<Position> getAccountPositions()
NotLoggedInException
- If not logged inpublic java.util.List<SecurityOrder> getOrders()
NotLoggedInException
- If not logged inpublic SecurityOrder makeLimitOrder(java.lang.String ticker, TimeInForce timeInForce, float limitPrice, int quantity, OrderTransactionType orderType) throws TickerNotFoundException
SecurityOrder
after running a LIMIT order
given the supplied parameters.ticker
- The ticker which the buy or sell order should be performed ontimeInForce
- The Enum representation for when this order should be madelimitPrice
- The price you're willing to accept in a sell, or pay in a buyquantity
- The number of shares you would like to buy or sellorderType
- Which type of order is being made. A buy, or sell.SecurityOrder
that was madeTickerNotFoundException
- Thrown when the ticker supplied to the
method is invalid.NotLoggedInException
- Thrown when this Robinhood Api instance is
not logged into an account. Run the login method first.public SecurityOrder makeLimitStopOrder(java.lang.String ticker, TimeInForce timeInForce, float limitPrice, int quantity, OrderTransactionType orderType, float stopPrice) throws TickerNotFoundException
ticker
- The ticker which the buy or sell order should be performed ontimeInForce
- The Enum representation for when this order should be madelimitPrice
- The price you're willing to accept in a sell, or pay in a buyquantity
- The number of shares you would like to buy or sellorderType
- Which type of order is being made. A buy, or a sellstopPrice
- The price at which the stop trigger converts the order
into a market orderSecurityOrder
TickerNotFoundException
- The ticker supplied is not valid.public SecurityOrder makeMarketOrder(java.lang.String ticker, int quantity, OrderTransactionType orderType, TimeInForce time) throws TickerNotFoundException
ticker
- What ticker you are performing this order onquantity
- How many shares should be transactedorderType
- Which type of order is being made. A buy, or a sell.time
- The Enum representation of when this order should be made.TickerNotFoundException
- if the ticker supplied was invalidNotLoggedInException
- if instance not logged inpublic SecurityOrder makeMarketStopOrder(java.lang.String ticker, int quantity, OrderTransactionType orderType, TimeInForce time, float stopPrice) throws TickerNotFoundException
ticker
- The stock tickerquantity
- The number of elements to orderorderType
- OrderTransactionType.BUY
or OrderTransactionType.SELL
time
- The time and/or duration an order will be active.stopPrice
- The stop (activation) priceSecurityOrder
created, this order can fail
(SecurityOrder.reject_reason
TickerNotFoundException
- If the ticker is not tracked by RHNotLoggedInException
- If instance is not logged in@Deprecated public SecurityOrder cancelOrder(SecurityOrder order) throws RobinhoodApiException
order
- The SecurityOrder
to cancelSecurityOrder
RobinhoodApiException
- If the order could not be cancelledpublic java.util.List<Option> getOptions()
NotLoggedInException
- If the instance is not logged inpublic TickerFundamental getFundamental(java.lang.String ticker)
TickerFundamental
for the supplied ticker nameticker
- The Stock's tickerTickerFundamental
public java.util.List<TickerFundamental> getFundamentalList(java.util.Collection<java.lang.String> tickers) throws RequestTooLargeException
List
of TickerFundamental
.tickers
- A collection of stock tickersList
of TickerFundamental
.RequestTooLargeException
- If the Collection is longer than 10public TickerQuote getQuoteByTicker(java.lang.String ticker) throws TickerNotFoundException
TickerQuote
for the supplied ticker.
Contains general information, such as the current asking price and the
last trading price. Does not require the API to be logged on.ticker
- Which symbol you are retrieving a quote forTickerQuote
TickerNotFoundException
- If the quote is not foundpublic java.util.List<TickerQuote> getQuoteListByTickers(java.util.Collection<java.lang.String> tickers) throws RequestTooLargeException
tickers
- The tickers to get quotes of (e.g. MSFT, FIT)TickerQuoteElements
.
A value in the list may be null if the ticker was not found
on Robinhood.RequestTooLargeException
- if the collection is longer than 1,630public Instrument getInstrumentByTicker(java.lang.String ticker) throws TickerNotFoundException
ticker
- The stock tickerInstrument
requestedTickerNotFoundException
- If the ticker is not tracked by Robinhoodpublic java.util.List<Instrument> getInstrumentsByKeyword(java.lang.String keyword)
keyword
- The keyword to search withList
of InstrumentElements
returned by Robinhood's searchpublic java.util.List<Instrument> getAllInstruments()
Instrument
tracked by Robinhood.
This method performs several calls to the Robinhood servers and is
therefore rather expensive to use. Try to use it sparingly (it's not
like it's going to be changing all the time)Instrument
tracked by Robinhoodpublic InstrumentCollectionList getCollectionData(java.lang.String collectionName)
collectionName
- the collection nameInstrument
.public RatingList getRatingsByTickers(java.lang.String... tickers) throws RequestTooLargeException
tickers
- the tickersRequestTooLargeException
- if request is greater than
ApiMethod.MAX_TICKERS
public RatingList getRatingsByInstrumentIds(java.lang.String... ids)
ids
- the tickerspublic <E extends ApiElement> java.lang.Iterable<E> buildIterable(ApiElementList<E> elementList)
Iterable
based off a PaginatedIterator
.E
- The ApiElement of the ListelementList
- The ApiElementList
build frompublic boolean isLoggedIn()
true
if the API has been logged inpublic Configuration getConfig()
Configuration
@Deprecated public void setAuthToken(java.lang.String token)
token
- The new token