Ejemplo n.º 1
0
def logged_in_homepage(account):
    
    while True:
        selection = view.logged_in_screen(account.username, account.balance)
        
        if selection not in ["1", "2", "3", "4", "5", "6", "7", "8"]:
            view.improper_selection()
            time.sleep(3)
        
        if selection == "1":
            view.account_positions(account.username)
            Account.get_positions(account)
            time.sleep(3)
        elif selection == "2":
            deposit = view.deposit_funds()
            if not deposit.isdigit() or int(deposit) < 1:
                view.improper_balance()
                time.sleep(3)
            else:
                account.balance = int(account.balance) +  int(deposit)
                account.save()
                continue
        elif selection == "3":
            ticker_request = view.request_ticker_symbol()
            ticker_response = get_price(ticker_request)
            if type(ticker_response) == list:
                view.return_ticker_symbol_price(ticker_response)
                time.sleep(3)
            else:
                view.improper_ticker()
                time.sleep(3)
        elif selection == "4":
            ticker = view.request_ticker_symbol()
            ticker_price = get_price(ticker)
            if ticker_price == False:
                view.improper_ticker()
                time.sleep(3)
                continue
                 
            purchase_amount = view.get_shares(ticker_price)
            if not purchase_amount.isdigit():
                view.improper_money()
                time.sleep(3)
                continue

            total_cost = int(purchase_amount) * int(ticker_price[1])
            
            if total_cost < int(account.balance):
                Account.buy(account, ticker, purchase_amount, ticker_price[1], total_cost)
            elif int(total_cost) > int(account.balance):
                view.not_enough_money()
                time.sleep(3)

        elif selection == "5":
            Account.get_positions(account)
            time.sleep(3)
            ticker_to_sell = view.sell_shares()
            has_stock = get_price(ticker_to_sell)
            position = account.get_position_for(ticker_to_sell)
            amount = view.sell_shares_amount()

            if has_stock and position.shares >= int(amount):
                Account.sell(account, ticker_to_sell, amount)
            elif not has_stock:
                view.improper_ticker()
                time.sleep(3)
            else:
                view.not_enough_shares()
        elif selection == "6":
            selection = view.select_trade_option(account.username)
            
            if len(selection) != 1 or selection.lower() not in ["a", "b", "c"]:
                view.improper_selection()
                time.sleep(3)
            elif selection.lower() == "a":
                account_trades = Account.get_trades(account)
                if not account_trades:
                    view.no_trades(account.username)
                    time.sleep(3)
                for trade in account_trades:
                    view.show_trades(account.username, trade)
                    time.sleep(3)
            elif selection.lower() == "b":
                ticker_symbol = view.request_ticker_symbol()
                account_trades_by_ticker = Account.trades_for(account, ticker_symbol)
               
                if get_price(ticker_symbol) == False:
                    view.improper_ticker()
                    time.sleep(3)
                elif not account_trades_by_ticker:
                    view.no_trades(account.username)
                    time.sleep(3)              
                else:
                    for trade in account_trades_by_ticker:
                        view.show_trades(account.username, trade)
                        time.sleep(3)
            elif selection.lower() == "c":
                continue
        elif selection == "7":
            view.goodbye()
            welcome_homepage()
            return
        elif selection == "8":
            view.goodbye()
            return
