Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
# ==============================================================================
|
| 2 |
-
# 🚀 app.py (V35.
|
| 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.
|
| 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
|
| 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 |
-
#
|
| 542 |
-
#
|
| 543 |
-
|
| 544 |
-
|
|
|
|
| 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: {
|
| 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.
|
| 669 |
gr.HTML(f"<style>{custom_css}</style>")
|
| 670 |
|
| 671 |
-
gr.Markdown("# 🚀 Titan V35.
|
| 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):
|