pyrh.Robinhood

class pyrh.Robinhood(username, password, challenge_type='email', headers=None, proxies=None, **kwargs)

Wrapper class for fetching/parsing Robinhood endpoints.

Please see SessionManager for login functionality.

Provides a global convenience wrapper for the following manager objects:

  • InstrumentManager

  • TODO: Add to this list

__init__(username, password, challenge_type='email', headers=None, proxies=None, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

Return type

None

Methods

__init__(username, password[, …])

Initialize self.

adjusted_previous_close([stock])

Get adjusted previous closing price for a stock.

ask_price([stock])

Get asking price for a stock.

ask_size([stock])

Get ask size for a stock.

bid_price([stock])

Get bid price for a stock.

bid_size([stock])

Get bid size for a stock.

cancel_order(order_id)

Cancels specified order and returns the response.

dividends()

Wrapper for portfolios

fundamentals([stock])

Wrapper for get_fundamentlals function

get(url[, params, headers, raise_errors, …])

Run a wrapped session HTTP GET request.

get_account()

Fetch account information.

get_fundamentals([stock])

Find stock fundamentals data

get_historical_quotes(stock, interval, span)

get_news(stock)

Fetch news endpoint.

get_open_orders()

Returns all currently open (cancellable) orders.

get_option_chainid(symbol)

get_option_marketdata(instrument)

get_option_quote(arg_dict)

get_options(stock, expiration_dates, option_type)

Get a list (chain) of options contracts belonging to a particular stock

get_popularity([stock])

Get the number of robinhood users who own the given stock

get_quote([stock])

Wrapper for quote_data.

get_quote_list([stock, key])

Returns multiple stock info and keys from quote_data (prompt if blank)

get_stock_marketdata(instruments)

get_tickers_by_tag([tag])

Get a list of instruments belonging to a tag

get_url(url)

Flat wrapper for fetching URL directly/

instrument([symbol, id_])

Get a single instrument using a provided query parameter.

instruments([query])

Get a generator of instruments.

investment_profile()

Fetch investment_profile.

last_trade_price([stock])

Get last trade price for a stock

last_updated_at([stock])

Get last update datetime.

last_updated_at_datetime([stock])

Get last updated datetime.

login([force_refresh])

Login to the session.

logout()

Logout from the session.

options_owned()

order_history([orderId])

Wrapper for portfolios

place_buy_order(instrument, quantity[, …])

Wrapper for placing buy orders

place_limit_buy_order([instrument_URL, …])

Wrapper for placing limit buy orders

place_limit_sell_order([instrument_URL, …])

Wrapper for placing limit sell orders

place_market_buy_order([instrument_URL, …])

Wrapper for placing market buy orders

place_market_sell_order([instrument_URL, …])

Wrapper for placing market sell orders

place_order(instrument[, quantity, price, …])

Place an order with Robinhood

place_sell_order(instrument, quantity[, …])

Wrapper for placing sell orders

place_stop_limit_buy_order([instrument_URL, …])

Wrapper for placing stop limit buy orders

place_stop_limit_sell_order([…])

Wrapper for placing stop limit sell orders

place_stop_loss_buy_order([instrument_URL, …])

Wrapper for placing stop loss buy orders

place_stop_loss_sell_order([instrument_URL, …])

Wrapper for placing stop loss sell orders

portfolio()

Returns the user’s portfolio data

positions()

Returns the user’s positions data

post(url[, data, headers, raise_errors, …])

Run a wrapped session HTTP POST request.

previous_close([stock])

Get previous closing price for a stock.

previous_close_date([stock])

Get previous closing date for a stock.

print_quote([stock])

Print quote information.

print_quotes(stocks)

Print a collection of stocks.

quote_data([stock])

Fetch stock quote.

quotes_data(stocks)

Fetch quote for multiple stocks, in one single Robinhood API call.

securities_owned()

Returns list of securities’ symbols that the user has shares in

submit_buy_order([instrument_URL, symbol, …])

Submits buy order to Robinhood

submit_sell_order([instrument_URL, symbol, …])

Submits order to Robinhood

symbol([stock])

Get symbol for a stock.

user()

Attributes

authenticated

Check if the session is authenticated.

login_set

Check if login info is properly configured.

token_expired

Check if the issued auth token has expired.

adjusted_previous_close(stock='')

Get adjusted previous closing price for a stock.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

adjusted previous closing price

Return type

(float)

ask_price(stock='')

Get asking price for a stock.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

ask price

Return type

(float)

ask_size(stock='')

Get ask size for a stock.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

ask size

Return type

(int)

bid_price(stock='')

Get bid price for a stock.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

bid price

Return type

(float)

bid_size(stock='')

Get bid size for a stock.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

bid size

Return type

(int)

cancel_order(order_id)

Cancels specified order and returns the response.

If order cannot be cancelled, None is returned. (results from orders command).

Parameters

order_id (str or dict) – Order ID string that is to be cancelled or open order dict returned from order get.

Returns

result from orders put command

Return type

(requests.request)

dividends()

Wrapper for portfolios

Returns

obj: dict): JSON dict from getting dividends

