Client

All communication with the Robinhood servers is done through the RobinhoodClient.

class RobinhoodClient(timeout, session=None, session_file='.aiorobinhood.pickle')

An HTTP client for interacting with Robinhood.

By default, the device token is saved to the session_file in order to avoid re-triggering the SFA challenge flow upon every login(). With MFA, a passcode will need to be manually supplied every time.

The access and refresh tokens for a particular session can be saved and reloaded to the same file using the dump() and load() methods, respectively.

Parameters
  • timeout (int) – The request timeout, in seconds.

  • session (Optional[ClientSession]) – An open client session to inject, if possible.

  • session_file (str) – A path to a binary file for saving session variables.

Authentication

async RobinhoodClient.login(username, password, expires_in=86400, challenge_type=<ChallengeType.SMS: 'sms'>, **kwargs)

Authenticate the user (for both SFA and MFA accounts).

Parameters
  • username (str) – The account username.

  • password (str) – The account password.

  • expires_in (int) – The session duration, in seconds.

  • challenge_type (ChallengeType) – The challenge type (SFA only).

Raises
Return type

None

async RobinhoodClient.logout()

Invalidate the current session tokens.

Raises
Return type

None

async RobinhoodClient.refresh(expires_in=86400)

Fetch a fresh set session tokens.

Parameters

expires_in (int) – The session duration, in seconds.

Raises
Return type

None

async RobinhoodClient.dump()

Write the session tokens to the session file.

Raises

ClientUnauthenticatedError – The RobinhoodClient is not logged in.

Return type

None

async RobinhoodClient.load()

Read the session tokens from the session file.

Raises
Return type

None

Profile

async RobinhoodClient.get_account()

Fetch information associated with the Robinhood account.

Return type

Dict[str, Any]

Returns

The account information.

Raises
async RobinhoodClient.get_portfolio()

Fetch the portfolio information associated with the Robinhood account.

Return type

Dict[str, Any]

Returns

The account’s portfolio characteristics including equity value, margin, and withdrawable amount.

Raises
async RobinhoodClient.get_historical_portfolio(interval, span, extended_hours=False)

Fetch the historical value of the account portfolio.

Parameters
  • interval (HistoricalInterval) – The granularity of the historical data.

  • span (HistoricalSpan) – The period of the historical data.

  • extended_hours (bool) – Include data from extended trading hours.

Return type

Dict[str, Any]

Returns

Historical equity values of the account portfolio over the given interval and span.

Raises

Warning

Certain combinations of interval and span will be rejected by Robinhood.

Account

async RobinhoodClient.get_positions(nonzero=True, pages=None)

Fetch all the positions held by the account.

Parameters
  • nonzero (bool) – Only fetch open positions.

  • pages (Optional[int]) – The number of pages to fetch (default is unlimited).

Return type

List[Dict[str, Any]]

Returns

Position data for each holding, including quantity of shares held and average buy price.

Raises
async RobinhoodClient.get_watchlist(watchlist='Default', pages=None)

Fetch the securities in a given watchlist.

Parameters
  • watchlist (str) – The name of the watclist.

  • pages (Optional[int]) – The number of pages to fetch (default is unlimited).

Return type

List[str]

Returns

A list of instrument URLs in the watchlist.

Raises
async RobinhoodClient.add_to_watchlist(instrument, watchlist='Default')

Add a security to the given watchlist.

Parameters
  • instrument (str) – The instrument URL.

  • watchlist (str) – The name of the watchlist.

Raises
Return type

None

async RobinhoodClient.remove_from_watchlist(id_, watchlist='Default')

Remove a security from the given watchlist.

Parameters
  • id – The instrument ID.

  • watchlist (str) – The name of the watchlist.

Raises
Return type

None

Stocks

async RobinhoodClient.get_fundamentals(symbols=None, instruments=None)

Fetch the fundamental information pertaining to a list of securities.

Parameters
Return type

List[Dict[str, Any]]

Returns

Fundamental data for each security, including most recent OHLC prices, market capitalization, P/E and P/B ratios, etc.

Raises
async RobinhoodClient.get_instruments(symbol=None, ids=None, pages=None)

Fetch the instrument information pertaining to a list of securities.

Parameters
Return type

List[Dict[str, Any]]

Returns

Instrument data for each security, including ID and various URLs for fetching particular information.

Raises
async RobinhoodClient.get_quotes(symbols=None, instruments=None)

Fetch the quote information pertaining to a list of securities.

Parameters
Return type

List[Dict[str, Any]]

Returns

Quote data for each security, including ask/bid pricing data (both during regular and extended trading hours).

Raises
async RobinhoodClient.get_historical_quotes(interval, span, extended_hours=False, symbols=None, instruments=None)

Fetch historical quote information pertaining to a list of securities.

Parameters
Return type

List[Dict[str, Any]]

Returns

Historical quote data for each security, including OHLC pricing data at every interval in the given span.

Raises

Warning

Certain combinations of interval and span will be rejected by Robinhood.

async RobinhoodClient.get_tags(id_)

Fetch the tags for a particular security.

Parameters

id – An instrument ID.

Return type

List[str]

Returns

A list of Robinhood tags for the given security.

Raises
async RobinhoodClient.get_tag_members(tag)

Fetch the instruments belonging to a particular tag.

Parameters

tag (str) – The tag name.

Return type

List[str]

Returns

A list of instruments that match the given tag.

Raises

Orders

async RobinhoodClient.get_orders(order_id=None, pages=None)

Fetch historical order information.

