def post(self): """ Called when we have a POST request Returns: BaseResponse object with message and code """ data = request.get_json() is_ok, result = helper.validation(schemas.transfer_schema, data) if not is_ok: return result users_exist = usr_ex1 and usr_ex2 user_1_data = data["user1"] user_2_data = data["user2"] amount = data["amount"] username_1 = user_1_data["username"] username_2 = user_2_data["username"] try: helper.balance_validation(username_1, username_2) except ValueError as ex: return jsonify({"message": ex.args[0], "code": ex.args[1]}) helper.update_balance(config.users, user_1_data["username"], amount, balance_acc1, operator.sub) helper.update_balance(config.users, user_2_data["username"], amount, balance_acc2, operator.add) helper.update_tokens(config.users, user_1_data["username"], 1, operator.sub) return jsonify({ "Message": "Transaction completed successfully.", "Code": config.OK })
def post(self): """ Called when we have a POST request. Returns: BaseResponse object with message and code """ # taking data from server data = request.get_json() validation, result = helper.validation(config.users, schemas.update_balance_schema, data, config.update_balance_keys) if not validation: return jsonify(result) username, _, code, amount = result # add deposit to current money money_curr = config.users.find({"Username": username})[0]["Balance"] if amount <= 0: return jsonify({ "Message": "Amount must be greather than zero.", "Code": config.INVALID_AMOUNT }) # if code that is sent from user is not # 'D' for deposit or 'W' for withdraw # than we want to sent error to user # otherwise, we want to preform operation (deposit or withdraw) if code == "D": helper.update_balance(config.users, username, amount, money_curr, operator.add) elif code == "W": if amount > money_curr: return jsonify({ "Message": "You don't have enough money", "Code": config.NOT_ENOUGH_MONEY }) helper.update_balance(config.users, username, amount, money_curr, operator.sub) else: return jsonify({ "Message": "For withdraw enter 'W', for deposit enter 'D'", "Code": config.INVALID_CODE }) # remove one token helper.update_tokens(config.users, username, 1, operator.sub) return jsonify({ "Message": "You successfully updated your balance.", "Code": config.OK })
def withdraw(account): print("") print("Enter Amount to be Withdrawn: ") amount = float(input("£")) print("") account.balance -= amount update_balance(account, amount) print("") print("Withdrawal Successful") print("Your New Balance is: ") print("£{:,.2f}".format(account.balance)) print("") show_account_options(account)
def deposit(account): print("") print("Enter Amount to be Deposited: ") amount = float(input("£")) print("") account.balance += amount update_balance(account, amount) print("") print("Deposit Successful") print("Your New Balance is: ") print("£{:,.2f}".format(account.balance)) print("") show_account_options(account)
def make_deposit(self, deposit): balance = helper.retrieve_balance() amount = deposit # int(input('Enter amount to deposit:')) new_balances = (balance + amount) helper.update_balance(new_balances) print(f"Your new balance is: {new_balances}") if new_balances == balance + amount: self.is_success = 'YES' else: self.is_success = 'NO' # helper.receipt_or_nah() self.stop_time = dt.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
def post(self): """ Called when we have a POST request Returns: BaseResponse object with message and code """ data = request.get_json() is_valid, result = helper.validation(config.users, schemas.loan_schema, data, config.loan_keys) if not is_valid: return jsonify(result) username = data["username"] balance_usr = helper.find_balance(username) amount = data["amount"] bank_balance = helper.find_balance(config.bank_name) helper.update_balance(config.bank, config.bank_name, amount, bank_balance, operator.add) helper.update_balance(config.users, username, amount, balance_usr, operator.sub) return jsonify({ "Message": "Transaction successfully terminated.", "Code": config.OK })
def test_update_balance(self): account = generate_dummy_account() account.balance += 50.55 update_balance(account, account.balance) self.assertEqual(account.balance, 150.55)
best_choice['Stock']].tolist()[0] stocks_bought.at[i, 'volume'] += xvol stocks_bought.at[i, 'pricepaid'] = pricepaid else: stocks_bought = stocks_bought.append( { 'stocks': best_choice['Stock'], 'volume': xvol, 'pricepaid': pricepaid }, ignore_index=True) N += 1 print(N, "----", profit['profit'].iloc[-1], "----") ## I SHOULD UPDATE MY BALANCE IN THE END balanceSum = update_balance(df, stocks_bought, datetrack, profit['profit'].iloc[-1]) bal = bal.append({ 'date': datetrack, 'balance': balanceSum }, ignore_index=True) if break_flag == True: break daterange = pd.date_range( start=datetrack, periods=T) # πρέπει να επιστρέφω updated datetrack write_to_file(N, moves_history) plot_profit_balance(profit, bal)