Files
quantumbotx/testing/test_fbs_compatibility.py
T

215 lines
8.0 KiB
Python

#!/usr/bin/env python3
"""
🔄 FBS Broker Compatibility Test
Tests the automatic migration system when switching to FBS broker
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
load_dotenv()
def test_fbs_broker_support():
"""Test that FBS broker is properly supported in migration system"""
print("🔧 Testing FBS Broker Support...")
print("=" * 50)
try:
# Test 1: Import migration functions
from testing.broker_symbol_migrator import detect_current_broker, get_broker_preferred_symbols
print("✅ Successfully imported broker migration functions")
# Test 2: Check FBS in broker preferences
preferred_symbols = get_broker_preferred_symbols()
if "FBS" in preferred_symbols:
print("✅ FBS found in broker preference mapping")
fbs_mapping = preferred_symbols["FBS"]
print(f" FBS Symbol Mapping: {fbs_mapping}")
else:
print("❌ FBS not found in broker preferences")
return False
# Test 3: Check broker detection logic
# We'll simulate FBS server names that might be encountered
test_broker_names = ["FBS-Demo", "FBS-Live", "FBS-Real"]
print("\n🔍 Testing FBS Broker Detection...")
# Mock the broker detection (since we can't actually connect to FBS)
for server_name in test_broker_names:
if 'FBS' in server_name.upper():
print(f"✅ Would detect '{server_name}' as FBS broker")
else:
print(f"❌ Would NOT detect '{server_name}' as FBS broker")
# Test 4: Symbol compatibility
print("\n🎯 Testing FBS Symbol Compatibility...")
expected_symbols = ['XAUUSD', 'EURUSD', 'GBPUSD', 'BTCUSD', 'ETHUSD']
for symbol in expected_symbols:
if symbol in fbs_mapping:
mapped_symbol = fbs_mapping[symbol]
print(f"✅ {symbol} -> {mapped_symbol}")
else:
print(f"⚠️ {symbol} not mapped (will use fallback)")
return True
except Exception as e:
print(f"❌ Error during FBS compatibility test: {e}")
return False
def test_env_configuration():
"""Test FBS credentials in .env file"""
print("\n🔐 Testing FBS Environment Configuration...")
print("-" * 40)
# Check if FBS credentials are in .env
fbs_login = None
fbs_password = None
fbs_server = None
try:
with open('.env', 'r') as f:
env_content = f.read()
# Look for FBS credentials (commented or uncommented)
if 'FBS' in env_content:
print("✅ FBS credentials found in .env file")
# Parse FBS credentials
lines = env_content.split('\n')
for line in lines:
if 'FBS' in line:
print(f" {line.strip()}")
if 'MT5_LOGIN=' in line and 'FBS' in line:
fbs_login = line.split('=')[1].strip().strip('"')
elif 'MT5_PASSWORD=' in line and 'FBS' in line:
fbs_password = line.split('=')[1].strip().strip('"')
elif 'MT5_SERVER=' in line and 'FBS' in line:
fbs_server = line.split('=')[1].strip().strip('"')
# Validate credential format
if fbs_login and fbs_password and fbs_server:
print("✅ Complete FBS credentials available")
print(f" Login: {fbs_login}")
print(f" Server: {fbs_server}")
print(f" Password: {'*' * len(fbs_password)}")
return True
else:
print("⚠️ FBS credentials incomplete")
return False
else:
print("❌ No FBS credentials found in .env file")
return False
except Exception as e:
print(f"❌ Error reading .env file: {e}")
return False
def test_automatic_migration_simulation():
"""Simulate the automatic migration process for FBS"""
print("\n🔄 Simulating FBS Migration Process...")
print("-" * 40)
try:
# Simulate broker change detection
print("📊 Step 1: Broker Change Detection")
print(" Current: XMGlobal-MT5 7")
print(" New: FBS-Demo")
print(" ✅ Broker change detected: 'XMGlobal-MT5 7' -> 'FBS-Demo'")
# Simulate symbol migration
print("\n🔄 Step 2: Symbol Migration")
current_symbols = ["GOLD", "EURUSD", "GBPUSD"] # Current XM symbols
from testing.broker_symbol_migrator import get_broker_preferred_symbols
fbs_mapping = get_broker_preferred_symbols()["FBS"]
for symbol in current_symbols:
if symbol == "GOLD":
# GOLD (XM) should map to XAUUSD (FBS)
target_symbol = fbs_mapping.get("XAUUSD", "XAUUSD")
print(f" 🥇 Bot (Gold): {symbol} -> {target_symbol}")
elif symbol in fbs_mapping:
target_symbol = fbs_mapping[symbol]
print(f" 💰 Bot (Forex): {symbol} -> {target_symbol}")
else:
print(f" ✅ Bot (Forex): {symbol} -> {symbol} (no change needed)")
print("\n✅ Migration simulation completed successfully!")
return True
except Exception as e:
print(f"❌ Migration simulation failed: {e}")
return False
def provide_fbs_switching_guide():
"""Provide step-by-step guide for switching to FBS"""
print("\n📋 FBS Switching Guide")
print("=" * 50)
print("🔧 To switch to FBS broker:")
print("1. Open your .env file")
print("2. Comment out current credentials (add # at start of line):")
print(" #MT5_LOGIN=\"315116295\"")
print(" #MT5_PASSWORD=\"5X2xz!83UE\"")
print(" #MT5_SERVER=\"XMGlobal-MT5 7\"")
print("")
print("3. Uncomment FBS credentials (remove # from start of line):")
print(" MT5_LOGIN=\"103412769\"")
print(" MT5_PASSWORD=\"2jB-ArVz\"")
print(" MT5_SERVER=\"FBS-Demo\"")
print("")
print("4. Save the .env file")
print("5. Restart QuantumBotX: python run.py")
print("")
print("🤖 What will happen automatically:")
print("✅ Broker change will be detected")
print("✅ All bots will be migrated to FBS-compatible symbols")
print("✅ GOLD symbols will be mapped to XAUUSD")
print("✅ Forex pairs will remain the same (EURUSD, GBPUSD, etc.)")
print("✅ No manual bot reconfiguration needed!")
print("")
print("⚠️ Important notes:")
print("• Make sure FBS MT5 terminal is running")
print("• Check that your symbols are available in FBS Market Watch")
print("• Your trading strategies and parameters will be preserved")
def main():
"""Main test function"""
print("🔄 FBS Broker Compatibility Validation")
print("Testing automatic migration system for FBS")
print("=" * 60)
tests = [
("FBS Broker Support", test_fbs_broker_support),
("Environment Configuration", test_env_configuration),
("Migration Simulation", test_automatic_migration_simulation)
]
passed = 0
for test_name, test_func in tests:
print(f"\n🧪 Running: {test_name}")
if test_func():
passed += 1
print(f"✅ {test_name}: PASSED")
else:
print(f"❌ {test_name}: FAILED")
print(f"\n📊 Test Results: {passed}/{len(tests)} tests passed")
if passed == len(tests):
print("\n🎉 FBS COMPATIBILITY CONFIRMED!")
print("✨ You can safely switch to FBS broker")
provide_fbs_switching_guide()
else:
print("\n⚠️ Some compatibility issues detected")
print("Please review the failed tests above")
return passed == len(tests)
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)