當前位置: 首頁>>代碼示例>>Python>>正文


Python Stock.get_stocks_sorted_by_sustainability方法代碼示例

本文整理匯總了Python中models.Stock.get_stocks_sorted_by_sustainability方法的典型用法代碼示例。如果您正苦於以下問題:Python Stock.get_stocks_sorted_by_sustainability方法的具體用法?Python Stock.get_stocks_sorted_by_sustainability怎麽用?Python Stock.get_stocks_sorted_by_sustainability使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Stock的用法示例。


在下文中一共展示了Stock.get_stocks_sorted_by_sustainability方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: home

# 需要導入模塊: from models import Stock [as 別名]
# 或者: from models.Stock import get_stocks_sorted_by_sustainability [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())
開發者ID:damlaren,項目名稱:investorscope-app,代碼行數:41,代碼來源:views.py


注:本文中的models.Stock.get_stocks_sorted_by_sustainability方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。