Skip to content

Commit

Permalink
Merge pull request #7 from JadenSWang/Rebuild-Data-Gathering
Browse files Browse the repository at this point in the history
Fixed Error 401 while getting price
  • Loading branch information
JadenSWang authored May 20, 2020
2 parents ffc79ea + 8ad52ef commit 37afcd1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 41 deletions.
Binary file modified stock_wrapper/__pycache__/data.cpython-37.pyc
Binary file not shown.
Binary file modified stock_wrapper/__pycache__/stock.cpython-37.pyc
Binary file not shown.
95 changes: 54 additions & 41 deletions stock_wrapper/stock.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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']

0 comments on commit 37afcd1

Please sign in to comment.