def test_user_can_deposit(self):
        # Arrange
        account = Account("Alan", "33")
        expected_result = 100

        # Act
        account.deposit(100)
        observed = account.balance

        # Assert
        self.assertEqual(observed, expected_result)
Exemple #2
0
def deposit(name, password, amount):
    if not Account.login(name, password):
        msg = "Invalid login credentials, pls retry"
    else:
        pk = Account.login(name, password).pk
        account_deposit = Account(pk=pk)
        new_bal = account_deposit.deposit(float(amount))
        account_deposit.save()
        msg = "New Balance = {}".format(new_bal)
    return jsonify({'message': msg})
Exemple #3
0
def deposit(key, amount):
    if Account.api_authenticate(key) == None:
        msg = "Invalid login credentials, pls retry"
    else:
        #pk = Account.login(name, password).pk
        pk = Account.api_authenticate(key).pk
        account_deposit = Account(pk=pk)
        new_bal = account_deposit.deposit(float(amount))
        account_deposit.save()
        msg = "New Balance = {}".format(new_bal)
    return jsonify({'message': msg})
Exemple #4
0
def deposit(api_key):
    if Account.api_authenticate(api_key) == None:
        msg = "Invalid login credentials, pls retry"
    else: 
        if not request.json or 'amount' not in request.json:
            return jsonify({"error": "bad request"}), 400
        pk = Account.api_authenticate(api_key).pk
        account_deposit = Account(pk=pk)
        new_bal = account_deposit.deposit(float(request.json['amount']))
        account_deposit.save()
        msg = "New Balance = {}".format(new_bal)
    return jsonify({'message':msg})    
def main():
    while True:
        views.generic_msg("Welcome to Terminal Trader !")
        selection = views.welcome_menu()
        if selection is None:  #Bad input
            views.generic_msg(
                "Please enter a number that corresponds to a stated option")
        elif selection == 3:  #Exit
            views.generic_msg("Bye: Thanks for using Terminal Trader")
            break
        elif selection == 1:  #Create account
            new_username = views.get_input("Username")
            new_password = views.get_input("Password")
            new_account = Account(username=new_username)
            new_account.set_password(new_password)
            new_account.save()
        elif selection == 2:  #Login
            login_username = views.get_input("Username")
            login_password = views.get_input("Password")
            if not Account.login(login_username, login_password):
                views.generic_msg(
                    "Failed to find an account for the given Username/Password, pls retry"
                )
            else:  #Store account pk for re-use
                pk = Account.login(login_username, login_password).pk
                while True:
                    choice = views.main_menu()
                    if choice is None:  #Bad input
                        views.generic_msg(
                            "Please enter a number that corresponds \
                                           to a stated option")
                    elif choice == 8:  #Exit
                        break
                    elif choice == 1:  #View Balance & Positions
                        positions_sub_menu(pk)
                    elif choice == 2:  #Deposit money
                        deposit_amount = float(
                            views.get_input("Deposit Amount"))
                        account_deposit = Account(pk=pk)
                        new_bal = account_deposit.deposit(deposit_amount)
                        account_deposit.save()
                        views.generic_msg("New Balance = {}".format(new_bal))
                    elif choice == 3:  #Look up stock price
                        ticker = views.get_input(
                            "Please enter a Ticker Symbol")
                        quote = util.get_price(ticker)
                        if not quote:
                            views.generic_msg(
                                "The Ticker Symbol entered does not exist")
                        else:
                            views.stock_price(ticker, quote)
                    elif choice == 4:  #Look up ticker from Co. name
                        co_name = views.get_input("Please enter Company Name")
                        companies = util.get_ticker(co_name)
                        if not companies:
                            views.generic_msg(
                                "No matches for input Company Name")
                        else:
                            for co in companies:
                                views.show_companies(co)
                    elif choice == 5:  #Buy stock
                        ticker = views.get_input(
                            "Please enter a Ticker Symbol")
                        shares_buy = views.get_input(
                            "Please enter the number of shares to buy")
                        buy_txn = Account(pk=pk)
                        buy_txn.buy(ticker, shares_buy)
                        views.generic_msg("Buy transaction complete")
                    elif choice == 6:  #Sell stock
                        ticker = views.get_input(
                            "Please enter a Ticker Symbol")
                        shares_sell = views.get_input(
                            "Please enter the number of shares to sell")
                        sell_txn = Account(pk=pk)
                        sell_txn.sell(ticker, shares_sell)
                        views.generic_msg("Sell transaction complete")
                    elif choice == 7:  #View Trade History
                        trades_sub_menu(pk)
