Need help solving this error:
File "/workspaces/finance/app.py", line 223, in sell
if available_shares < shares:
TypeError: '<' not supported between instances of 'NoneType' and 'int'
I'm stuck and any help is much appreciated! Thank you!
@app.route("/sell", methods=["GET", "POST"])
@login_required
def sell():
"""Sell shares of stock"""
user_id = session["user_id"]
symbols = db.execute("SELECT symbol FROM trades WHERE user_id = ? GROUP BY symbol", user_id)
if request.method == "POST":
symbol = request.form.get("symbol")
shares = int(request.form.get("shares"))
# User did not provide any symbol
if not symbol:
return apology("Please select stock code", 400)
# User did not provide valid quantity
elif not shares:
return apology("Please provide valid quantity", 400)
available_shares = db.execute("SELECT SUM(quantity) AS subtotal FROM trades WHERE user_id = ? AND symbol = ?", user_id, symbol)[0]["subtotal"]
if available_shares < shares:
return apology("Insufficient shares to sell")
else:
cash = db.execute("SELECT cash FROM users WHERE id = ?", user_id)[0]["cash"]
stock_price = lookup(symbol)["price"]
total_price = shares * stock_price
db.execute("UPDATE users SET cash = ? WHERE id =?", cash+total_price, user_id)
db.execute("INSERT INTO trades (user_id, buy_sell, symbol, quantity, price, total_trade_value) VALUES (?, ?, ?, ?, ?, ?)", user_id, "(SOLD)", symbol, -shares, stock_price, total_price)
return redirect("/")
else:
return render_template("sell.html", symbols=symbols)