def logged_in_homepage(account):

    while True:
        print(account.username, account.balance)
        selection = view.logged_in_screen(account.username, account.balance)

        if selection not in ['1', '2', '3', '4', '5', '6', '7', '8', '9']:
            view.improper_selection()
            time.sleep(3)

        if selection == '1':
            Account.get_positions(account)

        elif selection == '2':
            deposit = view.deposit_funds()
            if not deposit.isdigit() or int(deposit) < 1:
                view.improper_balance()
                time.sleep(3)
            else:
                account.balance = int(account.balance) + int(deposit)
                account.save()
                continue

        elif selection == '3':
            ticker_request = view.request_ticker_symbol()
            ticker_response = get_price(ticker_request)
            if type(ticker_response) == list:
                view.return_ticker_symbol_price(ticker_response)
                time.sleep(2)
            else:
                view.improper_ticker()
                time.sleep(3)

        elif selection == '4':
            ticker = view.request_ticker_symbol()
            current_price = get_price(ticker)
            share_amount = view.get_shares(current_price)
            if share_amount:
                try:
                    Account.buy(account, ticker, share_amount, current_price)
                except ValueError:
                    view.insufficient_funds()
            else:
                view.improper_ticker()
                time.sleep(3)

        # elif selection == '5':
        #   Account.get_positions(account)
        #   # time.sleep(3)
        #   ticker_to_sell = view.sell_shares()
        #   has_stock = get_price(ticker_to_sell)
        #   print(has_stock)
        #   amount = view.sell_shares_amount()
        #   current_price = get_price(ticker_to_sell)
        #   if has_stock:
        #       Account.sell(account, ticker_to_sell, amount, current_price)
        #   else:
        #       view.improper_ticker()
        #       time.sleep(3)

        elif selection == '5':
            Account.get_positions(account)
            ticker = view.request_ticker_symbol()
            shares = int(view.sell_shares())

            try:
                Account.sell(account, ticker, shares)
            except ValueError:
                view.wups()
                time.sleep(3)
            # view.clearscreen()

        elif selection == '6':
            selection = view.select_trade_option(account.username)

            if len(selection) != 1 or selection.lower() not in ['a', 'b', 'c']:
                view.improper_selection()
                time.sleep(3)
            elif selection.lower() == 'a':
                account_trades = Account.get_trades(account)
                for trade in account_trades:
                    view.show_trades(account.username, trade)
                    time.sleep(1)
            elif selection.lower() == 'b':
                ticker_symbol = view.request_ticker_symbol()
                account_trades_by_ticker = Account.trades_for(
                    account, ticker_symbol)

                if account_trades_by_ticker:
                    for trade in account_trades_by_ticker:
                        view.show_trades(account.username, trade)
                        time.sleep(3)

                else:
                    view.improper_ticker()
                    time.sleep(3)
            elif selection.lower() == 'c':
                continue
        elif selection == '7':
            view.goodbye()
            welcome_homepage()
            return
        elif selection == '8':
            view.goodbye()
            return
        elif selection == '9':
            top_traded(
                'https://api.iextrading.com/1.0/stock/market/batch?symbols=aapl,fb&types=quote,news,chart&range=1m&last=5'
            )
            time.sleep(3)
Ejemplo n.º 3
0
def logged_in_homepage(account):

    while True:
        selection = view.logged_in_screen(account.username, account.balance)

        if selection not in ["1", "2", "3", "4", "5", "6", "7", "8", "9"]:
            view.improper_selection()
            time.sleep(3)

        if selection == "1":
            Account.get_positions(account)

        elif selection == "2":
            deposit = view.deposit_funds()
            if not deposit.isdigit() or int(deposit) < 1:
                view.improper_balance()
                time.sleep(3)
            else:
                account.balance = int(account.balance) + int(deposit)
                account.save()
                continue
        elif selection == "3":
            ticker_request = view.request_ticker_symbol()
            ticker_response = get_price(ticker_request)
            if type(ticker_response) == list:
                view.return_ticker_symbol_price(ticker_response)
                time.sleep(3)
            else:
                view.improper_ticker()
                time.sleep(3)
        elif selection == "4":
            ticker = view.request_ticker_symbol()
            current_price = get_price(ticker)
            share_amount = view.get_shares(current_price)
            if share_amount:
                try:
                    Account.buy(account, ticker, share_amount, current_price)
                except ValueError:
                    view.insufficient_funds()
            else:
                view.improper_ticker()
                time.sleep(3)

        # elif selection == "5":
        #     Account.get_positions(account)
        #     # time.sleep(3)
        #     ticker_to_sell = view.sell_shares()
        #     has_stock = get_price(ticker_to_sell)
        #     print(has_stock)
        #     amount = view.sell_shares_amount()
        #     current_price = get_price(ticker_to_sell)
        #     if has_stock:
        #         Account.sell(account, ticker_to_sell, amount, current_price)
        #     else:
        #         view.improper_ticker()
        #         time.sleep(3)

        elif selection == "5":
            Account.get_positions(account)
            ticker = view.request_ticker_symbol()
            shares = int(view.sell_shares())

            try:
                Account.sell(account, ticker, shares)
            except ValueError:
                view.wups()
                time.sleep(3)
                # view.clearscreen()

        elif selection == "6":
            selection = view.select_trade_option(account.username)

            if len(selection) != 1 or selection.lower() not in ["a", "b", "c"]:
                view.improper_selection()
                time.sleep(3)
            elif selection.lower() == "a":
                account_trades = Account.get_trades(account)
                for trade in account_trades:
                    view.show_trades(account.username, trade)
                    time.sleep(1)
            elif selection.lower() == "b":
                ticker_symbol = view.request_ticker_symbol()
                account_trades_by_ticker = Account.trades_for(
                    account, ticker_symbol)

                if account_trades_by_ticker:
                    for trade in account_trades_by_ticker:
                        view.show_trades(account.username, trade)
                        time.sleep(3)

                else:
                    view.improper_ticker()
                    time.sleep(3)
            elif selection.lower() == "c":
                continue
        elif selection == "7":
            view.goodbye()
            welcome_homepage()
            return
        elif selection == "8":
            view.goodbye()
            return
        elif selection == "9":
            top_traded(
                "https://api.iextrading.com/1.0/stock/market/batch?symbols=aapl,fb&types=quote,news,chart&range=1m&last=5"
            )
            time.sleep(3)