147 lines
4.0 KiB
Python
147 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|||
|
|
"""
|
||
|
|
Debug Script - Bot Status Check
|
||
|
|
Prüft warum Bot nicht tradet
|
||
|
|
"""
|
||
|
|
|
||
|
|
import MetaTrader5 as mt5
|
||
|
|
from datetime import datetime
|
||
|
|
import json
|
||
|
|
|
||
|
|
print("=" * 70)
|
||
|
|
print("🔍 BOT STATUS DEBUG")
|
||
|
|
print("=" * 70)
|
||
|
|
print()
|
||
|
|
|
||
|
|
# 1. MT5 Connection
|
||
|
|
print("1. MT5 VERBINDUNG")
|
||
|
|
print("-" * 70)
|
||
|
|
if mt5.initialize():
|
||
|
|
print("✅ MT5 initialisiert")
|
||
|
|
|
||
|
|
# Terminal Info
|
||
|
|
terminal_info = mt5.terminal_info()
|
||
|
|
if terminal_info:
|
||
|
|
print(f" Terminal: {terminal_info.name}")
|
||
|
|
print(f" Connected: {terminal_info.connected}")
|
||
|
|
print(f" Trade Allowed: {terminal_info.trade_allowed}")
|
||
|
|
|
||
|
|
# Account Info
|
||
|
|
account_info = mt5.account_info()
|
||
|
|
if account_info:
|
||
|
|
print(f" Account: {account_info.login}")
|
||
|
|
print(f" Balance: ${account_info.balance:.2f}")
|
||
|
|
print(f" Equity: ${account_info.equity:.2f}")
|
||
|
|
print(f" Trade Allowed: {account_info.trade_allowed}")
|
||
|
|
print(f" Trade Expert: {account_info.trade_expert}")
|
||
|
|
|
||
|
|
# Symbol Info
|
||
|
|
symbol_info = mt5.symbol_info("XAUUSD")
|
||
|
|
if symbol_info:
|
||
|
|
print(f" XAUUSD visible: {symbol_info.visible}")
|
||
|
|
print(f" XAUUSD trade_mode: {symbol_info.trade_mode}")
|
||
|
|
print(f" Current Bid: {symbol_info.bid}")
|
||
|
|
print(f" Current Ask: {symbol_info.ask}")
|
||
|
|
|
||
|
|
# Offene Positionen
|
||
|
|
positions = mt5.positions_get(symbol="XAUUSD")
|
||
|
|
if positions:
|
||
|
|
print(f" Offene Positionen: {len(positions)}")
|
||
|
|
for pos in positions:
|
||
|
|
print(f" - Ticket {pos.ticket}: {pos.type} {pos.volume} lots @ {pos.price_open}")
|
||
|
|
else:
|
||
|
|
print(f" Offene Positionen: 0")
|
||
|
|
|
||
|
|
else:
|
||
|
|
print("❌ MT5 Initialisierung fehlgeschlagen!")
|
||
|
|
print(f" Error: {mt5.last_error()}")
|
||
|
|
|
||
|
|
print()
|
||
|
|
|
||
|
|
# 2. Letzte Orders
|
||
|
|
print("2. LETZTE ORDERS (History)")
|
||
|
|
print("-" * 70)
|
||
|
|
from datetime import timedelta
|
||
|
|
now = datetime.now()
|
||
|
|
from_date = now - timedelta(days=4)
|
||
|
|
|
||
|
|
mt5.initialize()
|
||
|
|
deals = mt5.history_deals_get(from_date, now)
|
||
|
|
|
||
|
|
if deals:
|
||
|
|
print(f"Total Deals (letzte 4 Tage): {len(deals)}")
|
||
|
|
print()
|
||
|
|
print("Letzte 5 Deals:")
|
||
|
|
for deal in list(deals)[-5:]:
|
||
|
|
deal_time = datetime.fromtimestamp(deal.time)
|
||
|
|
print(f" {deal_time}: {deal.symbol} {deal.type} {deal.volume} lots @ {deal.price}")
|
||
|
|
else:
|
||
|
|
print("❌ Keine Deals in den letzten 4 Tagen!")
|
||
|
|
|
||
|
|
print()
|
||
|
|
|
||
|
|
# 3. Market Status
|
||
|
|
print("3. MARKET STATUS")
|
||
|
|
print("-" * 70)
|
||
|
|
symbol_info = mt5.symbol_info("XAUUSD")
|
||
|
|
if symbol_info:
|
||
|
|
print(f"Market Open: {symbol_info.session_deals > 0}")
|
||
|
|
print(f"Trading Session: {symbol_info.trade_mode}")
|
||
|
|
|
||
|
|
# Check if weekend
|
||
|
|
now = datetime.now()
|
||
|
|
weekday = now.weekday()
|
||
|
|
if weekday >= 5: # Saturday = 5, Sunday = 6
|
||
|
|
print(f"⚠️ WOCHENENDE (Tag {weekday}) - Markt geschlossen!")
|
||
|
|
else:
|
||
|
|
print(f"✅ Wochentag ({weekday}) - Markt sollte offen sein")
|
||
|
|
|
||
|
|
# Check trading hours
|
||
|
|
hour = now.hour
|
||
|
|
print(f"Aktuelle Zeit: {now.strftime('%Y-%m-%d %H:%M:%S')}")
|
||
|
|
print(f"UTC Hour: {hour}")
|
||
|
|
|
||
|
|
print()
|
||
|
|
|
||
|
|
# 4. Last Trade from JSON
|
||
|
|
print("4. LETZTER TRADE (aus JSON)")
|
||
|
|
print("-" * 70)
|
||
|
|
try:
|
||
|
|
with open('trade_performance_v16_XAUUSD_202601.json', 'r') as f:
|
||
|
|
trades = json.load(f)
|
||
|
|
|
||
|
|
if trades:
|
||
|
|
last_trade = trades[-1]
|
||
|
|
print(f"Zeitstempel: {last_trade['timestamp']}")
|
||
|
|
print(f"Confidence: {last_trade['confidence']}%")
|
||
|
|
print(f"Session: {last_trade['session']}")
|
||
|
|
|
||
|
|
last_time = datetime.fromisoformat(last_trade['timestamp'])
|
||
|
|
delta = now - last_time
|
||
|
|
hours = delta.total_seconds() / 3600
|
||
|
|
print(f"Vor {delta.days} Tagen, {int(hours % 24)} Stunden")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"❌ Error reading JSON: {e}")
|
||
|
|
|
||
|
|
print()
|
||
|
|
|
||
|
|
# 5. News Filter Status
|
||
|
|
print("5. NEWS FILTER STATUS")
|
||
|
|
print("-" * 70)
|
||
|
|
try:
|
||
|
|
from news_filter_simple import is_news_upcoming
|
||
|
|
|
||
|
|
if is_news_upcoming(minutes_ahead=30, minutes_after=30):
|
||
|
|
print("❌ NEWS FILTER AKTIV - Trading blockiert!")
|
||
|
|
else:
|
||
|
|
print("✅ NEWS FILTER INAKTIV - Trading erlaubt")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"⚠️ News Filter Error: {e}")
|
||
|
|
|
||
|
|
print()
|
||
|
|
print("=" * 70)
|
||
|
|
print("✅ DEBUG COMPLETE")
|
||
|
|
print("=" * 70)
|
||
|
|
|
||
|
|
mt5.shutdown()
|