Parameters
  • order_id (Optional[str]) – The ID of a particular order.

  • pages (Optional[int]) – The number of pages to fetch (default is unlimited).

Return type

List[Dict[str, Any]]

Returns

Order information for a particular order ID, or every order placed on the Robinhood account. Order information includes the price, type, and status of the order.

Raises
async RobinhoodClient.cancel_order(order_id)

Cancel an order.

Parameters

order_id (str) – The ID of a particular order.

Raises
Return type

None

Placing Orders

Warning

Robinhood rate limits the /orders endpoint used by the following methods.

async RobinhoodClient.place_limit_buy_order(symbol, price, quantity, time_in_force=<OrderTimeInForce.GFD: 'gfd'>, extended_hours=False)

Place a limit buy order.

Parameters
  • symbol (str) – A stock symbol.

  • price (Union[int, float]) – The limit price, in dollars.

  • quantity (int) – The quantity of shares to buy.

  • time_in_force (OrderTimeInForce) – Indicates how long the order should remain active before it executes or expires.

  • extended_hours (bool) – The order can be executed in extended trading hours.

Return type

str

Returns

The order ID.

Raises
async RobinhoodClient.place_limit_sell_order(symbol, price, quantity, time_in_force=<OrderTimeInForce.GFD: 'gfd'>, extended_hours=False)

Place a limit sell order.

Parameters
  • symbol (str) – A stock symbol.

  • price (Union[int, float]) – The limit price, in dollars.

  • quantity (int) – The quantity of shares to sell.

  • time_in_force (OrderTimeInForce) – Indicates how long the order should remain active before it executes or expires.

  • extended_hours (bool) – The order can be executed in extended trading hours.

Return type

str

Returns

The order ID.

Raises
async RobinhoodClient.place_market_buy_order(symbol, amount=None, quantity=None, time_in_force=<OrderTimeInForce.GFD: 'gfd'>, extended_hours=False)

Place a market buy order by quantity of shares or dollar amount.

Parameters
  • symbol (str) – A stock symbol.

  • amount (Union[int, float, None]) – The amount to buy, in dollars.

  • quantity (Union[int, float, None]) – The quantity of shares to buy.

  • time_in_force (OrderTimeInForce) – Indicates how long the order should remain active before it executes or expires.

  • extended_hours (bool) – The order can be executed in extended trading hours.

Return type

str

Returns

The order ID.

Raises
async RobinhoodClient.place_market_sell_order(symbol, amount=None, quantity=None, time_in_force=<OrderTimeInForce.GFD: 'gfd'>, extended_hours=False)

Place a market sell order by quantity of shares or dollar amount.

Parameters
  • symbol (str) – A stock symbol.

  • amount (Union[int, float, None]) – The amount to sell, in dollars.

  • quantity (Union[int, float, None]) – The quantity of shares to sell.

  • time_in_force (OrderTimeInForce) – Indicates how long the order should remain active before it executes or expires.

  • extended_hours (bool) – The order can be executed in extended trading hours.

Return type

str

Returns

The order ID.

Raises
async RobinhoodClient.place_stop_buy_order(symbol, price, quantity, time_in_force=<OrderTimeInForce.GFD: 'gfd'>, extended_hours=False)

Place a stop buy order.

Parameters
  • symbol (str) – A stock symbol.

  • price (Union[int, float]) – The stop price, in dollars.

  • quantity (int) – The quantity of shares to buy.

  • time_in_force (OrderTimeInForce) – Indicates how long the order should remain active before it executes or expires.

  • extended_hours (bool) – The order can be executed in extended trading hours.

Return type

str

Returns

The order ID.

Raises
async RobinhoodClient.place_stop_sell_order(symbol, price, quantity, time_in_force=<OrderTimeInForce.GFD: 'gfd'>, extended_hours=False)

Place a stop sell order.

Parameters
  • symbol (str) – A stock symbol.

  • price (Union[int, float]) – The stop price, in dollars.

  • quantity (int) – The quantity of shares to sell.

  • time_in_force (OrderTimeInForce) – Indicates how long the order should remain active before it executes or expires.

  • extended_hours (bool) – The order can be executed in extended trading hours.

Return type

str

Returns

The order ID.

Raises
async RobinhoodClient.place_stop_limit_buy_order(symbol, price, quantity, stop_price, time_in_force=<OrderTimeInForce.GFD: 'gfd'>, extended_hours=False)

Place a limit buy order triggered at a given stop price.

Parameters
  • symbol (str) – A stock symbol.

  • price (Union[int, float]) – The limit price, in dollars.

  • quantity (int) – The quantity of shares to buy.

  • stop_price (Union[int, float]) – The stop price at which to place the limit order, in dollars.

  • time_in_force (OrderTimeInForce) – Indicates how long the order should remain active before it executes or expires.

  • extended_hours (bool) – The order can be executed in extended trading hours.

Return type

str

Returns

The order ID.

Raises
async RobinhoodClient.place_stop_limit_sell_order(symbol, price, quantity, stop_price, time_in_force=<OrderTimeInForce.GFD: 'gfd'>, extended_hours=False)

Place a limit sell order triggered at a given stop price.

Parameters
  • symbol (str) – A stock symbol.

  • price (Union[int, float]) – The limit price, in dollars.

  • quantity (int) – The quantity of shares to sell.

  • stop_price (Union[int, float]) – The stop price at which to place the limit order, in dollars.

  • time_in_force (OrderTimeInForce) – Indicates how long the order should remain active before it executes or expires.

  • extended_hours (bool) – The order can be executed in extended trading hours.

Return type

str

Returns

The order ID.

Raises