123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #!/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")
|