def test_earning(self): earnings = r.get_earnings(self.single_stock)[0] assert ('symbol' in earnings) assert (earnings['symbol'] == self.single_stock) assert ('instrument' in earnings) assert isinstance(earnings["instrument"], str) assert ('year' in earnings) assert isinstance(earnings["year"], int) assert ('quarter' in earnings) assert isinstance(earnings["quarter"], int) assert ('eps' in earnings) assert isinstance(earnings["eps"], dict) assert ("actual" in earnings["eps"]) assert isinstance(earnings["eps"]["actual"], float) assert ("estimate" in earnings["eps"]) assert isinstance(earnings["eps"]["estimate"], float) assert ('report' in earnings) assert isinstance(earnings["report"], dict) assert ("date" in earnings["report"]) assert isinstance(earnings["report"]["date"], str) assert ("timing" in earnings["report"]) assert isinstance(earnings["report"]["timing"], str) assert ("verified" in earnings["report"]) assert isinstance(earnings["report"]["verified"], bool) assert ('call' in earnings) assert isinstance(earnings["call"], dict) assert ("broadcast_url" in earnings["call"]) assert ("datetime" in earnings["call"]) assert isinstance(earnings["call"]["datetime"], str) assert ("replay_url" in earnings["call"]) assert isinstance(earnings["call"]["replay_url"], str) fake_earnings = r.get_earnings(self.fake_stock) assert (len(fake_earnings) == 0)
def test_earning(self): earnings = r.get_earnings(self.single_stock)[0] assert (earnings['symbol'] == self.single_stock) assert ('symbol' in earnings) assert ('instrument' in earnings) assert ('year' in earnings) assert ('quarter' in earnings) assert ('eps' in earnings) assert ('report' in earnings) assert ('call' in earnings) fake_earnings = r.get_earnings(self.fake_stock) assert (len(fake_earnings) == 0)
def test_earning(self): earnings = r.get_earnings(self.single_stock)[0] self.assertEqual(earnings['symbol'], self.single_stock) self.assertIn('symbol', earnings) self.assertIn('instrument', earnings) self.assertIn('year', earnings) self.assertIn('quarter', earnings) self.assertIn('eps', earnings) self.assertIn('report', earnings) self.assertIn('call', earnings) fake_earnings = r.get_earnings(self.fake_stock) self.assertEqual(len(fake_earnings), 0)
def getEarnings(symbols, year, month): current_year_dates = [] for symbol in symbols: try: earnings = r.get_earnings(symbol) # print(earnings) if len(earnings) > 0: earnings = list(filter(lambda e: e['report'] != None, earnings)) current_year = list( filter(lambda e: e['report']['date'][0:4] == year, earnings)) earnings_dates = list( map(lambda e: e['report']['date'], current_year)) earnings_dates = list( filter(lambda e: e[5:7] == month, earnings_dates)) current_year_dates.append((symbol, earnings_dates)) else: print(symbol, 'no earnings') except Exception as e: print('skipped', symbol, e) current_year_dates = list(filter(fltrempty, current_year_dates)) current_year_dates = sorted(current_year_dates, key=lambda x: x[1][0]) current_month_date = [(x[0], x[1][0]) for x in current_year_dates] return current_month_date
def getEarningsCurrentMonth(symbol, year, month): year_month = year + '-' + month earnings = r.get_earnings(symbol=symbol) if len(earnings) > 0: report_dicts = list(filter(lambda e: e['report'] != None, earnings)) #print(symbol,report_dict) year_month_dicts = list( filter(lambda e: e['report']['date'][0:7] == year_month, report_dicts)) year_month_date = list( map(lambda e: e['report']['date'], year_month_dicts)) if len(year_month_date) > 0: #print(symbol,year_month_date) return symbol, year_month_date[0]
def daysToEarnings(symbol=str): today = dt.date.today() earnings = rh.get_earnings(symbol) earnings = pd.DataFrame(earnings) report = earnings.report daysUntil = 100 for item in report: date = dt.datetime.strptime(str(item['date']), '%Y-%m-%d') date = date.date() td = date - today td = td.days if td < daysUntil and td > 0: daysUntil = td return int(daysUntil)
def getstockinfo(watchlistname): # fetch data from robinhood and parse data into a dictionary structure that stockcontainer can accept for stock in watchlist: week = r.get_historicals(stock, span='week', bounds="regular") month = r.get_historicals(stock, span='month', bounds="regular") year = r.get_historicals(stock, span='year', bounds="regular") fiveyear = r.get_historicals(stock, span='5year', bounds="regular") data = {} data['name'] = str(stock) data[ 'price'] = "Stock created using secondary method - price not supported" data['earnings'] = r.get_earnings(stock) data['events'] = r.get_events(stock) data['fundamentals'] = r.get_fundamentals(stock) x = stockcontainer(stock, data, "f**k off", week, month, year, fiveyear) traj = trajectory(x) x.addtrajectory(traj) stocksArray.append(x)
def get_earnings(symbol): result = rh.get_earnings(symbol) ui.success(result)
data['earnings'] = r.get_earnings(stock) data['events'] = r.get_events(stock) data['fundamentals'] = r.get_fundamentals(stock) x = stockcontainer(stock, data, "f**k off", week, month, year, fiveyear) traj = trajectory(x) x.addtrajectory(traj) stocksArray.append(x) addmystocks = True blacklist = [] for key, value in stockList.items(): if addmystocks: if key not in blacklist: earnings = r.get_earnings(key) weekraw = r.get_historicals(key, span='week', bounds="regular") monthraw = r.get_historicals(key, span='month', bounds="regular") yearraw = r.get_historicals(key, span="year", bounds="regular") fiveyearraw = r.get_historicals(key, span="5year", bounds="regular") stocksArray.append( (stockcontainer(key, value, earnings, weekraw, monthraw, yearraw, fiveyearraw))) stocknumber = stocknumber + 1 else: print(f'{key} excluded from calculations') if addmystocks: for stock in stocksArray: