Riy777 commited on
Commit
f726fa2
·
verified ·
1 Parent(s): 93b1daa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -1,5 +1,5 @@
1
  # ==============================================================================
2
- # 🚀 app.py (V35.5 - GEM-Architect: UI Logic Fix for PnL)
3
  # ==============================================================================
4
 
5
  import os
@@ -176,7 +176,7 @@ async def auto_pilot_loop():
176
  async def lifespan(app: FastAPI):
177
  global r2, data_manager, ml_processor, adaptive_hub, trade_manager, whale_monitor, news_fetcher, senti_analyzer, sys_state
178
 
179
- logger.info("\n🚀 [System] Startup Sequence (Titan V35.5)...")
180
  try:
181
  r2 = R2Service()
182
  data_manager = DataManager(contracts_db={}, whale_monitor=None, r2_service=r2)
@@ -484,7 +484,7 @@ async def run_cycle_from_gradio():
484
  return "🚀 Launched."
485
 
486
  # ------------------------------------------------------------------------------
487
- # UI Updates (Updated for PnL Fix)
488
  # ------------------------------------------------------------------------------
489
  async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
490
  empty_chart = go.Figure()
@@ -534,14 +534,14 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
534
  </div>
535
  """
536
 
537
- # ✅ التصحيح الجوهري هنا:
538
  # Virtual Equity = الرصيد المحقق + الربح/الخسارة العائمة
539
  virtual_equity = equity + pnl_val_unrealized
540
 
541
- # Total PnL (للعرض) يجب أن يُحسب بناءً على Virtual Equity وليس Equity فقط
542
- # لكي يعكس الواقع (9.96 - 10.00 = -0.04) بدلاً من (10.06 - 10.00 = +0.06)
543
- total_pnl_val = virtual_equity - INITIAL_CAPITAL
544
- total_pnl_color = "#00ff00" if total_pnl_val >= 0 else "#ff0000"
 
545
 
546
  # --- باقي الكود للعرض كما هو ---
547
  portfolio = await r2.get_portfolio_state_async()
@@ -561,7 +561,7 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
561
  <div style='background-color: #1a1a1a; padding: 15px; border-radius: 8px; border: 1px solid #333; text-align:center;'>
562
  <h3 style='margin:0; color:#888; font-size:14px;'>💼 Smart Portfolio</h3>
563
  <div style='font-size: 24px; font-weight: bold; color: white; margin: 5px 0 0 0;'>${virtual_equity:,.2f}</div>
564
- <div style='font-size: 14px; color: {total_pnl_color}; margin-bottom: 5px;'>({total_pnl_val:+,.2f} USD)</div>
565
 
566
  <table style='width:100%; font-size:12px; margin-top:5px; color:#ccc;'>
567
  <tr><td>Allocated:</td><td style='text-align:right; color:#ffa500;'>${allocated:.2f}</td></tr>
@@ -665,10 +665,10 @@ async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
665
  def create_gradio_ui():
666
  custom_css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
667
 
668
- with gr.Blocks(title="Titan V35.5 (UI PnL Fix)") as demo:
669
  gr.HTML(f"<style>{custom_css}</style>")
670
 
671
- gr.Markdown("# 🚀 Titan V35.5 (Portfolio-Aware & Dual-Core)")
672
 
673
  with gr.Row():
674
  with gr.Column(scale=3):
 
1
  # ==============================================================================
2
+ # 🚀 app.py (V35.6 - GEM-Architect: Active Trade PnL Display)
3
  # ==============================================================================
4
 
5
  import os
 
176
  async def lifespan(app: FastAPI):
177
  global r2, data_manager, ml_processor, adaptive_hub, trade_manager, whale_monitor, news_fetcher, senti_analyzer, sys_state
178
 
179
+ logger.info("\n🚀 [System] Startup Sequence (Titan V35.6)...")
180
  try:
181
  r2 = R2Service()
182
  data_manager = DataManager(contracts_db={}, whale_monitor=None, r2_service=r2)
 
484
  return "🚀 Launched."
485
 
486
  # ------------------------------------------------------------------------------
487
+ # UI Updates (Updated for Active Trade PnL)
488
  # ------------------------------------------------------------------------------
489
  async def check_live_pnl_and_status(selected_view="Dual-Core (Hybrid)"):
490
  empty_chart = go.Figure()
 
534
  </div>
535
  """
536
 
 
537
  # Virtual Equity = الرصيد المحقق + الربح/الخسارة العائمة
538
  virtual_equity = equity + pnl_val_unrealized
539
 
540
+ # FIX: User requested ACTIVE TRADE PnL ONLY under the main Equity
541
+ # (Instead of Total Account PnL)
542
+ # If no trade active, this is 0.00
543
+ active_trade_pnl_val = pnl_val_unrealized
544
+ active_pnl_color = "#00ff00" if active_trade_pnl_val >= 0 else "#ff0000"
545
 
546
  # --- باقي الكود للعرض كما هو ---
547
  portfolio = await r2.get_portfolio_state_async()
 
561
  <div style='background-color: #1a1a1a; padding: 15px; border-radius: 8px; border: 1px solid #333; text-align:center;'>
562
  <h3 style='margin:0; color:#888; font-size:14px;'>💼 Smart Portfolio</h3>
563
  <div style='font-size: 24px; font-weight: bold; color: white; margin: 5px 0 0 0;'>${virtual_equity:,.2f}</div>
564
+ <div style='font-size: 14px; color: {active_pnl_color}; margin-bottom: 5px;'>({active_trade_pnl_val:+,.2f} USD)</div>
565
 
566
  <table style='width:100%; font-size:12px; margin-top:5px; color:#ccc;'>
567
  <tr><td>Allocated:</td><td style='text-align:right; color:#ffa500;'>${allocated:.2f}</td></tr>
 
665
  def create_gradio_ui():
666
  custom_css = ".gradio-container {background:#0b0f19} .dataframe {background:#1a1a1a!important} .html-box {min-height:180px}"
667
 
668
+ with gr.Blocks(title="Titan V35.6 (Active PnL Only)") as demo:
669
  gr.HTML(f"<style>{custom_css}</style>")
670
 
671
+ gr.Markdown("# 🚀 Titan V35.6 (Portfolio-Aware & Dual-Core)")
672
 
673
  with gr.Row():
674
  with gr.Column(scale=3):