Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# ==============================================================================
|
| 2 |
-
# 🚀 app.py (V37.
|
| 3 |
# ==============================================================================
|
| 4 |
|
| 5 |
import os
|
|
@@ -190,7 +190,7 @@ async def auto_pilot_loop():
|
|
| 190 |
async def lifespan(app: FastAPI):
|
| 191 |
global r2, data_manager, ml_processor, adaptive_hub, trade_manager, whale_monitor, news_fetcher, senti_analyzer, sys_state, scheduler
|
| 192 |
|
| 193 |
-
logger.info("\n🚀 [System] Startup Sequence (Titan V37.
|
| 194 |
try:
|
| 195 |
# 1. الخدمات الأساسية
|
| 196 |
r2 = R2Service()
|
|
@@ -244,11 +244,17 @@ async def lifespan(app: FastAPI):
|
|
| 244 |
logger.info("✅ [System] Shutdown Complete.")
|
| 245 |
|
| 246 |
# ------------------------------------------------------------------------------
|
| 247 |
-
# Helper Tasks
|
| 248 |
# ------------------------------------------------------------------------------
|
| 249 |
-
async def _analyze_symbol_task(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
try:
|
|
|
|
| 251 |
required_tfs = ["5m", "15m", "1h", "4h"]
|
|
|
|
| 252 |
data_tasks = [data_manager.get_latest_ohlcv(symbol, tf, limit=300) for tf in required_tfs]
|
| 253 |
all_data = await asyncio.gather(*data_tasks)
|
| 254 |
|
|
@@ -260,7 +266,19 @@ async def _analyze_symbol_task(symbol: str) -> Dict[str, Any]:
|
|
| 260 |
return None
|
| 261 |
|
| 262 |
current_price = await data_manager.get_latest_price_async(symbol)
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
|
| 265 |
res = await ml_processor.process_compound_signal(raw_data)
|
| 266 |
if not res: return None
|
|
@@ -309,7 +327,8 @@ async def run_unified_cycle():
|
|
| 309 |
|
| 310 |
# LAYER 2: Deep Analysis
|
| 311 |
log_and_print(f" [2/5] 🧠 L2 Deep Analysis ({len(candidates)} items)...")
|
| 312 |
-
|
|
|
|
| 313 |
results = await asyncio.gather(*tasks)
|
| 314 |
valid_l2 = [res for res in results if res is not None]
|
| 315 |
|
|
@@ -760,10 +779,10 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
|
|
| 760 |
def create_gradio_ui():
|
| 761 |
custom_css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
|
| 762 |
|
| 763 |
-
with gr.Blocks(title="Titan V37.
|
| 764 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 765 |
|
| 766 |
-
gr.Markdown("# 🚀 Titan V37.
|
| 767 |
|
| 768 |
with gr.Row():
|
| 769 |
with gr.Column(scale=3):
|
|
|
|
| 1 |
# ==============================================================================
|
| 2 |
+
# 🚀 app.py (V37.2 - GEM-Architect: Neural Dashboard + Context Pipeline Fix)
|
| 3 |
# ==============================================================================
|
| 4 |
|
| 5 |
import os
|
|
|
|
| 190 |
async def lifespan(app: FastAPI):
|
| 191 |
global r2, data_manager, ml_processor, adaptive_hub, trade_manager, whale_monitor, news_fetcher, senti_analyzer, sys_state, scheduler
|
| 192 |
|
| 193 |
+
logger.info("\n🚀 [System] Startup Sequence (Titan V37.2 - Neural Dashboard)...")
|
| 194 |
try:
|
| 195 |
# 1. الخدمات الأساسية
|
| 196 |
r2 = R2Service()
|
|
|
|
| 244 |
logger.info("✅ [System] Shutdown Complete.")
|
| 245 |
|
| 246 |
# ------------------------------------------------------------------------------
|
| 247 |
+
# Helper Tasks (Modified for Context)
|
| 248 |
# ------------------------------------------------------------------------------
|
| 249 |
+
async def _analyze_symbol_task(candidate_data: Dict[str, Any]) -> Dict[str, Any]:
|
| 250 |
+
"""
|
| 251 |
+
Receives full candidate dict from L1 (Regime, Dynamic Limits),
|
| 252 |
+
not just the symbol string.
|
| 253 |
+
"""
|
| 254 |
try:
|
| 255 |
+
symbol = candidate_data['symbol']
|
| 256 |
required_tfs = ["5m", "15m", "1h", "4h"]
|
| 257 |
+
|
| 258 |
data_tasks = [data_manager.get_latest_ohlcv(symbol, tf, limit=300) for tf in required_tfs]
|
| 259 |
all_data = await asyncio.gather(*data_tasks)
|
| 260 |
|
|
|
|
| 266 |
return None
|
| 267 |
|
| 268 |
current_price = await data_manager.get_latest_price_async(symbol)
|
| 269 |
+
|
| 270 |
+
# ✅ FIX: Inject Context (Limits & Regime) into raw_data for L2 Processor
|
| 271 |
+
raw_data = {
|
| 272 |
+
'symbol': symbol,
|
| 273 |
+
'ohlcv': ohlcv_data,
|
| 274 |
+
'current_price': current_price,
|
| 275 |
+
'timestamp': time.time(),
|
| 276 |
+
# Preserving L1 Context
|
| 277 |
+
'dynamic_limits': candidate_data.get('dynamic_limits', {}),
|
| 278 |
+
'asset_regime': candidate_data.get('asset_regime', 'UNKNOWN'),
|
| 279 |
+
'strategy_tag': candidate_data.get('strategy_tag', 'NONE'),
|
| 280 |
+
'l1_score': candidate_data.get('l1_sort_score', 0)
|
| 281 |
+
}
|
| 282 |
|
| 283 |
res = await ml_processor.process_compound_signal(raw_data)
|
| 284 |
if not res: return None
|
|
|
|
| 327 |
|
| 328 |
# LAYER 2: Deep Analysis
|
| 329 |
log_and_print(f" [2/5] 🧠 L2 Deep Analysis ({len(candidates)} items)...")
|
| 330 |
+
# ✅ FIX: Pass the WHOLE candidate object, not just symbol string
|
| 331 |
+
tasks = [_analyze_symbol_task(c) for c in candidates]
|
| 332 |
results = await asyncio.gather(*tasks)
|
| 333 |
valid_l2 = [res for res in results if res is not None]
|
| 334 |
|
|
|
|
| 779 |
def create_gradio_ui():
|
| 780 |
custom_css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
|
| 781 |
|
| 782 |
+
with gr.Blocks(title="Titan V37.2 (Neural Dashboard)") as demo:
|
| 783 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 784 |
|
| 785 |
+
gr.Markdown("# 🚀 Titan V37.2 (Cybernetic: Neural Dashboard)")
|
| 786 |
|
| 787 |
with gr.Row():
|
| 788 |
with gr.Column(scale=3):
|