def test_get_all(self): symbol = 'GOOG' all_info = ystockquote.get_all(symbol) self.assertIsInstance(all_info, dict) self.assertEqual(all_info['dividend_yield'], ystockquote.get_dividend_yield(symbol)) self.assertEqual(all_info['fifty_sma'], ystockquote.get_50_sma(symbol)) self.assertEqual(all_info['company_name'], ystockquote.get_company_name(symbol)) self.assertEqual(all_info['book_value'], ystockquote.get_book_value(symbol))
def populate(): """ Populates the database with the companies entered. """ companies = get_companies_symbol() # Gets current date and last year's dates current_time = time.strftime('%Y-%m-%d') last_year = str(int(time.strftime('%Y')) - 1) + time.strftime('-%m-%d') # Adds stock to database for stock in companies: print stock Stock.objects.get_or_create( symbol=stock, name=ystockquote.get_company_name(stock)[1:-1], historical_prices=ystockquote.get_historical_prices( stock, last_year, current_time))
def lookup(): symbol = request.args.get('symbol') name = re.sub('["]', '', ystockquote.get_company_name(symbol)) price = ystockquote.get_last_trade_price(symbol) change = ystockquote.get_change_percent_change(symbol) change_realtime, dash, change_percent = change.split() change_realtime = re.sub('["]', '', change_realtime) change_percent = re.sub('["]', '', change_percent) if change_realtime > 0: status = 'gain' else: status = 'loss' today = datetime.today() offset = 10 week = datetime.now() - timedelta(days=offset) history = ystockquote.get_historical_prices(symbol, week.strftime('%Y-%m-%d'), today.strftime('%Y-%m-%d')) return json.dumps({ 'symbol': symbol, 'name': name, 'price': price, 'change_realtime': change_realtime, 'change_percent': change_percent, 'status': status, 'history': history }) pass
print (eval_stock('CSG')) print (type(float(ystockquote.get_todays_high('GOOG')))) print(ystockquote.get_short_ratio('LQMT')) print(ystockquote.get_eps_estimate_current_year('GOOG')) #trailing 12 months number print(ystockquote.get_eps('GOOG')) print(ystockquote.get_price_eps_estimate_current_year('GOOG')) ##Some of the methods available name = ystockquote.get_company_name('GOOG') mktcap = ystockquote.get_market_cap('GOOG') print ("Name: %s , Market Cap %s" %(name,mktcap)) ystockquote.get_200_sma() ystockquote.get_50_sma() ystockquote.get_annualized_gain() ystockquote.get_1_year_target() ystockquote.get_52_week_high() ystockquote.get_52_week_low() ystockquote.get_change_200_sma() ystockquote.get_52_week_range() ystockquote.get_book_value() ystockquote.get_eps_estimate_current_year()