test_performance_command.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. #!/usr/bin/env python3
  2. """
  3. Test script to demonstrate the new /performance command functionality.
  4. """
  5. def demo_performance_ranking():
  6. """Demo what the performance ranking will look like."""
  7. print("🏆 Token Performance Ranking Demo")
  8. print("=" * 50)
  9. # Mock token performance data (sorted by P&L)
  10. token_performance = {
  11. 'BTC': {
  12. 'total_pnl': 150.75,
  13. 'pnl_percentage': 5.2,
  14. 'completed_trades': 8,
  15. 'win_rate': 75.0
  16. },
  17. 'ETH': {
  18. 'total_pnl': 45.30,
  19. 'pnl_percentage': 3.1,
  20. 'completed_trades': 5,
  21. 'win_rate': 60.0
  22. },
  23. 'SOL': {
  24. 'total_pnl': -25.40,
  25. 'pnl_percentage': -2.8,
  26. 'completed_trades': 3,
  27. 'win_rate': 33.3
  28. }
  29. }
  30. sorted_tokens = sorted(
  31. token_performance.items(),
  32. key=lambda x: x[1]['total_pnl'],
  33. reverse=True
  34. )
  35. print("🏆 Token Performance Ranking\n")
  36. for i, (token, stats) in enumerate(sorted_tokens, 1):
  37. # Ranking emoji
  38. if i == 1:
  39. rank_emoji = "🥇"
  40. elif i == 2:
  41. rank_emoji = "🥈"
  42. elif i == 3:
  43. rank_emoji = "🥉"
  44. else:
  45. rank_emoji = f"#{i}"
  46. # P&L emoji
  47. pnl_emoji = "🟢" if stats['total_pnl'] >= 0 else "🔴"
  48. print(f"{rank_emoji} {token}")
  49. print(f" {pnl_emoji} P&L: ${stats['total_pnl']:,.2f} ({stats['pnl_percentage']:+.1f}%)")
  50. print(f" 📊 Trades: {stats['completed_trades']} | Win: {stats['win_rate']:.0f}%")
  51. print()
  52. # Summary
  53. total_pnl = sum(stats['total_pnl'] for stats in token_performance.values())
  54. total_trades = sum(stats['completed_trades'] for stats in token_performance.values())
  55. total_pnl_emoji = "🟢" if total_pnl >= 0 else "🔴"
  56. print("💼 Portfolio Summary:")
  57. print(f" {total_pnl_emoji} Total P&L: ${total_pnl:,.2f}")
  58. print(f" 📈 Tokens Traded: {len(token_performance)}")
  59. print(f" 🔄 Completed Trades: {total_trades}")
  60. print()
  61. print("💡 Usage: /performance BTC for detailed BTC stats")
  62. def demo_detailed_performance():
  63. """Demo what detailed token performance will look like."""
  64. print("\n📊 BTC Detailed Performance Demo")
  65. print("=" * 50)
  66. # Mock detailed BTC stats
  67. token_stats = {
  68. 'token': 'BTC',
  69. 'total_pnl': 150.75,
  70. 'pnl_percentage': 5.2,
  71. 'completed_volume': 2900.00,
  72. 'expectancy': 18.84,
  73. 'total_trades': 12,
  74. 'completed_trades': 8,
  75. 'buy_trades': 6,
  76. 'sell_trades': 6,
  77. 'win_rate': 75.0,
  78. 'profit_factor': 3.2,
  79. 'total_wins': 6,
  80. 'total_losses': 2,
  81. 'largest_win': 85.50,
  82. 'largest_loss': 32.20,
  83. 'avg_win': 42.15,
  84. 'avg_loss': 28.75,
  85. 'recent_trades': [
  86. {
  87. 'side': 'buy',
  88. 'value': 500,
  89. 'timestamp': '2023-12-01T10:30:00',
  90. 'pnl': 0
  91. },
  92. {
  93. 'side': 'sell',
  94. 'value': 500,
  95. 'timestamp': '2023-12-01T14:15:00',
  96. 'pnl': 45.20
  97. },
  98. {
  99. 'side': 'buy',
  100. 'value': 300,
  101. 'timestamp': '2023-12-01T16:45:00',
  102. 'pnl': 0
  103. }
  104. ]
  105. }
  106. pnl_emoji = "🟢" if token_stats['total_pnl'] >= 0 else "🔴"
  107. print(f"📊 {token_stats['token']} Detailed Performance\n")
  108. print("💰 P&L Summary:")
  109. print(f"• {pnl_emoji} Total P&L: ${token_stats['total_pnl']:,.2f} ({token_stats['pnl_percentage']:+.2f}%)")
  110. print(f"• 💵 Total Volume: ${token_stats['completed_volume']:,.2f}")
  111. print(f"• 📈 Expectancy: ${token_stats['expectancy']:,.2f}")
  112. print()
  113. print("📊 Trading Activity:")
  114. print(f"• Total Trades: {token_stats['total_trades']}")
  115. print(f"• Completed: {token_stats['completed_trades']}")
  116. print(f"• Buy Orders: {token_stats['buy_trades']}")
  117. print(f"• Sell Orders: {token_stats['sell_trades']}")
  118. print()
  119. print("🏆 Performance Metrics:")
  120. print(f"• Win Rate: {token_stats['win_rate']:.1f}%")
  121. print(f"• Profit Factor: {token_stats['profit_factor']:.2f}")
  122. print(f"• Wins: {token_stats['total_wins']} | Losses: {token_stats['total_losses']}")
  123. print()
  124. print("💡 Best/Worst:")
  125. print(f"• Largest Win: ${token_stats['largest_win']:,.2f}")
  126. print(f"• Largest Loss: ${token_stats['largest_loss']:,.2f}")
  127. print(f"• Avg Win: ${token_stats['avg_win']:,.2f}")
  128. print(f"• Avg Loss: ${token_stats['avg_loss']:,.2f}")
  129. print()
  130. print("🔄 Recent Trades:")
  131. for trade in token_stats['recent_trades'][-3:]:
  132. side_emoji = "🟢" if trade['side'] == 'buy' else "🔴"
  133. pnl_display = f" | P&L: ${trade['pnl']:.2f}" if trade['pnl'] != 0 else ""
  134. print(f"• {side_emoji} {trade['side'].upper()} ${trade['value']:,.0f} @ 12/01 10:30{pnl_display}")
  135. print()
  136. print("🔄 Use /performance to see all token rankings")
  137. def demo_no_data_scenarios():
  138. """Demo what happens when there's no trading data."""
  139. print("\n📭 No Data Scenarios Demo")
  140. print("=" * 50)
  141. print("1. No trading data at all:")
  142. print("📊 Token Performance\n")
  143. print("📭 No trading data available yet.\n")
  144. print("💡 Performance tracking starts after your first completed trades.")
  145. print("Use /long or /short to start trading!")
  146. print()
  147. print("2. No trading history for specific token:")
  148. print("📊 SOL Performance\n")
  149. print("📭 No trading history found for SOL.\n")
  150. print("💡 Start trading SOL with:")
  151. print("• /long SOL 100")
  152. print("• /short SOL 100")
  153. print()
  154. print("🔄 Use /performance to see all token rankings.")
  155. print()
  156. print("3. Open positions but no completed trades:")
  157. print("📊 ETH Performance\n")
  158. print("ETH has open positions but no completed trades yet\n")
  159. print("📈 Current Activity:")
  160. print("• Total Trades: 3")
  161. print("• Buy Orders: 2")
  162. print("• Sell Orders: 1")
  163. print("• Volume: $1,500.00")
  164. print()
  165. print("💡 Complete some trades to see P&L statistics!")
  166. print("🔄 Use /performance to see all token rankings.")
  167. if __name__ == "__main__":
  168. print("🚀 Performance Command Demo")
  169. print("=" * 60)
  170. demo_performance_ranking()
  171. demo_detailed_performance()
  172. demo_no_data_scenarios()
  173. print("\n" + "=" * 60)
  174. print("✅ Key Features:")
  175. print("• Token performance ranking (best to worst P&L)")
  176. print("• Detailed stats for specific tokens")
  177. print("• Win rate, profit factor, expectancy calculations")
  178. print("• Recent trade history included")
  179. print("• Mobile-friendly compressed and detailed views")
  180. print("• Handles cases with no data gracefully")
  181. print("• Easy navigation between ranking and details")
  182. print("\n💡 Usage:")
  183. print("• /performance - Show all token rankings")
  184. print("• /performance BTC - Show detailed BTC stats")
  185. print("• /performance ETH - Show detailed ETH stats")