#!/usr/bin/env python3 """ Test script to demonstrate the enhanced positions display with P&L percentages. """ def demo_positions_display(): """Demo what the enhanced positions message will look like.""" print("š Enhanced Positions Display Demo") print("=" * 50) # Mock position data positions = [ { 'symbol': 'BTC/USDC:USDC', 'contracts': 0.05, # Long position 'entryPx': 45000, 'unrealizedPnl': 1250 }, { 'symbol': 'ETH/USDC:USDC', 'contracts': -2.0, # Short position 'entryPx': 3000, 'unrealizedPnl': -150 }, { 'symbol': 'SOL/USDC:USDC', 'contracts': 10.0, # Long position 'entryPx': 100, 'unrealizedPnl': 75 } ] print("š <b>Open Positions</b>\n") total_unrealized = 0 total_position_value = 0 for position in positions: symbol = position['symbol'] contracts = float(position['contracts']) unrealized_pnl = float(position['unrealizedPnl']) entry_price = float(position['entryPx']) # Calculate position value and P&L percentage position_value = abs(contracts) * entry_price pnl_percentage = (unrealized_pnl / position_value * 100) if position_value > 0 else 0 pnl_emoji = "š¢" if unrealized_pnl >= 0 else "š“" # Extract token name for cleaner display token = symbol.split('/')[0] if '/' in symbol else symbol position_type = "LONG" if contracts > 0 else "SHORT" print(f"š {token} ({position_type})") print(f" š Size: {abs(contracts):.6f} {token}") print(f" š° Entry: ${entry_price:,.2f}") print(f" šµ Value: ${position_value:,.2f}") print(f" {pnl_emoji} P&L: ${unrealized_pnl:,.2f} ({pnl_percentage:+.2f}%)") print() total_unrealized += unrealized_pnl total_position_value += position_value # Calculate overall P&L percentage total_pnl_percentage = (total_unrealized / total_position_value * 100) if total_position_value > 0 else 0 total_pnl_emoji = "š¢" if total_unrealized >= 0 else "š“" print(f"š¼ Total Portfolio:") print(f" šµ Total Value: ${total_position_value:,.2f}") print(f" {total_pnl_emoji} Total P&L: ${total_unrealized:,.2f} ({total_pnl_percentage:+.2f}%)") def demo_comparison(): """Show before vs after comparison.""" print("\nš Before vs After Comparison") print("=" * 50) print("BEFORE (old format):") print("š BTC/USDC:USDC") print(" š Size: 0.05 contracts") print(" š° Entry: $45,000.00") print(" š¢ PnL: $1,250.00") print() print("š¼ Total Unrealized P&L: $1,175.00") print("\nAFTER (enhanced format):") print("š BTC (LONG)") print(" š Size: 0.050000 BTC") print(" š° Entry: $45,000.00") print(" šµ Value: $2,250.00") print(" š¢ P&L: $1,250.00 (+55.56%)") print() print("š¼ Total Portfolio:") print(" šµ Total Value: $8,250.00") print(" š¢ Total P&L: $1,175.00 (+14.24%)") if __name__ == "__main__": print("š Enhanced Positions Display Test") print("=" * 60) demo_positions_display() demo_comparison() print("\n" + "=" * 60) print("ā Enhanced features:") print("⢠Shows position direction (LONG/SHORT)") print("⢠Displays token names instead of full symbols") print("⢠Shows position size in token units") print("⢠Adds position value for context") print("⢠P&L shown as both $ and % for easy assessment") print("⢠Total portfolio value and P&L percentage") print("⢠Clean, mobile-friendly formatting")