def leaderboard_stats_by_acct(self, account_pk, username): positions = Position.all_from_account(account_pk) stock_mv = [] for x in positions: if x.total_quantity > 0: stock_mv.append(x.value()) print( f"Account pk: {account_pk}, Username: {username}, Total Stock Value: ${round(sum(stock_mv),2)}, Cash Balance: ${round(self.balance,2)}, Total Portfolio Value: ${round(sum(stock_mv),2)+round(self.balance,2)}" )
def show_holdings_by_account(self): positions = Position.all_from_account(self.pk) if positions == []: print("\nYou do not have any positions.\n") else: stock_mv = [] for position in positions: if position.total_quantity > 0: print( f"""Ticker: {position.ticker.upper()} Quantity: {position.total_quantity} Market Value: ${round(position.value(),2)}""" ) stock_mv.append(position.value()) print( f"\nTotal Market Value of Stock Holdings: ${round(sum(stock_mv),2)}" ) print(f"Cash Balance in Account: ${round(self.balance,2)}") print( f"Total Value of Your Portfolio: ${(sum(stock_mv)+round(self.balance,2))}\n\n" )
def test_all_from_account(self): result = Position.all_from_account(jimid) self.assertEqual(len(result), 1, "all_from_account func returns list with correct number of elements 1 is from seed") self.assertIsInstance(result[0], Position, "all_from_account func returns position object") self.assertEqual(result[0].total_quantity, 5, "all_from_account func populates attributes")