123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- #!/usr/bin/env python3
- """
- Trading Statistics Demo
- Shows sample trading statistics to demonstrate what the bot tracks.
- """
- import sys
- from pathlib import Path
- from datetime import datetime, timedelta
- import random
- # Add src directory to Python path
- sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
- from trading_stats import TradingStats
- def create_demo_stats():
- """Create demo trading statistics."""
- print("📊 Creating Demo Trading Statistics...\n")
-
- # Create stats instance with demo file
- stats = TradingStats("demo_stats.json")
-
- # Set initial balance
- initial_balance = 1000.0
- stats.set_initial_balance(initial_balance)
-
- # Simulate some trades over 30 days
- current_balance = initial_balance
- base_time = datetime.now() - timedelta(days=30)
-
- print("🎲 Simulating 30 days of trading...")
-
- # Generate sample trades
- symbols = ["BTC/USDC:USDC", "ETH/USDC:USDC"]
-
- for day in range(30):
- date = base_time + timedelta(days=day)
-
- # 70% chance of trading each day
- if random.random() < 0.7:
- # 1-3 trades per day
- num_trades = random.randint(1, 3)
-
- for _ in range(num_trades):
- symbol = random.choice(symbols)
-
- # Simulate buy trade
- if symbol == "BTC/USDC:USDC":
- price = random.uniform(45000, 55000)
- amount = random.uniform(0.001, 0.01)
- else: # ETH
- price = random.uniform(2800, 3200)
- amount = random.uniform(0.01, 0.1)
-
- trade_value = amount * price
-
- # Record buy
- stats.data['trades'].append({
- 'timestamp': date.isoformat(),
- 'symbol': symbol,
- 'side': 'buy',
- 'amount': amount,
- 'price': price,
- 'value': trade_value,
- 'order_id': f'demo_{len(stats.data["trades"])}',
- 'type': 'manual',
- 'pnl': 0.0
- })
-
- # Sometimes sell (60% chance)
- if random.random() < 0.6:
- # Sell at slightly different price
- sell_price = price * random.uniform(0.98, 1.05) # -2% to +5%
- pnl = amount * (sell_price - price)
- current_balance += pnl
-
- sell_date = date + timedelta(hours=random.randint(1, 12))
-
- stats.data['trades'].append({
- 'timestamp': sell_date.isoformat(),
- 'symbol': symbol,
- 'side': 'sell',
- 'amount': amount,
- 'price': sell_price,
- 'value': amount * sell_price,
- 'order_id': f'demo_{len(stats.data["trades"])}',
- 'type': 'manual',
- 'pnl': pnl
- })
-
- # Record daily balance
- daily_variance = random.uniform(-20, 30) # Daily balance change
- current_balance += daily_variance
-
- stats.data['daily_balances'].append({
- 'date': date.date().isoformat(),
- 'balance': current_balance,
- 'timestamp': date.isoformat()
- })
-
- # Save the demo data
- stats._save_stats()
-
- return stats, current_balance
- def main():
- """Main demo function."""
- print("🎮 Trading Statistics Demo\n")
- print("This shows what your bot will track when you start trading manually.\n")
-
- # Create demo data
- stats, current_balance = create_demo_stats()
-
- # Display statistics
- print("📈 Sample Trading Statistics:\n")
- stats_message = stats.format_stats_message(current_balance)
-
- # Convert HTML to plain text for terminal display
- plain_message = stats_message.replace('<b>', '').replace('</b>', '')
- plain_message = plain_message.replace('<i>', '').replace('</i>', '')
-
- print(plain_message)
-
- print("\n" + "="*60)
- print("🎯 What This Means:")
- print("✅ Your bot will track ALL these metrics automatically")
- print("📱 View anytime on your phone with /stats command")
- print("💾 Statistics persist between bot restarts")
- print("🔄 Every manual trade updates your performance metrics")
- print("📊 Professional-grade analytics from day one")
- print("="*60)
-
- print(f"\n📁 Demo data saved to: demo_stats.json")
- print("🗑️ You can delete this file - it's just for demonstration")
- if __name__ == "__main__":
- main()
|