demo_stats.py 4.7 KB

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