Rug¶
- class rug.Rug(symbol=None)¶
The Rug class provides a unified interface to all the functionality of the individual classes in the rug package.
Use as:
from rug import Rug Rug("AAPL").get_dividends()
- get_basic_info()¶
Downloads basic info about symbol. Data are:
company_name
market
description
has_dividends
year_low
year_high
pe_ratio
eps
market_cap
60_months_beta
upcoming_earnings_date
- similar_items
name
market_cap
- get_current_price_change()¶
Fetches current market price inc. pre/post market prices/percent/value changes. Also returns current market state (pre-market, open, post-market).
Fetched stucture has following fields:
state (pre-market, open, post-market, closed)
- pre_market
- change
percents
value
value
- current_market
- change
percents
value
value
- post_market
- change
percents
value
value
Values are floats (if present) or 0.0. Returned dict looks like:
{ "state": "open", "pre_market": { "change": { "percents": -1.32476, "value": -1.42001 }, "value": 105.77 }, "current_market": { "change": { "percents": -1.6046284000000002, "value": -1.7200012 }, "value": 105.47 }, "post_market": { "change": { "percents": 0.0, "value": 0.0 }, "value": 0.0 } }
- Returns:
Current/Pre/Post market numbers (all are floats).
- Return type:
dict
- get_dividends()¶
Fetches symbol dividends with following fields:
yield
amount
ex_date
payment_date
record_date
growth_since
- Returns:
List of dividend objects.
- Return type:
list
- get_earnings()¶
Returns earnings as time went in a list of tuples where first is a date and the second is earning value.
- Raises:
SymbolNotFound – In case the page doesn’t exist/returns error code or has no data.
DataException – In case data were found but are not JSON valid.
- Returns:
List of earnings including dates.
- Return type:
list
- get_earnings_calendar()¶
Fetches upcomming earnings annoucements within next 14 days.
Each earning dict has the following structure:
date
symbol
when (BEFORE_OPEN or AFTER_CLOSE)
- Returns:
List of earning objects.
- Return type:
list
- get_eps()¶
Returns eps for the given
self.symbolas table rows (list of lists) where first row is table headers for comprehension. Rows are sorted chronologically.- Raises:
SymbolNotFound – In case the page doesn’t exist/returns error code or has no data.
DataException – In case data were found but are not in valid format - only one HTML table.
- Returns:
List of lists with earnings.
- Return type:
list
- get_etf_basic_info()¶
Fetches ETF basic data including dividends. In case any record cannot be fetched it’s still present but has
Nonevalue or in case of dividends an emtpy list. Excetpion is description record where if not found an exception is raised.Returns data in format:
{ '60_month_beta': 4.08, 'alpha': 18.2, 'asset_class': 'Equity', 'asset_value': 60.9, 'brand': 'Direxion Investments', 'description': 'The Direxion Daily Semiconductor Bull and Bear 3X Shares seek ' 'daily investment results, before fees and expenses, of 300% ' 'or 300% of the inverse (or opposite) of the performance of ' 'the PHLX Semiconductor Sector Index.', 'dividend': 0.28, 'dividend_yield': 0.46, 'dividends': [{'amount': 0.0077, 'date': datetime.date(2010, 9, 22)}, {'amount': 0.0053, 'date': datetime.date(2014, 12, 23)}, {'amount': 0.121, 'date': datetime.date(2017, 12, 19)}, {'amount': 0.351, 'date': datetime.date(2018, 6, 19)}, {'amount': 0.452, 'date': datetime.date(2018, 9, 25)}, {'amount': 0.283, 'date': datetime.date(2018, 12, 27)}, {'amount': 0.243, 'date': datetime.date(2019, 3, 19)}, {'amount': 0.194, 'date': datetime.date(2019, 6, 25)}, {'amount': 0.313, 'date': datetime.date(2019, 9, 24)}, {'amount': 0.288, 'date': datetime.date(2019, 12, 23)}, {'amount': 0.079, 'date': datetime.date(2020, 3, 24)}, {'amount': 0.094, 'date': datetime.date(2020, 6, 23)}, {'amount': 0.003, 'date': datetime.date(2020, 12, 22)}, {'amount': 0.016, 'date': datetime.date(2021, 3, 23)}, {'amount': 0.014, 'date': datetime.date(2021, 12, 21)}, {'amount': 0.007, 'date': datetime.date(2022, 3, 22)}, {'amount': 0.019, 'date': datetime.date(2022, 6, 22)}, {'amount': 0.04, 'date': datetime.date(2022, 9, 20)}, {'amount': 0.038, 'date': datetime.date(2022, 12, 20)}, {'amount': 0.025, 'date': datetime.date(2023, 3, 21)}, {'amount': 0.038, 'date': datetime.date(2023, 6, 21)}, {'amount': 0.033, 'date': datetime.date(2023, 9, 19)}, {'amount': 0.063, 'date': datetime.date(2023, 12, 21)}, {'amount': 0.035, 'date': datetime.date(2024, 3, 19)}, {'amount': 0.149, 'date': datetime.date(2024, 6, 25)}], 'expense_ratio': 0.9, 'first_trade_price': 9.64, 'inception': datetime.date(2010, 3, 11), 'index_tracked': 'PHLX Semiconductor Sector Index', 'last_dividend_date': datetime.date(2024, 6, 25), 'latest_dividend': 0.149, 'latest_split': '15-1', 'leverage': 'Triple-Long', 'managed_assets': '11,981,859.20 K', 'management_fee': 0.9, 'name': 'Direxion Daily Semiconductor Bull 3X Shares', 'options': True, 'pe_ratio': 0.03, 'split_date': datetime.date(2021, 3, 2), 'std_dev': 1.31 }
- Returns:
Data as a dict with all the keys.
- Return type:
dict
- get_etf_holdings()¶
Fetches ETF holdings table as a list of dicts with following keys:
name
symbol (can be None)
instrument
weight (in %)
- get_insider_trading()¶
Fetches insiders transactions (if available) as a list with following fields:
person
relationship
date
transaction
price
amount
- Returns:
Inriders transaction in reversed chronological order.
- Return type:
list
- get_price_ratings()¶
Returns price ratings a.k.a price targets by analysts.
Returned rows are:
date
status
analyst
rating
target price
- Returns:
Rows as a list of tuples where each tuple has 5 items.
- Return type:
list
- get_ratings()¶
Returns ratings for past 4 months. Each months is a dict with status and it’s values where values are in absolute number (number of analyst) and percents (ratio).
Returns data in format:
[ { "Strong Buy":{ "value":"14", "percent":60.86956521739131 }, "Hold":{ "value":"9", "percent":39.130434782608695 } }, { "Strong Buy":{ "value":"15", "percent":65.21739130434783 }, "Hold":{ "value":"8", "percent":34.78260869565217 } }, { "Strong Buy":{ "value":"15", "percent":62.5 }, "Moderate Buy":{ "value":"1", "percent":4.166666666666666 }, "Hold":{ "value":"8", "percent":33.33333333333333 } }, { "Strong Buy":{ "value":"17", "percent":73.91304347826086 }, "Moderate Buy":{ "value":"1", "percent":4.3478260869565215 }, "Hold":{ "value":"5", "percent":21.73913043478261 } } ]
- Raises:
SymbolNotFound – In case the page doesn’t exist/returns error code.
- Returns:
List of each month data.
- Return type:
list
- get_revenues()¶
Returns revenues as time went in a list of tuples where first is a date and the second is revenue value.
- Raises:
SymbolNotFound – In case the page doesn’t exist/returns error code or has no data.
DataException – In case data were found but are not JSON valid.
- Returns:
List of EPS including dates.
- Return type:
list