demo_stats.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/usr/bin/env python3
  2. """
  3. Trading Statistics Demo
  4. Shows sample trading statistics to demonstrate what the bot tracks.
  5. """
  6. from src.stats import TradingStats
  7. from datetime import datetime, timedelta
  8. import random
  9. def create_demo_stats():
  10. """Create demo trading statistics."""
  11. print("📊 Creating Demo Trading Statistics...\n")
  12. # Create stats instance with demo file
  13. stats = TradingStats("demo_stats.json")
  14. # Set initial balance
  15. initial_balance = 1000.0
  16. stats.set_initial_balance(initial_balance)
  17. # Simulate some trades over 30 days
  18. current_balance = initial_balance
  19. base_time = datetime.now() - timedelta(days=30)
  20. print("🎲 Simulating 30 days of trading...")
  21. # Generate sample trades
  22. symbols = ["BTC/USDC:USDC", "ETH/USDC:USDC"]
  23. for day in range(30):
  24. date = base_time + timedelta(days=day)
  25. # 70% chance of trading each day
  26. if random.random() < 0.7:
  27. # 1-3 trades per day
  28. num_trades = random.randint(1, 3)
  29. for _ in range(num_trades):
  30. symbol = random.choice(symbols)
  31. # Simulate buy trade
  32. if symbol == "BTC/USDC:USDC":
  33. price = random.uniform(45000, 55000)
  34. amount = random.uniform(0.001, 0.01)
  35. else: # ETH
  36. price = random.uniform(2800, 3200)
  37. amount = random.uniform(0.01, 0.1)
  38. trade_value = amount * price
  39. # Record buy
  40. stats.data['trades'].append({
  41. 'timestamp': date.isoformat(),
  42. 'symbol': symbol,
  43. 'side': 'buy',
  44. 'amount': amount,
  45. 'price': price,
  46. 'value': trade_value,
  47. 'order_id': f'demo_{len(stats.data["trades"])}',
  48. 'type': 'manual',
  49. 'pnl': 0.0
  50. })
  51. # Sometimes sell (60% chance)
  52. if random.random() < 0.6:
  53. # Sell at slightly different price
  54. sell_price = price * random.uniform(0.98, 1.05) # -2% to +5%
  55. pnl = amount * (sell_price - price)
  56. current_balance += pnl
  57. sell_date = date + timedelta(hours=random.randint(1, 12))
  58. stats.data['trades'].append({
  59. 'timestamp': sell_date.isoformat(),
  60. 'symbol': symbol,
  61. 'side': 'sell',
  62. 'amount': amount,
  63. 'price': sell_price,
  64. 'value': amount * sell_price,
  65. 'order_id': f'demo_{len(stats.data["trades"])}',
  66. 'type': 'manual',
  67. 'pnl': pnl
  68. })
  69. # Record daily balance
  70. daily_variance = random.uniform(-20, 30) # Daily balance change
  71. current_balance += daily_variance
  72. stats.data['daily_balances'].append({
  73. 'date': date.date().isoformat(),
  74. 'balance': current_balance,
  75. 'timestamp': date.isoformat()
  76. })
  77. # Save the demo data
  78. stats._save_stats()
  79. return stats, current_balance
  80. def main():
  81. """Main demo function."""
  82. print("🎮 Trading Statistics Demo\n")
  83. print("This shows what your bot will track when you start trading manually.\n")
  84. # Create demo data
  85. stats, current_balance = create_demo_stats()
  86. # Display statistics
  87. print("📈 Sample Trading Statistics:\n")
  88. stats_message = stats.format_stats_message(current_balance)
  89. # Convert HTML to plain text for terminal display
  90. plain_message = stats_message.replace('<b>', '').replace('</b>', '')
  91. plain_message = plain_message.replace('<i>', '').replace('</i>', '')
  92. print(plain_message)
  93. print("\n" + "="*60)
  94. print("🎯 What This Means:")
  95. print("✅ Your bot will track ALL these metrics automatically")
  96. print("📱 View anytime on your phone with /stats command")
  97. print("💾 Statistics persist between bot restarts")
  98. print("🔄 Every manual trade updates your performance metrics")
  99. print("📊 Professional-grade analytics from day one")
  100. print("="*60)
  101. print(f"\n📁 Demo data saved to: demo_stats.json")
  102. print("🗑️ You can delete this file - it's just for demonstration")
  103. if __name__ == "__main__":
  104. main()