Riy777 commited on
Commit
6c90167
·
verified ·
1 Parent(s): 8ca82de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -30
app.py CHANGED
@@ -1,5 +1,5 @@
1
- # app.py (V24.0 - GEM-Architect: Full Architecture with L2.5 Boosting)
2
- # تمت استعادة طبقة "التعزيز" (L2.5) لدمج الأخبار والحيتان في التقييم.
3
 
4
  import os
5
  import sys
@@ -154,7 +154,7 @@ async def auto_pilot_loop():
154
  @asynccontextmanager
155
  async def lifespan(app: FastAPI):
156
  global r2, data_manager, ml_processor, hub_manager, trade_manager, whale_monitor, news_fetcher, senti_analyzer, sys_state
157
- logger.info("\n🚀 [System] Startup Sequence Initiated (Titan V24.0)...")
158
  try:
159
  logger.info(" [1/7] Initializing R2 & Data Services...")
160
  r2 = R2Service()
@@ -227,7 +227,7 @@ async def run_unified_cycle():
227
  1. Guardian (إدارة)
228
  2. L1 Screening (فلترة)
229
  3. L2 Analysis (تحليل فني)
230
- 4. L2.5 Boosting (تعزيز: حيتان + أخبار) -> 🔥 [تمت الاستعادة]
231
  5. L3 Oracle (تحكيم)
232
  6. L4 Sniper (تنفيذ)
233
  """
@@ -277,14 +277,14 @@ async def run_unified_cycle():
277
  results = await asyncio.gather(*tasks)
278
  valid_l2 = [res for res in results if res is not None]
279
 
280
- # نأخذ أفضل 10 بناءً على التحليل الفني فقط للمرحلة التالية
281
  top_technical = sorted(valid_l2, key=lambda x: x.get('enhanced_final_score', 0.0), reverse=True)[:10]
282
 
283
  if not top_technical:
284
  log_and_print("⚠️ No valid L2 candidates.")
285
  sys_state.set_cycle_end(logs=log_buffer.getvalue()); return
286
 
287
- # 4. 🔥 L2.5 Enrichment & Boosting (Whales + News) 🔥
288
  log_and_print(f" [3/5] 🚀 L2.5 Boosting (Whales & News)...")
289
  boosted_candidates = []
290
 
@@ -292,46 +292,42 @@ async def run_unified_cycle():
292
  symbol = cand['symbol']
293
  current_score = cand['enhanced_final_score']
294
 
295
- # أ. تعزيز الحيتان (+0.10 كحد أقصى)
296
  whale_score = 0.0
297
- whale_txt = "Normal"
298
  try:
299
  w_data = await whale_monitor.get_symbol_whale_activity(symbol)
300
  net_flow = w_data.get('accumulation_analysis_24h', {}).get('net_flow_usd', 0)
301
- if net_flow > 500000:
302
- whale_score = 0.10; whale_txt = "🔥 HIGH"
303
- elif net_flow > 100000:
304
- whale_score = 0.05; whale_txt = "✅ POS"
305
  except: pass
306
 
307
- # ب. تعزيز الأخبار (+0.05 كحد أقصى)
308
  news_score = 0.0
309
- news_txt = "-"
310
  try:
311
  news_item = await news_fetcher.get_news(symbol)
312
  if news_item:
313
  sentiment = senti_analyzer.polarity_scores(news_item.get('summary', ''))
314
- if sentiment['compound'] > 0.2:
315
- news_score = 0.05; news_txt = "POS"
316
  except: pass
317
 
318
- # تحديث الدرجة
319
  new_final = current_score + whale_score + news_score
320
- cand['enhanced_final_score'] = new_final # تحديث الدرجة للمراحل القادمة
321
- cand['boost_info'] = f"W:{whale_txt} N:{news_txt}"
 
 
322
  boosted_candidates.append(cand)
323
 
324
- # إعادة الترتيب بعد التعزيز
325
  final_top_10 = sorted(boosted_candidates, key=lambda x: x['enhanced_final_score'], reverse=True)
326
 
327
- # عرض الجدول المعزز
328
- log_and_print(f"{'SYMBOL':<10} | {'FINAL':<6} | {'BASE':<6} | {'BOOST INFO'}")
329
  log_and_print("-" * 45)
330
  for c in final_top_10:
331
- # نحسب الدرجة الأساسية بطرح التعزيز
332
- base_s = c['enhanced_final_score'] - (0.10 if 'HIGH' in c['boost_info'] else 0) - (0.05 if 'POS' in c['boost_info'] else 0)
333
- # تقريبي للعرض فقط
334
- log_and_print(f"{c['symbol']:<10} | {c['enhanced_final_score']:.3f} | {base_s:.2f} | {c['boost_info']}")
335
 
336
  # 5. L3 Oracle
337
  log_and_print(f" [4/5] 🔮 L3 Oracle Check...")
@@ -535,12 +531,12 @@ async def check_live_pnl_and_status(selected_view="Hybrid System"):
535
  return "Error", "Error", empty_chart, "0", "0", "0", "0", "0%", wl_df_empty, "Err", "Err", "Err"
536
 
537
  # ==============================================================================
538
- # 🎨 UI
539
  # ==============================================================================
540
  def create_gradio_ui():
541
  css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
542
- with gr.Blocks(title="Titan V24.0", css=css, theme=gr.themes.Monochrome()) as demo:
543
- gr.Markdown("# 🚀 Titan V24.0 (Full Architecture)")
544
 
545
  with gr.Row():
546
  with gr.Column(scale=3):
@@ -589,7 +585,7 @@ def create_gradio_ui():
589
  # ==============================================================================
590
  # 🏁 Server
591
  # ==============================================================================
592
- fast_api_server = FastAPI(lifespan=lifespan, title="Titan V24.0 Pro", description="Titan Enterprise Trading System")
593
  gradio_dashboard = create_gradio_ui()
594
  app = gr.mount_gradio_app(app=fast_api_server, blocks=gradio_dashboard, path="/")
595
 
 
1
+ # app.py (V24.1 - GEM-Architect: Numeric Boosting Display)
2
+ # تم تحديث طبقة التعزيز (L2.5) لعرض درجات الحيتان والأخبار رقمياً بدقة.
3
 
4
  import os
5
  import sys
 
154
  @asynccontextmanager
155
  async def lifespan(app: FastAPI):
156
  global r2, data_manager, ml_processor, hub_manager, trade_manager, whale_monitor, news_fetcher, senti_analyzer, sys_state
157
+ logger.info("\n🚀 [System] Startup Sequence Initiated (Titan V24.1)...")
158
  try:
159
  logger.info(" [1/7] Initializing R2 & Data Services...")
160
  r2 = R2Service()
 
227
  1. Guardian (إدارة)
228
  2. L1 Screening (فلترة)
229
  3. L2 Analysis (تحليل فني)
230
+ 4. L2.5 Boosting (تعزيز رقمي: حيتان + أخبار)
231
  5. L3 Oracle (تحكيم)
232
  6. L4 Sniper (تنفيذ)
233
  """
 
