btb.libtrading package

Submodules

btb.libtrading.trading module

synopis:

Convenience wrapper for trading functionality.

class btb.libtrading.trading.Trading(username, password, qr_code)[source]

Bases: object

Provides a simple stock trading API using the pyrh library. As such this library is only compatible with Robinhood accounts.

Parameters:
  • username (str) – Username of account to log into, in the form of an email.

  • password (str) – password of account to log into.

  • qr_code (str) – QR code of account to log into, needed to avoid full two step verification process for each login.

buy_dollar_amount(ticker, dollar_amount) None[source]

Places a market buy order for provided stock ticker given a dollar amount for the amount to buy.

Parameters:
  • ticker (str) – Stock ticker (symbol) to be purchased.

  • dollar_amount (float) – The dollar amount used to calculated the number of shares to buy.

Returns:

None.

buy_quantity(ticker, quantity) None[source]

Places a market buy order for provided stock ticker given a quantity to buy.

Parameters:
  • ticker (str) – Stock ticker (symbol) to be purchased.

  • quantity (float) – The amount of shares to be purchased.

Returns:

None.

buy_with_current_funds(ticker) None[source]

Places a market buy order for provided stock ticker using the remaining account balance.

Parameters:

ticker (str) – Stock ticker (symbol) to be purchased.

Returns:

None.

get_least_recently_purchased() Dict[str, float][source]

Returns Robinhood instrument ID and quantity of least recently purchased stock.

Returns:

Dictionary containing Robinhood instrument ID and quantity of least recently purchased stock.

Return type:

dict[str, float]

liquidity() int[source]

Returns the integer percentage of account liquidity. e.g. If the account is worth $100 and currently has a buying power of $10 then the liquidity is 10 (10%).

Returns:

Integer percentage of account liquidity.

Return type:

int

round_decimals_down(number: float, decimals: int = 5) float[source]

Returns a value rounded down to a specific number of decimal places.

Parameters:
  • number (float) – Number to be rounded.

  • decimals (int) – Number of decimal place at which to round down.

return: Round float. :rtype: float

sell_dollar_amount(ticker, dollar_amount) None[source]

Places a market sell order for provided stock ticker given a dollar amount for the amount to sell.

Parameters:
  • ticker (str) – Stock ticker (symbol) to be sold.

  • dollar_amount (float) – The dollar amount used to calculated the number of shares to sell.

Returns:

None.

sell_quantity(ticker, quantity) None[source]

Places a market sell order for provided stock ticker given a quantity to sell.

Parameters:
  • ticker (str) – Stock ticker (symbol) to be sold.

  • quantity (float) – The amount of shares to be sold.

Returns:

None.

Module contents