diff --git a/stock_wrapper/__pycache__/data.cpython-37.pyc b/stock_wrapper/__pycache__/data.cpython-37.pyc index 56ffae8..7702864 100644 Binary files a/stock_wrapper/__pycache__/data.cpython-37.pyc and b/stock_wrapper/__pycache__/data.cpython-37.pyc differ diff --git a/stock_wrapper/__pycache__/stock.cpython-37.pyc b/stock_wrapper/__pycache__/stock.cpython-37.pyc index bd6b507..0b540d1 100644 Binary files a/stock_wrapper/__pycache__/stock.cpython-37.pyc and b/stock_wrapper/__pycache__/stock.cpython-37.pyc differ diff --git a/stock_wrapper/stock.py b/stock_wrapper/stock.py index 8087c9d..b2d2fc2 100644 --- a/stock_wrapper/stock.py +++ b/stock_wrapper/stock.py @@ -1,19 +1,17 @@ import yfinance -import robin_stocks import stock_wrapper class Stock(): def __init__(self, ticker): self.ticker = ticker - - self.fundamentals = robin_stocks.get_fundamentals(self.ticker)[0] + self.reload_info() def __str__(self): return self.ticker - def reload_cache(self): - self.fundamentals = robin_stocks.get_fundamentals(self.ticker)[0] + def reload_info(self): + self.company_info = yfinance.Ticker(self.ticker).info def get_historical_prices(self, span='day'): return stock_wrapper.data.get_historical_prices(self.ticker, span=span) @@ -24,100 +22,115 @@ def history(self): @property def price(self): - return float(robin_stocks.stocks.get_latest_price(self.ticker)[0]) + data_this_minute = self.__get_current_price_data() + return float((data_this_minute['Close'] + data_this_minute['Open']) / 2) @property def open(self): """ :return: latest open price """ - return float(robin_stocks.stocks.get_fundamentals(self.ticker)[0]['open']) + return float(self.__get_current_price_data()['Open']) @property def close(self): """ :return: latest closing price """ - return float(robin_stocks.stocks.get_historicals(self.ticker, span='day')[0]['close_price']) + return float(self.__get_current_price_data()['Close']) @property - def low(self): + def high(self): """ - :return: lowest price today + :return: highest price today """ - return float(robin_stocks.stocks.get_fundamentals(self.ticker)[0]['low']) + return float(self.__get_current_price_data()['High']) @property - def low_52_weeks(self): + def low(self): """ - :return: highest price this year + :return: lowest price today """ - return float(robin_stocks.stocks.get_fundamentals(self.ticker)[0]['low_52_weeks']) + return float(self.__get_current_price_data()['Low']) + + def __get_current_price_data(self): + return yfinance.Ticker(self.ticker).history(period='day', interval='1m').iloc[[-1]] @property - def high(self): + def low_52_weeks(self): """ - :return: highest price today + :return: highest price this year """ - return float(robin_stocks.stocks.get_fundamentals(self.ticker)[0]['high']) + return self.company_info['fiftyTwoWeekLow'] @property def high_52_weeks(self): """ :return: highest price this year """ - return float(robin_stocks.stocks.get_fundamentals(self.ticker)[0]['high_52_weeks']) + return self.company_info['fiftyTwoWeekHigh'] @property def market_cap(self): - return float(robin_stocks.stocks.get_fundamentals(self.ticker)[0]['market_cap']) + return self.company_info['marketCap'] @property def volume(self): """ :return: average market volume """ - return int(float(robin_stocks.stocks.get_fundamentals(self.ticker)[0]['volume'])) - - @property - def volume_2_weeks(self): - """ - :return: average market volume from past two weeks - """ - return int(float(robin_stocks.stocks.get_fundamentals(self.ticker)[0]['average_volume_2_weeks'])) - - @property - def ceo(self): - return robin_stocks.stocks.get_fundamentals(self.ticker)[0]['ceo'] + return self.company_info['averageVolume'] @property def sector(self): - return self.fundamentals['sector'] + return self.company_info['sector'] @property def industry(self): - return robin_stocks.stocks.get_fundamentals(self.ticker)[0]['industry'] + return self.company_info['industry'] @property def shares_outstanding(self): - return robin_stocks.stocks.get_fundamentals(self.ticker)[0]['shares_outstanding'] + return self.company_info['sharesOutstanding'] @property def num_employees(self): - return robin_stocks.stocks.get_fundamentals(self.ticker)[0]['num_employees'] + return self.company_info['fullTimeEmployees'] @property def hq_city(self): - return self.fundamentals['headquarters_city'] + return self.company_info['city'] @property def hq_state(self): - return self.fundamentals['headquarters_state'] + return self.company_info['state'] @property - def description(self): - return self.fundamentals['description'] + def hq_country(self): + return self.company_info['country'] + + #contact information + @property + def website(self): + return self.company_info['website'] + + @property + def website(self): + return self.company_info['website'] @property - def year_founded(self): - return self.fundamentals['year_founded'] + def address(self): + return self.company_info['address1'] + + @property + def phone(self): + return self.company_info['phone'] + + @property + def logo(self): + return self.company_info['logo_url'] + + @property + def description(self): + return self.company_info['longBusinessSummary'] +