test_stop_loss_config.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #!/usr/bin/env python3
  2. """
  3. Test script to demonstrate the stop loss configuration and functionality.
  4. This script shows how the automatic stop loss system would work.
  5. """
  6. import sys
  7. import os
  8. sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
  9. from config import Config
  10. def test_stop_loss_config():
  11. """Test and display stop loss configuration."""
  12. print("🛡️ Stop Loss Configuration Test")
  13. print("=" * 50)
  14. # Display current configuration
  15. print(f"📊 Risk Management Enabled: {Config.RISK_MANAGEMENT_ENABLED}")
  16. print(f"🛑 Stop Loss Percentage: {Config.STOP_LOSS_PERCENTAGE}%")
  17. print(f"⏰ Monitoring Interval: {Config.BOT_HEARTBEAT_SECONDS} seconds")
  18. print()
  19. # Simulate position scenarios
  20. scenarios = [
  21. {
  22. 'name': 'Long BTC Position',
  23. 'position_type': 'long',
  24. 'entry_price': 45000,
  25. 'current_prices': [44000, 42000, 40500, 39000],
  26. 'position_size': 0.1
  27. },
  28. {
  29. 'name': 'Short ETH Position',
  30. 'position_type': 'short',
  31. 'entry_price': 3000,
  32. 'current_prices': [3100, 3200, 3300, 3400],
  33. 'position_size': 2.0
  34. }
  35. ]
  36. for scenario in scenarios:
  37. print(f"📋 Scenario: {scenario['name']}")
  38. print(f" Direction: {scenario['position_type'].upper()}")
  39. print(f" Entry Price: ${scenario['entry_price']:,.2f}")
  40. print(f" Position Size: {scenario['position_size']}")
  41. print()
  42. for current_price in scenario['current_prices']:
  43. # Calculate P&L percentage
  44. if scenario['position_type'] == 'long':
  45. pnl_percent = ((current_price - scenario['entry_price']) / scenario['entry_price']) * 100
  46. else: # short
  47. pnl_percent = ((scenario['entry_price'] - current_price) / scenario['entry_price']) * 100
  48. # Check if stop loss would trigger
  49. would_trigger = pnl_percent <= -Config.STOP_LOSS_PERCENTAGE
  50. # Calculate loss value
  51. loss_value = scenario['position_size'] * abs(current_price - scenario['entry_price'])
  52. status = "🛑 STOP LOSS TRIGGERED!" if would_trigger else "✅ Safe"
  53. print(f" Current Price: ${current_price:,.2f} | P&L: {pnl_percent:+.2f}% | Loss: ${loss_value:,.2f} | {status}")
  54. print()
  55. def test_stop_loss_thresholds():
  56. """Test different stop loss threshold scenarios."""
  57. print("🔧 Stop Loss Threshold Testing")
  58. print("=" * 50)
  59. thresholds = [5.0, 10.0, 15.0, 20.0]
  60. entry_price = 50000 # BTC example
  61. print(f"Entry Price: ${entry_price:,.2f}")
  62. print()
  63. for threshold in thresholds:
  64. # Calculate trigger prices
  65. long_trigger_price = entry_price * (1 - threshold/100)
  66. short_trigger_price = entry_price * (1 + threshold/100)
  67. print(f"Stop Loss Threshold: {threshold}%")
  68. print(f" Long Position Trigger: ${long_trigger_price:,.2f} (loss of ${entry_price - long_trigger_price:,.2f})")
  69. print(f" Short Position Trigger: ${short_trigger_price:,.2f} (loss of ${short_trigger_price - entry_price:,.2f})")
  70. print()
  71. def test_monitoring_frequency():
  72. """Test monitoring frequency scenarios."""
  73. print("⏰ Monitoring Frequency Analysis")
  74. print("=" * 50)
  75. frequencies = [10, 30, 60, 120, 300] # seconds
  76. print("Different monitoring intervals and their implications:")
  77. print()
  78. for freq in frequencies:
  79. checks_per_minute = 60 / freq
  80. checks_per_hour = 3600 / freq
  81. print(f"Interval: {freq} seconds")
  82. print(f" Checks per minute: {checks_per_minute:.1f}")
  83. print(f" Checks per hour: {checks_per_hour:.0f}")
  84. print(f" Responsiveness: {'High' if freq <= 30 else 'Medium' if freq <= 120 else 'Low'}")
  85. print(f" API Usage: {'High' if freq <= 10 else 'Medium' if freq <= 60 else 'Low'}")
  86. print()
  87. if __name__ == "__main__":
  88. print("🚀 Stop Loss System Configuration Test")
  89. print("=" * 60)
  90. print()
  91. # Test current configuration
  92. test_stop_loss_config()
  93. print("\n" + "=" * 60)
  94. test_stop_loss_thresholds()
  95. print("\n" + "=" * 60)
  96. test_monitoring_frequency()
  97. print("\n" + "=" * 60)
  98. print("✅ Stop Loss System Ready!")
  99. print(f"📊 Current Settings: {Config.STOP_LOSS_PERCENTAGE}% stop loss, {Config.BOT_HEARTBEAT_SECONDS}s monitoring")
  100. print("🛡️ Automatic position protection is enabled")
  101. print("📱 You'll receive Telegram notifications for all stop loss events")