Esempio n. 1
0
def quote():
    if request.method == 'GET':
        return render_template('quote.html')
    else:
        ticker_symbol = request.form['copsymb']
        x = model.quote(ticker_symbol)
        return render_template('quote.html', message=x)
Esempio n. 2
0
def quote(balance, earnings, idno, xbal, xearn):
    if request.method == 'GET':
        return render_template('quote.html',
                               balance=balance,
                               earnings=earnings,
                               idno=idno,
                               xbal=xbal,
                               xearn=xearn)
    else:
        idz1 = idno
        quoting = request.form['quotez']
        x = model.quote(quoting)
        #zeez=x.split()
        if isinstance(x, str):
            message2 = "An error occured..." + x
            return render_template('quote.html',
                                   balance=balance,
                                   earnings=earnings,
                                   idno=idno,
                                   xbal=xbal,
                                   xearn=xearn,
                                   message2=message2)
        else:
            bal, earn = model.create(idz1)
            xstr = str(x)
            mess = "the quote is " + xstr + " for {}.".format(quoting)
            return redirect(
                url_for("landing",
                        message1=mess,
                        balance=bal.balancez,
                        earnings=earn.earningz,
                        idno=idno,
                        xbal=bal,
                        xearn=earn))
Esempio n. 3
0
def quote():
    balance = model.check_balance()
    if request.method == 'GET':
        return render_template('quote_menu.html', balance=balance)
    else:
        ticker_symbol = (request.form['ticker_symbol']).upper()
        x = model.quote(ticker_symbol)
        return render_template('homepage.html', x=x, balance=balance)
Esempio n. 4
0
def game_loop():
    user_input = view.main_menu()
    buy_inputs = ['b', 'buy']
    sell_inputs = ['s', 'sell']
    lookup_inputs = ['l', 'lookup']
    quote_inputs = ['q', 'quote']
    exit_inputs = ['e', 'exit']
    view_inputs = ['v', 'view']
    pl_inputs = ['p', 'p']
    acceptable_inputs = buy_inputs      \
        + sell_inputs   \
        + lookup_inputs \
        + quote_inputs  \
        + exit_inputs   \
        + view_inputs   \
        + pl_inputs
    on_off_switch = True
    while on_off_switch:
        if user_input.lower() in acceptable_inputs:
            if user_input.lower() in buy_inputs:
                (ticker_symbol, trade_volume) = view.buy_menu()
                x = model.buy(ticker_symbol, trade_volume)
                return x

            elif user_input.lower() in sell_inputs:
                (ticker_symbol, trade_volume) = view.sell_menu()
                x = model.sell(ticker_symbol, trade_volume)
                return x

            elif user_input.lower() in lookup_inputs:
                company_name = view.lookup_menu()
                x = model.lookup(company_name)
                return x

            elif user_input.lower() in quote_inputs:
                ticker_symbol = view.quote_menu()
                x = model.quote(ticker_symbol)
                return x

            elif user_input.lower() in view_inputs:
                balance = view.portfolio_menu()
                x = model.portfolio(balance)
                return x

            elif user_input.lower() in pl_inputs:
                p = view.pl_menu()
                x = model.pl(p)
                return x

            elif user_input.lower() in exit_inputs:
                break
                #on_off_switch = False
            else:
                print('Bad input. Restarting game in five seconds...')
                time.sleep(5)
                game_loop()
        else:
            return 'Plese Start Over'
Esempio n. 5
0
def quote():
    if request.method == 'GET':
        message = 'What do you wanna get a quote of {}?'.format(
            session['username'])
        return render_template('quote.html', message=message)
    elif request.method == 'POST':
        ticker = request.form["ticker"]
        message = model.quote(ticker)
        return render_template('quote.html', message=message)
Esempio n. 6
0
def get_quote(apikey):
    if not request.json or not 'Ticker' in request.json:
        abort(400)
    if not isinstance(request.json['Ticker'], (str)):
        abort(400)
    user_name = model.api_authenticate(apikey)

    if not user_name:
        return (jsonify({"error": "count not authenticate"}))
    ticker = request.json['Ticker']
    return jsonify({"Ticker": ticker, "price": model.quote(ticker)})
Esempio n. 7
0
def quote():

    if request.method == 'GET':
        return render_template('dashboard.html')
    else:
        user_name = '%s' % escape(session['username'])
        quote = request.form['quote']
        price = model.quote(quote)
        info = model.dashboard(user_name)
        if price:
            return render_template('dashboard.html',
                                   quote_info=quote + ': ' + str(price),
                                   info=info)
        else:
            return render_template('dashboard.html',
                                   quote_info='Could not find quote',
                                   info=info)
Esempio n. 8
0
def game_loop():
    user_input = view.main_menu()
    lookup_inputs = ['l', 'lookup', 'look-up', 'lookup']
    quote_inputs = ['q', 'quote']
    acceptable_inputs = lookup_inputs \
          +quote_inputs
    if user_input in acceptable_inputs:
        if user_input in lookup_inputs:
            x = view.lookup_menu()
            y = model.lookup(x)
            print(y)
        elif user_input in quote_inputs:
            x = view.quote_menu()
            y = model.quote(x)
            print(y)
        else:
            print('Error: uncaught exception')
    else:
        print('Error: uncaught exception')
