Riy777 commited on
Commit
f8269d8
·
1 Parent(s): c600730

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py (Updated to V8.5 - Vader Injection Fix)
2
  import os
3
  import traceback
4
  import signal
@@ -549,7 +549,7 @@ async def run_3_layer_analysis_explorer() -> List[Dict[str, Any]]:
549
 
550
 
551
  async def re_analyze_open_trade_async(trade_data):
552
- """(V8.3) إضافة جلب حجم التداول لـ Reflector"""
553
  symbol = trade_data.get('symbol')
554
  try:
555
  async with state_manager.trade_analysis_lock:
@@ -576,7 +576,6 @@ async def re_analyze_open_trade_async(trade_data):
576
  if not ohlcv_data_list: print(f"⚠️ Failed to get re-analysis data for {symbol}"); return None
577
  ohlcv_data = ohlcv_data_list[0]
578
 
579
- # (جلب حجم التداول اليومي الحالي لإعادة التحليل)
580
  print(f" 🔄 [Re-Analyze] Fetching current daily volume for {symbol}...")
581
  symbol_daily_volume = await data_manager_global.get_symbol_daily_volume(symbol)
582
 
@@ -603,7 +602,6 @@ async def re_analyze_open_trade_async(trade_data):
603
  processed_data['ohlcv'] = processed_data['raw_ohlcv']
604
  processed_data['sentiment_data'] = market_context
605
 
606
- # (جلب الأخبار ودرجة VADER الخام لتمريرها إلى Reflector لاحقاً)
607
  if news_fetcher_global and VADER_ANALYZER:
608
  try:
609
  news_text = await news_fetcher_global.get_news_for_symbol(symbol)
@@ -618,8 +616,14 @@ async def re_analyze_open_trade_async(trade_data):
618
  else:
619
  processed_data['news_text'] = "News analysis disabled."
620
  processed_data['news_score'] = 0.0
621
-
622
- re_analysis_decision = await llm_service_global.re_analyze_trade_async(trade_data, processed_data)
 
 
 
 
 
 
623
 
624
  if re_analysis_decision:
625
  await r2_service_global.save_system_logs_async({ "trade_reanalyzed": True, "symbol": symbol, "action": re_analysis_decision.get('action'), 'strategy': re_analysis_decision.get('strategy', 'GENERIC') })
@@ -721,7 +725,7 @@ async def run_bot_cycle_async():
721
 
722
  @asynccontextmanager
723
  async def lifespan(application: FastAPI):
724
- # 🔴 --- START OF CHANGE (V8.4 - Whale Learning Loop) --- 🔴
725
  """Application lifecycle management"""
726
  print("🚀 Starting application initialization (Explorer/Sentry/Executor)...")
727
  try:
@@ -753,7 +757,6 @@ async def lifespan(application: FastAPI):
753
  raise
754
  finally:
755
  await cleanup_on_shutdown()
756
- # 🔴 --- END OF CHANGE --- 🔴
757
 
758
 
759
  application = FastAPI(lifespan=lifespan, title="AI Trading Bot", description="Explorer-Sentry-Executor Architecture (V5.9)", version="5.9.0")
 
1
+ # app.py (Updated to V8.6 - Vader + ndarray Fix)
2
  import os
3
  import traceback
4
  import signal
 
549
 
550
 
551
  async def re_analyze_open_trade_async(trade_data):
552
+ """(V8.6) إضافة إصلاح ndarray"""
553
  symbol = trade_data.get('symbol')
554
  try:
555
  async with state_manager.trade_analysis_lock:
 
576
  if not ohlcv_data_list: print(f"⚠️ Failed to get re-analysis data for {symbol}"); return None
577
  ohlcv_data = ohlcv_data_list[0]
578
 
 
579
  print(f" 🔄 [Re-Analyze] Fetching current daily volume for {symbol}...")
580
  symbol_daily_volume = await data_manager_global.get_symbol_daily_volume(symbol)
581
 
 
602
  processed_data['ohlcv'] = processed_data['raw_ohlcv']
603
  processed_data['sentiment_data'] = market_context
604
 
 
605
  if news_fetcher_global and VADER_ANALYZER:
606
  try:
607
  news_text = await news_fetcher_global.get_news_for_symbol(symbol)
 
616
  else:
617
  processed_data['news_text'] = "News analysis disabled."
618
  processed_data['news_score'] = 0.0
619
+
620
+ # 🔴 --- START OF CHANGE (V8.6 - ndarray Fix) --- 🔴
621
+ # (يجب تنقية البيانات قبل إرسالها إلى LLMService لتجنب خطأ ndarray)
622
+ print(f" 🔄 [Re-Analyze] Sanitizing data for {symbol} before LLM log...")
623
+ sanitized_processed_data = _sanitize_results_for_json(processed_data)
624
+
625
+ re_analysis_decision = await llm_service_global.re_analyze_trade_async(trade_data, sanitized_processed_data)
626
+ # 🔴 --- END OF CHANGE --- 🔴
627
 
628
  if re_analysis_decision:
629
  await r2_service_global.save_system_logs_async({ "trade_reanalyzed": True, "symbol": symbol, "action": re_analysis_decision.get('action'), 'strategy': re_analysis_decision.get('strategy', 'GENERIC') })
 
725
 
726
  @asynccontextmanager
727
  async def lifespan(application: FastAPI):
728
+ # (V8.4 - Whale Learning Loop)
729
  """Application lifecycle management"""
730
  print("🚀 Starting application initialization (Explorer/Sentry/Executor)...")
731
  try:
 
757
  raise
758
  finally:
759
  await cleanup_on_shutdown()
 
760
 
761
 
762
  application = FastAPI(lifespan=lifespan, title="AI Trading Bot", description="Explorer-Sentry-Executor Architecture (V5.9)", version="5.9.0")