277
  results = await asyncio.gather(*tasks)
278
  valid_l2 = [res for res in results if res is not None]
279
 
280
+ # نأخذ أفضل 10 بناءً على التحليل الفني
281
  top_technical = sorted(valid_l2, key=lambda x: x.get('enhanced_final_score', 0.0), reverse=True)[:10]
282
 
283
  if not top_technical:
284
  log_and_print("⚠️ No valid L2 candidates.")
285
  sys_state.set_cycle_end(logs=log_buffer.getvalue()); return
286
 
287
+ # 4. 🔥 L2.5 Enrichment & Boosting (Numeric) 🔥
288
  log_and_print(f" [3/5] 🚀 L2.5 Boosting (Whales & News)...")
289
  boosted_candidates = []
290
 
 
292
  symbol = cand['symbol']
293
  current_score = cand['enhanced_final_score']
294
 
295
+ # أ. تعزيز الحيتان
296
  whale_score = 0.0
 
297
  try:
298
  w_data = await whale_monitor.get_symbol_whale_activity(symbol)
299
  net_flow = w_data.get('accumulation_analysis_24h', {}).get('net_flow_usd', 0)
300
+ if net_flow > 500000: whale_score = 0.10
301
+ elif net_flow > 100000: whale_score = 0.05
 
 
302
  except: pass
303
 
304
+ # ب. تعزيز الأخبار
305
  news_score = 0.0
 
306
  try:
307
  news_item = await news_fetcher.get_news(symbol)
308
  if news_item:
309
  sentiment = senti_analyzer.polarity_scores(news_item.get('summary', ''))
310
+ if sentiment['compound'] > 0.2: news_score = 0.05
 
311
  except: pass
312
 
313
+ # تحديث الدرجة وتخزين القيم الخام
314
  new_final = current_score + whale_score + news_score
315
+ cand['enhanced_final_score'] = new_final
316
+ cand['whale_score'] = whale_score # حفظ الدرجة الرقمية
317
+ cand['news_score'] = news_score # حفظ الدرجة الرقمية
318
+ cand['boost_info'] = f"W:{whale_score:.2f} N:{news_score:.2f}"
319
  boosted_candidates.append(cand)
320
 
321
+ # إعادة الترتيب
322
  final_top_10 = sorted(boosted_candidates, key=lambda x: x['enhanced_final_score'], reverse=True)
323
 
324
+ # عرض الجدول المعزز بالأرقام
325
+ log_and_print(f"{'SYMBOL':<10} | {'FINAL':<6} | {'BASE':<6} | {'BOOST (W/N)'}")
326
  log_and_print("-" * 45)
327
  for c in final_top_10:
328
+ # حساب الدرجة الأساسية من القيم المخزنة بدقة
329
+ base_s = c['enhanced_final_score'] - c.get('whale_score', 0.0) - c.get('news_score', 0.0)
330
+ log_and_print(f"{c['symbol']:<10} | {c['enhanced_final_score']:.3f} | {base_s:.3f} | {c['boost_info']}")
 
331
 
332
  # 5. L3 Oracle
333
  log_and_print(f" [4/5] 🔮 L3 Oracle Check...")
 
531
  return "Error", "Error", empty_chart, "0", "0", "0", "0", "0%", wl_df_empty, "Err", "Err", "Err"
532
 
533
  # ==============================================================================
534
+ # 🎨 Gradio UI
535
  # ==============================================================================
536
  def create_gradio_ui():
537
  css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
538
+ with gr.Blocks(title="Titan V24.1", css=css, theme=gr.themes.Monochrome()) as demo:
539
+ gr.Markdown("# 🚀 Titan V24.1 (Full Architecture)")
540
 
541
  with gr.Row():
542
  with gr.Column(scale=3):
 
585
  # ==============================================================================
586
  # 🏁 Server
587
  # ==============================================================================
588
+ fast_api_server = FastAPI(lifespan=lifespan, title="Titan V24.1 Pro", description="Titan Enterprise Trading System")
589
  gradio_dashboard = create_gradio_ui()
590
  app = gr.mount_gradio_app(app=fast_api_server, blocks=gradio_dashboard, path="/")
591