Esempio n. 9
0
def game_loop():
    start = view.start_up_menu()
    if start == "s":
        (user_name, password) = view.sign_up_menu()
        model.sign_up(user_name, password)
    else:
        (user_name, password) = view.logg_in_menu()
        _id = model.user_check(password)
        print(_id)

    while 1:
        buy_inputs = ['b', 'buy']
        sell_inputs = ['s', 'sell']
        lookup_inputs = ['l', 'lookup', 'look up', 'look-up']
        quote_inputs = ['q', 'quote']
        exit_inputs = ['e', 'exit', 'quit']
        view_inputs = ['v']
        acceptable_inputs = buy_inputs     \
                            +sell_inputs   \
                            +lookup_inputs \
                            +quote_inputs  \
                            +exit_inputs   \
                            +view_inputs
        user_input = view.main_menu()
        if user_input in acceptable_inputs:
            if user_input in buy_inputs:
                balance = model.check_balance(user_name)
                fee = 6.25
                ticker_symbol = view.quote_menu()
                price = model.quote(ticker_symbol)
                trade_volume = view.transaction_menu(balance, ticker_symbol,
                                                     price)
                transaction_cost = (float(trade_volume) * price) + fee
                if transaction_cost <= balance:
                    balance -= transaction_cost
                    model.update_cash(user_name, balance)
                    model.buy(user_name, ticker_symbol, float(trade_volume),
                              float(price))
                    model.buy_holdings(user_name, ticker_symbol,
                                       float(trade_volume), price)
                else:
                    print("Not enough monay")

            elif user_input in sell_inputs:
                ticker_symbol = view.quote_menu()
                price = model.quote(ticker_symbol)
                trade_volume = view.sell_menu()
                owned = model.check_holdings(user_name, ticker_symbol)
                if owned and int(trade_volume) <= owned:
                    model.sell_holdings(user_name, ticker_symbol, trade_volume,
                                        price, owned)

            elif user_input in lookup_inputs:
                return model.lookup(view.lookup_menu())
            elif user_input in quote_inputs:
                return model.quote(view.quote_menu())
            elif user_input in view_inputs:
                users = model.get_users()
                users_list = [
                ]  # this is a list of all the users that currenttly have holdings
                for i in users:
                    users_list.append(i[0])

                users_holdings = [
                ]  # users holdings by tickers but not numbers
                for i in users_list:
                    user_holdings = model.get_holdings(i)
                    a = []
                    for i in user_holdings:
                        a.append(i[0])
                    users_holdings.append(a)

                tickers = [
                ]  # is all the stocks the users, un "set'd" and joinined together
                for i in users_holdings:
                    for j in i:
                        tickers.append(j)
                prices = {
                }  # this has all the prices for all the stocks owned in the holdings
                for i in set(tickers):  #
                    price = model.quote(i)
                    prices[i] = price

                volumes = [
                ]  # a list of lists of amount of stock each of them own
                for i in users_list:
                    volumes.append(model.holdings_volumes(i))
                # print(users_holdings)
                # print(volumes)
                values_final = {}
                for i in range(len(users_holdings)):
                    total = 0
                    for j in range(len(users_holdings[i])):
                        total += (prices[users_holdings[i][j]]) * (
                            volumes[i][j][0])
                    values_final[users_list[i]] = total
                highest = 0
                sorted_words = {}
                while values_final:
                    for i in values_final:
                        if values_final[i] >= highest:
                            highest = values_final[i]
                            word = i
                    sorted_words[word] = highest
                    values_final.pop(i)
                    highest = 0
                for i in sorted_words:
                    print("{} : {}".format(i, sorted_words[i]))
                    # highest = 0
                # while values_final:
                #     for i in range(len(values))
                #     if values[i]

                # need to add total balance
                #work vwamp

            elif user_input in exit_inputs:
                break
Esempio n. 10
0
     balance = model.get_balance(pk)
     holdings = model.get_holdings(pk)
     view.show_status(balance, holdings)
     view.pause()
 elif option.strip() == '3':
     ticker_symbol, number_of_shares = view.sell_menu()
     status = model.sell(pk, ticker_symbol, number_of_shares)
     if status == False:
         view.sell_error()
         view.pause()
     else:
         view.sell_good()
         view.pause()
 elif option.strip() == '5':
     ticker_symbol = view.quote_prompt()
     quote = model.quote(ticker_symbol)
     view.display_quote(ticker_symbol, quote)
     view.pause()
 elif option.strip() == "2":
     account_pk = pk
     ticker_symbol = view.getsymbol()
     number_of_shares = view.volume()
     finalbuy = model.buy(account_pk, ticker_symbol, number_of_shares)
     if finalbuy == False:
         view.failuremessage()
     else:
         view.successmessage()
 elif option.strip() == "4":
     account_pk = pk
     ticker_symbol = view.ticker_request()
     orders = model.get_orders(account_pk, ticker_symbol)