Return type

(

fundamentals(stock='')

Wrapper for get_fundamentlals function

get_account()

Fetch account information.

Returns

accounts endpoint payload

Return type

(dict)

get_fundamentals(stock='')

Find stock fundamentals data

Parameters

(str) – stock ticker

Returns

contents of fundamentals endpoint

Return type

(dict)

get_news(stock)

Fetch news endpoint.

Parameters

stock (str) – stock ticker

Returns

(dict) values returned from news endpoint

get_open_orders()

Returns all currently open (cancellable) orders.

If not orders are currently open, None is returned.

TODO: Is there a way to get these from the API endpoint without stepping through

order history?

get_options(stock, expiration_dates, option_type)

Get a list (chain) of options contracts belonging to a particular stock

Args: stock ticker (str), list of expiration dates to filter on

(YYYY-MM-DD), and whether or not its a ‘put’ or a ‘call’ option type (str).

Returns

a list (chain) of contracts for a given underlying equity instrument

Return type

Options Contracts (List)

get_popularity(stock='')

Get the number of robinhood users who own the given stock

Parameters

stock (str) – stock ticker

Returns

number of users who own the stock

Return type

(int)

get_quote(stock='')

Wrapper for quote_data.

get_quote_list(stock='', key='')

Returns multiple stock info and keys from quote_data (prompt if blank)

Parameters
  • stock (str) – stock ticker (or tickers separated by a comma)

  • prompt if blank (,) –

  • key (str) – key attributes that the function should return

Returns

Returns values from each stock or empty list

if none of the stocks were valid

Return type

(list)

get_tickers_by_tag(tag=None)

Get a list of instruments belonging to a tag

Args: tag - Tags may include but are not limited to:
  • top-movers

  • etf

  • 100-most-popular

  • mutual-fund

  • finance

  • cap-weighted

  • investment-trust-or-fund

Returns

a list of Ticker strings

Return type

(List)

get_url(url)

Flat wrapper for fetching URL directly/

investment_profile()

Fetch investment_profile.

last_trade_price(stock='')

Get last trade price for a stock

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

last trade price

Return type

(float)

last_updated_at(stock='')

Get last update datetime.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

last update datetime

Return type

(str)

last_updated_at_datetime(stock='')

Get last updated datetime.

Note

queries quote endpoint, dict wrapper self.last_updated_at returns time as str in format: ‘YYYY-MM-ddTHH:mm:ss:000Z’

Parameters

stock (str) – stock ticker

Returns

last update datetime

Return type

(datetime)

order_history(orderId=None)

Wrapper for portfolios

Optional Args: add an order ID to retrieve information about a single order.

Returns

JSON dict from getting orders

Return type

(dict)

place_buy_order(instrument, quantity, ask_price=0.0)

Wrapper for placing buy orders

Parameters
  • instrument (dict) – the RH URL and symbol in dict for the instrument to be traded

  • quantity (int) – quantity of stocks in order

  • ask_price (float) – price for order (OPTIONAL! If not given, ask_price is automatic.)

Returns

result from orders put command

Return type

(requests.request)

place_limit_buy_order(instrument_URL=None, symbol=None, time_in_force=None, price=None, quantity=None)

Wrapper for placing limit buy orders

Notes

If only one of the instrument_URL or symbol are passed as arguments the other will be looked up automatically.

Parameters
  • instrument_URL (str) – The RH URL of the instrument

  • symbol (str) – The ticker symbol of the instrument

  • time_in_force (str) – ‘GFD’ or ‘GTC’ (day or until cancelled)

  • price (float) – The max price you’re willing to pay per share

  • quantity (int) – Number of shares to buy

Returns

result from orders put command

Return type

(requests.request)

place_limit_sell_order(instrument_URL=None, symbol=None, time_in_force=None, price=None, quantity=None)

Wrapper for placing limit sell orders

Notes

If only one of the instrument_URL or symbol are passed as arguments the other will be looked up automatically.

Parameters
  • instrument_URL (str) – The RH URL of the instrument

  • symbol (str) – The ticker symbol of the instrument

  • time_in_force (str) – ‘GFD’ or ‘GTC’ (day or until cancelled)

  • price (float) – The minimum price you’re willing to get per share

  • quantity (int) – Number of shares to sell

Returns

result from orders put command

Return type

(requests.request)

place_market_buy_order(instrument_URL=None, symbol=None, time_in_force=None, quantity=None)

Wrapper for placing market buy orders

Notes

If only one of the instrument_URL or symbol are passed as arguments the other will be looked up automatically.

Parameters
  • instrument_URL (str) – The RH URL of the instrument

  • symbol (str) – The ticker symbol of the instrument

  • time_in_force (str) – ‘GFD’ or ‘GTC’ (day or until cancelled)

  • quantity (int) – Number of shares to buy

Returns

result from orders put command

Return type

(requests.request)

place_market_sell_order(instrument_URL=None, symbol=None, time_in_force=None, quantity=None)

Wrapper for placing market sell orders

Notes

If only one of the instrument_URL or symbol are passed as arguments the other will be looked up automatically.

Parameters
  • instrument_URL (str) – The RH URL of the instrument

  • symbol (str) – The ticker symbol of the instrument

  • time_in_force (str) – ‘GFD’ or ‘GTC’ (day or until cancelled)

  • quantity (int) – Number of shares to sell

Returns

result from orders put command

Return type

(requests.request)

place_order(instrument, quantity=1, price=0.0, transaction=None, trigger='immediate', order='market', time_in_force='gfd')

Place an order with Robinhood

Parameters
  • instrument (dict) – the RH URL and symbol in dict for the instrument to be traded

  • quantity (int) – quantity of stocks in order

  • bid_price (float) – price for order

  • transaction (Transaction) – BUY or SELL enum

  • trigger (Trigger) – IMMEDIATE or STOP enum

  • order (Order) – MARKET or LIMIT

  • time_in_force (TIME_IN_FORCE) – GFD or GTC (day or until cancelled)

Returns

result from orders put command

Return type

(requests.request)

place_sell_order(instrument, quantity, bid_price=0.0)

Wrapper for placing sell orders

Parameters
  • instrument (dict) – the RH URL and symbol in dict for the instrument to be traded

  • quantity (int) – quantity of stocks in order

  • bid_price (float) – price for order (OPTIONAL! If not given, bid_price is automatic.)

Returns

result from orders put command

Return type

(requests.request)

place_stop_limit_buy_order(instrument_URL=None, symbol=None, time_in_force=None, stop_price=None, price=None, quantity=None)

Wrapper for placing stop limit buy orders

Notes

If only one of the instrument_URL or symbol are passed as arguments the other will be looked up automatically.

Parameters
  • instrument_URL (str) – The RH URL of the instrument

  • symbol (str) – The ticker symbol of the instrument

  • time_in_force (str) – ‘GFD’ or ‘GTC’ (day or until cancelled)

  • stop_price (float) – The price at which this becomes a limit order

  • price (float) – The max price you’re willing to pay per share

  • quantity (int) – Number of shares to buy

Returns

result from orders put command

Return type

(requests.request)

place_stop_limit_sell_order(instrument_URL=None, symbol=None, time_in_force=None, price=None, stop_price=None, quantity=None)

Wrapper for placing stop limit sell orders

Notes

If only one of the instrument_URL or symbol are passed as arguments the other will be looked up automatically.

Parameters
  • instrument_URL (str) – The RH URL of the instrument

  • symbol (str) – The ticker symbol of the instrument

  • time_in_force (str) – ‘GFD’ or ‘GTC’ (day or until cancelled)

  • stop_price (float) – The price at which this becomes a limit order

  • price (float) – The max price you’re willing to get per share

  • quantity (int) – Number of shares to sell

Returns

result from orders put command

Return type

(requests.request)

place_stop_loss_buy_order(instrument_URL=None, symbol=None, time_in_force=None, stop_price=None, quantity=None)

Wrapper for placing stop loss buy orders

Notes

If only one of the instrument_URL or symbol are passed as arguments the other will be looked up automatically.

Parameters
  • instrument_URL (str) – The RH URL of the instrument

  • symbol (str) – The ticker symbol of the instrument

  • time_in_force (str) – ‘GFD’ or ‘GTC’ (day or until cancelled)

  • stop_price (float) – The price at which this becomes a market order

  • quantity (int) – Number of shares to buy

Returns

result from orders put command

Return type

(requests.request)

place_stop_loss_sell_order(instrument_URL=None, symbol=None, time_in_force=None, stop_price=None, quantity=None)

Wrapper for placing stop loss sell orders

Notes

If only one of the instrument_URL or symbol are passed as arguments the other will be looked up automatically.

Parameters
  • instrument_URL (str) – The RH URL of the instrument

  • symbol (str) – The ticker symbol of the instrument

  • time_in_force (str) – ‘GFD’ or ‘GTC’ (day or until cancelled)

  • stop_price (float) – The price at which this becomes a market order

  • quantity (int) – Number of shares to sell

Returns

result from orders put command

Return type

(requests.request)

portfolio()

Returns the user’s portfolio data

positions()

Returns the user’s positions data

Returns

object: dict): JSON dict from getting positions

