本文整理汇总了Python中models.Stock.get_stocks方法的典型用法代码示例。如果您正苦于以下问题:Python Stock.get_stocks方法的具体用法?Python Stock.get_stocks怎么用?Python Stock.get_stocks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Stock
的用法示例。
在下文中一共展示了Stock.get_stocks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stock
# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import get_stocks [as 别名]
def stock():
if not account.user_is_logged_in():
return redirect(url_for("login"))
ticker = request.args.get("ticker", "AAPL") # TODO: no ticker is error...
# Find the stock.
stock = Stock.get_stock_from_db(ticker)
# Check for errors.
if stock == -1:
N_STOCKS = 20 # number of stocks to retrieve
tickers = Stock.get_all_tickers()
stocks = Stock.get_stocks(N_STOCKS, True) # default: list of stocks by alpha order
return render_template("home.html",
error="No ticker matching that name could be found.",
tickers = tickers, stocks = stocks,
metric = "alpha", order = True,
has_recs = account.user_has_recommendations())
# Get the prices with corresponding dates.
# Produce formatted date strings to paste into HTML.
price_time_series = Stock.get_time_series(ticker, 7)
price_dates = price_time_series.keys()
price_dates.sort()
price_dates_str = []
price_values = []
for curr_date in price_dates:
price_values.append(price_time_series[curr_date])
price_dates_str.append(curr_date.strftime("%m-%d"))
# Compute price change now-- consistent with time series data!
price_change = price_values[-1] - price_values[-2]
# Put a blurb in the stock page if it is recommended.
stock_is_recommended = False
if account.user_has_recommendations():
if stock.ticker in Stock.recommended_tickers:
stock_is_recommended = True
return render_template("stock.html", ticker = stock.ticker,
name = stock.name, latest_price = stock.cur_price,
pe_ratio = stock.pe, market_cap = stock.cap,
dividends = stock.dividends,
beta = stock.beta,
sustainability = stock.sustainability,
socialgood = stock.socialgood,
american = stock.american,
price_change = price_change,
price_series_dates = price_dates_str,
price_series_values = price_values,
recommended = stock_is_recommended)
示例2: home
# 需要导入模块: from models import Stock [as 别名]
# 或者: from models.Stock import get_stocks [as 别名]
def home():
N_STOCKS = 20 # number of stocks to retrieve
if not account.user_is_logged_in():
return redirect(url_for("login"))
# Get all stock tickers
tickers = Stock.get_all_tickers()
# Get default sorting metric and order
order = None
metric = request.args.get("metric", "recs")
order_arg = request.args.get("order", "lowhigh")
if order_arg == "lowhigh":
order = True
elif order_arg == "highlow":
order = False
# Get sorted stocks
stocks = None
if metric == "alpha":
stocks = Stock.get_stocks(N_STOCKS, order)
elif metric == "price":
stocks = Stock.get_stocks_sorted_by_price(N_STOCKS, order)
elif metric == "pe":
stocks = Stock.get_stocks_sorted_by_pe(N_STOCKS, order)
elif metric == "risk":
stocks = Stock.get_stocks_sorted_by_risk(N_STOCKS, order)
elif metric == "recs":
stocks = Stock.get_recommendations()
elif metric == "sustainability":
stocks = Stock.get_stocks_sorted_by_sustainability(N_STOCKS, order)
elif metric == "socialgood":
stocks = Stock.get_stocks_sorted_by_socialgood(N_STOCKS, order)
elif metric == "american":
stocks = Stock.get_stocks_sorted_by_american(N_STOCKS, order)
return render_template("home.html", tickers = tickers, stocks = stocks,
metric = metric, order = order,
has_recs = account.user_has_recommendations())