Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# app.py (
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import traceback
|
|
@@ -23,6 +23,8 @@ try:
|
|
| 23 |
from whale_monitor.core import EnhancedWhaleMonitor
|
| 24 |
from sentiment_news import NewsFetcher
|
| 25 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
|
|
|
|
|
|
| 26 |
except ImportError as e:
|
| 27 |
# إيقاف فوري للنظام في حال فقدان أي مكون حيوي
|
| 28 |
sys.exit(f"❌ [FATAL ERROR] Failed to import core modules: {e}")
|
|
@@ -39,6 +41,7 @@ learning_hub: LearningHubManager = None
|
|
| 39 |
whale_monitor: EnhancedWhaleMonitor = None
|
| 40 |
news_fetcher: NewsFetcher = None
|
| 41 |
vader: SentimentIntensityAnalyzer = None
|
|
|
|
| 42 |
|
| 43 |
class SystemState:
|
| 44 |
def __init__(self):
|
|
@@ -52,12 +55,12 @@ sys_state = SystemState()
|
|
| 52 |
# ==============================================================================
|
| 53 |
async def initialize_system():
|
| 54 |
global r2, data_manager, ml_processor, trade_manager, llm_service, learning_hub
|
| 55 |
-
global whale_monitor, news_fetcher, vader
|
| 56 |
|
| 57 |
if sys_state.ready:
|
| 58 |
return
|
| 59 |
|
| 60 |
-
print("\n🔌 [System
|
| 61 |
|
| 62 |
try:
|
| 63 |
# 1. البنية التحتية والبيانات (Infrastructure Layer)
|
|
@@ -89,14 +92,26 @@ async def initialize_system():
|
|
| 89 |
await ml_processor.initialize()
|
| 90 |
print(" ✅ ML Processor (Titan + Patterns) ready.")
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
await trade_manager.initialize_sentry_exchanges()
|
| 94 |
# بدء مهام المراقبة الخلفية للحارس
|
| 95 |
asyncio.create_task(trade_manager.start_sentry_loops())
|
| 96 |
-
print(" ✅ TradeManager Sentry loops started.")
|
| 97 |
|
| 98 |
sys_state.ready = True
|
| 99 |
-
print("\n🚀 [SYSTEM READY] All core systems are online and awaiting orders.")
|
| 100 |
|
| 101 |
except Exception as e:
|
| 102 |
print(f"\n❌ [INIT FATAL ERROR] System failed to start: {e}")
|
|
@@ -325,7 +340,7 @@ async def _run_explorer_mode_full():
|
|
| 325 |
|
| 326 |
if layer3_input_candidates:
|
| 327 |
print("📋 [L3 Qualification] The following candidates are advancing to Omniscient Brain:")
|
| 328 |
-
# رأس الجدول المحسن
|
| 329 |
print(f" {'#':<2} {'SYMBOL':<10} | {'L1':<6} | {'Whale Info':<16} | {'News Info':<16} | {'FINAL L2':<8}")
|
| 330 |
print("-" * 70)
|
| 331 |
for i, cand in enumerate(layer3_input_candidates, 1):
|
|
@@ -388,7 +403,7 @@ async def lifespan(app: FastAPI):
|
|
| 388 |
if data_manager: await data_manager.close()
|
| 389 |
print("👋 [System] Shutdown complete.")
|
| 390 |
|
| 391 |
-
app = FastAPI(lifespan=lifespan, title="Titan Hybrid System
|
| 392 |
|
| 393 |
@app.get("/")
|
| 394 |
async def root():
|
|
@@ -396,6 +411,7 @@ async def root():
|
|
| 396 |
return {
|
| 397 |
"system_status": "ONLINE",
|
| 398 |
"initialized": sys_state.ready,
|
|
|
|
| 399 |
"current_mode": "RE-ANALYSIS" if trade_manager and trade_manager.open_positions else "EXPLORER"
|
| 400 |
}
|
| 401 |
|
|
|
|
| 1 |
+
# app.py (V15.1 - Full Production - Guard V2 Integrated & Verbose Restored)
|
| 2 |
import os
|
| 3 |
import sys
|
| 4 |
import traceback
|
|
|
|
| 23 |
from whale_monitor.core import EnhancedWhaleMonitor
|
| 24 |
from sentiment_news import NewsFetcher
|
| 25 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
| 26 |
+
# [NEW] وحدة الحارس الجديد
|
| 27 |
+
from ml_engine.guard_engine import GuardEngine
|
| 28 |
except ImportError as e:
|
| 29 |
# إيقاف فوري للنظام في حال فقدان أي مكون حيوي
|
| 30 |
sys.exit(f"❌ [FATAL ERROR] Failed to import core modules: {e}")
|
|
|
|
| 41 |
whale_monitor: EnhancedWhaleMonitor = None
|
| 42 |
news_fetcher: NewsFetcher = None
|
| 43 |
vader: SentimentIntensityAnalyzer = None
|
| 44 |
+
guard_engine: GuardEngine = None # [NEW]
|
| 45 |
|
| 46 |
class SystemState:
|
| 47 |
def __init__(self):
|
|
|
|
| 55 |
# ==============================================================================
|
| 56 |
async def initialize_system():
|
| 57 |
global r2, data_manager, ml_processor, trade_manager, llm_service, learning_hub
|
| 58 |
+
global whale_monitor, news_fetcher, vader, guard_engine
|
| 59 |
|
| 60 |
if sys_state.ready:
|
| 61 |
return
|
| 62 |
|
| 63 |
+
print("\n🔌 [System V15.1] Starting Full Initialization Sequence (with Guard V2)...")
|
| 64 |
|
| 65 |
try:
|
| 66 |
# 1. البنية التحتية والبيانات (Infrastructure Layer)
|
|
|
|
| 92 |
await ml_processor.initialize()
|
| 93 |
print(" ✅ ML Processor (Titan + Patterns) ready.")
|
| 94 |
|
| 95 |
+
# [NEW] تهيئة محرك الحماية
|
| 96 |
+
guard_engine = GuardEngine()
|
| 97 |
+
await guard_engine.initialize()
|
| 98 |
+
print(" ✅ Guard Engine V2 (Exit Protector) ready.")
|
| 99 |
+
|
| 100 |
+
# [MODIFIED] تمرير الحارس لمدير التداول
|
| 101 |
+
trade_manager = TradeManager(
|
| 102 |
+
r2,
|
| 103 |
+
data_manager,
|
| 104 |
+
ml_processor.titan,
|
| 105 |
+
ml_processor.pattern_engine,
|
| 106 |
+
guard_engine=guard_engine # <--- تسليم الحارس
|
| 107 |
+
)
|
| 108 |
await trade_manager.initialize_sentry_exchanges()
|
| 109 |
# بدء مهام المراقبة الخلفية للحارس
|
| 110 |
asyncio.create_task(trade_manager.start_sentry_loops())
|
| 111 |
+
print(" ✅ TradeManager Sentry loops started (Guard V2 Active).")
|
| 112 |
|
| 113 |
sys_state.ready = True
|
| 114 |
+
print("\n🚀 [SYSTEM READY V15.1] All core systems are online and awaiting orders.")
|
| 115 |
|
| 116 |
except Exception as e:
|
| 117 |
print(f"\n❌ [INIT FATAL ERROR] System failed to start: {e}")
|
|
|
|
| 340 |
|
| 341 |
if layer3_input_candidates:
|
| 342 |
print("📋 [L3 Qualification] The following candidates are advancing to Omniscient Brain:")
|
| 343 |
+
# رأس الجدول المحسن (تمت استعادته بالكامل)
|
| 344 |
print(f" {'#':<2} {'SYMBOL':<10} | {'L1':<6} | {'Whale Info':<16} | {'News Info':<16} | {'FINAL L2':<8}")
|
| 345 |
print("-" * 70)
|
| 346 |
for i, cand in enumerate(layer3_input_candidates, 1):
|
|
|
|
| 403 |
if data_manager: await data_manager.close()
|
| 404 |
print("👋 [System] Shutdown complete.")
|
| 405 |
|
| 406 |
+
app = FastAPI(lifespan=lifespan, title="Titan Hybrid System V15.1 (Full Production + Guard V2)")
|
| 407 |
|
| 408 |
@app.get("/")
|
| 409 |
async def root():
|
|
|
|
| 411 |
return {
|
| 412 |
"system_status": "ONLINE",
|
| 413 |
"initialized": sys_state.ready,
|
| 414 |
+
"guard_v2_active": guard_engine.initialized if guard_engine else False, # [NEW] حالة الحارس
|
| 415 |
"current_mode": "RE-ANALYSIS" if trade_manager and trade_manager.open_positions else "EXPLORER"
|
| 416 |
}
|
| 417 |
|