Beispiel #1
0
def sell():
    if request.method == 'GET':
        if 'username' in session:
            return render_template('sell.html')
        else:
            flash('You will need to log in before you can sell your holdings')
            return redirect('/login')
    else:
        try:
            ticker_symbol = request.form['ticker_symbol'].upper()
            number_of_shares = int(request.form['number_of_shares'])
            total_price = model.apiget(ticker_symbol) * number_of_shares
            total_price_rounded = round(total_price, 2)
            user_object = model.set_user_object(session['username'])
            try:
                user_object.sell(ticker=ticker_symbol, volume=number_of_shares)
            except:
                flash('You do not own enough shares')
                return redirect('/sell')
        except:
            flash('Invalid Entry! Try Again..')
            return redirect('/sell')
        flash(
            f"You have just sold {number_of_shares} shares of {ticker_symbol} for {total_price_rounded}"
        )
        return redirect('/buy')
Beispiel #2
0
def see_balance():
    if 'username' in session:
        user_object = model.set_user_object(session['username'])
        balance = user_object.balance
        flash(f'You currently have ${balance} in your account')
        return render_template('see_balance.html')
    else:
        flash('You will need to log in before you can see your balance')
        return redirect('/login')
Beispiel #3
0
def portfolio():
    if request.method == 'GET':
        if 'username' in session:
            user_object = model.set_user_object(session['username'])
            xs = user_object.getpositions_array()
            return render_template('portfolio.html', message=xs)
        else:
            flash('You will need to log in before you can sell your holdings')
            return redirect('/login')
Beispiel #4
0
def trade_history():
    if request.method == 'GET':
        if 'username' in session:
            user_object = model.set_user_object(session['username'])
            xs = user_object.gettrades_array()
            return render_template('trade_history.html', message=xs)
        else:
            flash(
                'You will need to log in before you can see your trade history'
            )
            return redirect('/login')
Beispiel #5
0
def deposit_funds():
    if request.method == 'GET':
        if 'username' in session:
            return render_template('deposit_funds.html')
        else:
            flash('You will need to log in before you can deposit funds')
            return redirect('/login')
    else:
        try:
            amt_of_funds = int(request.form["deposit_amount"])
        except:
            flash('please enter valid amount to deposit')
            return redirect('/desposit_funds')
        user_object = model.set_user_object(session['username'])
        user_object.deposit_funds(amt_of_funds)
        flash(f'You have sucessfully deposited ${amt_of_funds}')
        return redirect('/deposit_funds')
def login():
    if request.method == 'GET':
        if 'username' in session:
            return redirect('/message_board')
        return render_template('login.html')
    else:
        try:
            username = request.form['username']
            password = request.form['password']
            user_object = model.set_user_object(username)
        except:
            flash("Invalid Login")
            return redirect('/login')
        if user_object.check_password(user_object.pass_hash, password):
            session['username'] = username
            flash(f'User {username} successfully logged in!')
            return redirect('/login')
        else:
            flash("Invalid Login")
            return redirect('/login')