Return type

(

previous_close(stock='')

Get previous closing price for a stock.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

previous closing price

Return type

(float)

previous_close_date(stock='')

Get previous closing date for a stock.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

previous close date

Return type

(str)

print_quote(stock='')

Print quote information.

Parameters

stock (str) – ticker to fetch

Returns

None

print_quotes(stocks)

Print a collection of stocks.

Parameters

stocks (list) – list of stocks to pirnt

Returns

None

quote_data(stock='')

Fetch stock quote.

Parameters

stock (str or dict) – stock ticker symbol or stock instrument

Returns

JSON contents from quotes endpoint

Return type

(dict)

quotes_data(stocks)

Fetch quote for multiple stocks, in one single Robinhood API call.

Parameters

stocks (list<str>) – stock tickers

Returns

List of JSON contents from quotes endpoint, in the same order of input args. If any ticker is invalid, a None will occur at that position.

Return type

(list of dict)

securities_owned()

Returns list of securities’ symbols that the user has shares in

Returns

object: dict): Non-zero positions

Return type

(

submit_buy_order(instrument_URL=None, symbol=None, order_type=None, time_in_force=None, trigger=None, price=None, stop_price=None, quantity=None, side=None)

Submits buy order to Robinhood

Notes

This is normally not called directly. Most programs should use one of the following instead:

place_market_buy_order() place_limit_buy_order() place_stop_loss_buy_order() place_stop_limit_buy_order() place_market_sell_order() place_limit_sell_order() place_stop_loss_sell_order() place_stop_limit_sell_order()

Parameters
  • instrument_URL (str) – the RH URL for the instrument

  • symbol (str) – the ticker symbol for the instrument

  • order_type (str) – ‘market’ or ‘limit’

  • time_in_force (TIME_IN_FORCE) – ‘gfd’ or ‘gtc’ (day or until cancelled)

  • trigger (str) – ‘immediate’ or ‘stop’ enum

  • price (float) – The share price you’ll accept

  • stop_price (float) – The price at which the order becomes a market or limit order

  • quantity (int) – The number of shares to buy/sell

  • side (str) – BUY or sell

Returns

result from orders put command

Return type

(requests.request)

submit_sell_order(instrument_URL=None, symbol=None, order_type=None, time_in_force=None, trigger=None, price=None, stop_price=None, quantity=None, side=None)

Submits order to Robinhood

Notes

This is normally not called directly. Most programs should use one of the following instead:

place_market_buy_order() place_limit_buy_order() place_stop_loss_buy_order() place_stop_limit_buy_order() place_market_sell_order() place_limit_sell_order() place_stop_loss_sell_order() place_stop_limit_sell_order()

Parameters
  • instrument_URL (str) – the RH URL for the instrument

  • symbol (str) – the ticker symbol for the instrument

  • order_type (str) – ‘MARKET’ or ‘LIMIT’

  • time_in_force (TIME_IN_FORCE) – GFD or GTC (day or until cancelled)

  • trigger (str) – IMMEDIATE or STOP enum

  • price (float) – The share price you’ll accept

  • stop_price (float) – The price at which the order becomes a market or limit order

  • quantity (int) – The number of shares to buy/sell

  • side (str) – BUY or sell

Returns

result from orders put command

Return type

(requests.request)

symbol(stock='')

Get symbol for a stock.

Note

queries quote endpoint, dict wrapper

Parameters

stock (str) – stock ticker

Returns

stock symbol

Return type

(str)