示例#1
0
def dashboard():
    username = active_user()
    csv_file_path = os.path.join((os.path.dirname(__file__)), "..", "..",
                                 f"users/{username}", f"{username}.csv")
    csv_file_path2 = os.path.join((os.path.dirname(__file__)), "..", "..",
                                  f"users/{username}",
                                  f"{username}_transactions.csv")
    results = pd.read_csv(csv_file_path).to_dict("records")
    if len(results) == 0:
        results = ""
    stocks_df = pd.read_csv(csv_file_path)
    transactions_df = pd.read_csv(csv_file_path2)
    cash_value = float(transactions_df["Value"].sum())
    positions = stocks_df["Total Value"].sum()
    if positions == " ":
        positions = 0.00
        total = cash_value
    else:
        format_dict(results)
        positions = float(positions)
        total = cash_value + positions
    return render_template("dashboard.html",
                           username=username,
                           results=results,
                           value=to_usd(cash_value),
                           value2=to_usd(positions),
                           value3=to_usd(total))
示例#2
0
def sell_order():
    username = active_user()
    csv_file_path = os.path.join((os.path.dirname(__file__)), "..", "..",
                                 f"users/{username}", f"{username}.csv")
    data = pd.read_csv(csv_file_path).to_dict("records")
    user = dict(request.form)
    user['ticker'] = user['ticker'].upper()
    stock = [n["Stock"] for n in data if n["Stock"] == user['ticker']]
    shares_aval = [n["Shares"] for n in data if n["Stock"] == user['ticker']]
    if not stock:
        flash(f"You Do Not Own That Stock", "danger")
    elif int(user['share_count']) > shares_aval[0]:
        flash(f"You Do Not Own That Many Shares", "danger")
    else:
        results = live_price(user['ticker'], API_KEY)
        if str(results) == "Invalid Stock Symbol, Try Again":
            flash(f"{results}", "danger")
        else:
            shares = int(user['share_count'])
            sell_transac(csv_file_path, stock, shares, results, shares_aval[0])
            transac_rec(user['ticker'], results, shares, username, "Sell")
            flash(
                f"You Sold {shares} Shares of {user['ticker']} For {to_usd(results*shares)}",
                "success")
    return redirect("/buy-sell")
示例#3
0
def transac():
    username = active_user()
    csv_file_path = os.path.join((os.path.dirname(__file__)), "..", "..",
                                 f"users/{username}",
                                 f"{username}_transactions.csv")
    results = pd.read_csv(csv_file_path).to_dict("records")
    format_dict2(results)
    return render_template("transactions.html", results=results)
示例#4
0
def buy_order():
    user = dict(request.form)
    username = active_user()
    user['ticker'] = user['ticker'].upper()
    results = live_price(user['ticker'], API_KEY)
    csv_file_path = os.path.join((os.path.dirname(__file__)), "..", "..",
                                 f"users/{username}", f"{username}.csv")
    pos_count = len(pd.read_csv(csv_file_path).to_dict("records"))
    csv_file_path2 = os.path.join((os.path.dirname(__file__)), "..", "..",
                                  f"users/{username}",
                                  f"{username}_transactions.csv")
    data = pd.read_csv(csv_file_path).to_dict("records")
    transactions_df = pd.read_csv(csv_file_path2)
    cash_value = float(transactions_df["Value"].sum())
    stock = [n["Stock"] for n in data if n["Stock"] == user['ticker']]
    if str(results) == "Invalid Stock Symbol, Try Again":
        flash(f"{results}", "danger")
    elif len(stock) > 0:
        shares = int(user['share_count'])
        if (shares * results) > cash_value:
            flash(f"Insufficient Funds", "danger")
        else:
            buy_transac(csv_file_path, stock, shares, results)
            flash(
                f"You Bought {shares} Shares of {user['ticker']} For {to_usd(results*shares)}",
                "success")
            transac_rec(user['ticker'], results, shares, username, "Buy+")
    elif pos_count > 4:
        flash(
            f"Reached Positions Limit of 5, Please Sell Position Before Buying A New One",
            "danger")
    else:
        shares = int(user['share_count'])
        if (shares * results) > cash_value:
            flash(f"Insufficient Funds", "danger")
        else:
            flash(
                f"You Bought {shares} Shares of {user['ticker']} For {to_usd(results*shares)}",
                "success")
            transac_rec(user['ticker'], results, shares, username, "Buy")
    return redirect("/buy-sell")
示例#5
0
def update():
    username = active_user()
    update_prices(username, API_KEY)
    flash(f"Market Values Updated", "success")
    return redirect("/dashboard")