def home(): if request.method == 'POST': form = request.form selection = form["symbol"] price = get_price(selection) else: price = "" return render_template("home.html", price=price)
def sell(): form = SellForm() if request.form: selection = form.stock.data stmt = select(UserYOLO).where(UserYOLO.stock == selection, UserYOLO.username == current_user.username) stock_sell = stmt.number_shares price_string = get_price(selection) price = float(price_string) if form.amount.data < stock_sell: print("hello") current_user.dat_green = current_user.dat_green+price * form.amount.data db.session.commit() else: return render_template('broke.html') return render_template('sell.html', form=form)
def buy(): form = BuyForm() if request.form: selection = form.stock.data price_string = get_price(selection) price = float(price_string) if price * form.amount.data < current_user.dat_green: new_buy = UserYOLO(username=current_user.username, stock=form.stock.data, number_shares=form.amount.data, initial_price=price) db.session.add(new_buy) db.session.commit() current_user.dat_green = current_user.dat_green-price * form.amount.data db.session.commit() else: return render_template('broke.html') return render_template('buy.html', form=form)