def main():
    while True:
        selection = views.welcome_menu()
        if selection is None:
            #Bad input
            views.generic_msg(
                "Please enter a number that corresponds to a stated option")
        elif selection == 3:
            #Exit
            views.generic_msg("Bye: Thanks for using Terminal Trader")
            break
        elif selection == 1:
            #Create account
            new_username = views.get_input("Username")
            new_password = views.get_input("Password")
            new_account = Account(username=new_username)
            new_account.set_password(new_password)
            new_account.save()
        elif selection == 2:
            #Login
            login_username = views.get_input("Username")
            login_password = views.get_input("Password")
            if not Account.login(login_username, login_password):
                views.generic_msg(
                    "Failed to find an account for the given Username/Password, pls retry"
                )
            else:
                #Retrieve account balance & pk for re-use
                balance = Account()
                current_bal, pk = balance.get_bal(login_username,
                                                  login_password)
                while True:
                    choice = views.main_menu()
                    if choice is None:
                        #Bad input
                        views.generic_msg(
                            "Please enter a number that corresponds to a stated option"
                        )
                    elif choice == 7:
                        #Exit
                        break
                    elif choice == 1:  #View Balance & Positions
                        views.generic_msg(
                            "Your current balance = {}".format(current_bal))
                        while True:
                            position_choice = views.position_menu()
                            if position_choice is None:
                                #Bad input
                                views.generic_msg(
                                    "Please enter a number that corresponds to a stated option"
                                )
                            elif position_choice == 3:
                                #Exit
                                break
                            elif position_choice == 1:
                                #Retrieve and display a given position, taking in a ticker symbol
                                ticker = views.get_input(
                                    "Please enter a Ticker Symbol")
                                user_position = Account(pk=pk)
                                position = user_position.get_position_for(
                                    ticker)
                                views.show_positions(position)
                            elif position_choice == 2:
                                #Retrieve and display all positions
                                user_positions = Account(pk=pk)
                                positions = user_positions.get_positions()
                                for position in positions:
                                    views.show_positions(position)
                    elif choice == 2:  #Deposit money
                        deposit_amount = float(
                            views.get_input("Deposit Amount"))
                        account_deposit = Account()
                        new_bal = account_deposit.deposit(
                            login_username, login_password, deposit_amount)
                        account_deposit.save()
                        views.generic_msg("New Balance = {}".format(new_bal))
                    elif choice == 3:  #Look up stock price
                        ticker = views.get_input(
                            "Please enter a Ticker Symbol")
                        print(util.get_price(ticker))
                    elif choice == 4:  #Buy stock
                        ticker = views.get_input(
                            "Please enter a Ticker Symbol")
                        shares_buy = views.get_input(
                            "Please enter the number of shares to buy")

                    elif choice == 5:  #Sell stock
                        ticker = views.get_input(
                            "Please enter a Ticker Symbol")
                        shares_sell = views.get_input(
                            "Please enter the number of shares to sell")
                    elif choice == 6:  #View Trade History
                        while True:
                            trade_choice = views.trades_menu()
                            if trade_choice is None:
                                #Bad input
                                views.generic_msg(
                                    "Please enter a number that corresponds to a stated option"
                                )
                            elif trade_choice == 3:
                                #Exit
                                break
                            elif trade_choice == 1:
                                #Retrieve and display trades re a give ticker symbol
                                ticker = views.get_input(
                                    "Please enter a Ticker Symbol")
                                user_trade = Account(pk=pk)
                                trades = user_trade.get_trades_for(ticker)
                                views.show_trades(trades)
                            elif trade_choice == 2:
                                #Retrieve and display all trades
                                user_trades = Account(pk=pk)
                                trades = user_trades.get_trades()
                                for trade in trades:
                                    views.show_trades(trade)
 def testDeposit(self):
     greg = Account("Greg")
     greg.balance = 5002.00
     greg.deposit(5000.00)
     self.assertEqual(greg.balance, 10002.00)