#!/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("šŸ“ˆ Open Positions\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")