Riy777 commited on
Commit
39397dc
·
verified ·
1 Parent(s): 91219ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -20
app.py CHANGED
@@ -1,4 +1,4 @@
1
- # app.py (V17.5 - GEM-Architect Fixes: Graph, Pricing, Single-Trade Logic)
2
  import os
3
  import sys
4
  import traceback
@@ -89,6 +89,22 @@ class SystemState:
89
 
90
  sys_state = SystemState()
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  # ==============================================================================
93
  # 🚀 تهيئة التطبيق ودورة الحياة (Lifespan)
94
  # ==============================================================================
@@ -185,12 +201,6 @@ async def _analyze_symbol_task(symbol: str) -> Dict[str, Any]:
185
  # [ 🚀 🚀 🚀 ] الدورة الموحدة (معدلة: منطق الصفقة الواحدة + وضع الإدارة)
186
  # ==============================================================================
187
  async def run_unified_cycle():
188
- """
189
- دورة التحليل الكاملة:
190
- 1. التحقق من وجود صفقة مفتوحة (R2).
191
- 2. إذا وجدت -> وضع الإدارة (Re-analyze open trade).
192
- 3. إذا لم توجد -> وضع البحث (L1 -> L2 -> L3 -> L4).
193
- """
194
 
195
  log_buffer = StringIO()
196
 
@@ -229,16 +239,16 @@ async def run_unified_cycle():
229
 
230
  if entry > 0:
231
  pnl = ((current_price - entry) / entry) * 100
232
- log_and_print(f" 💰 PnL الحالي: {pnl:.2f}% | السعر: {current_price}")
233
  else:
234
  log_and_print(f" ⚠️ خطأ في سعر الدخول المسجل.")
235
 
236
  log_and_print(f"✅ [Cycle END] تم تحديث حالة الصفقة المفتوحة.")
237
  sys_state.set_cycle_end(logs=log_buffer.getvalue())
238
- return # إنهاء الدورة هنا - لا تفتح صفقات جديدة
239
 
240
  # ============================================================
241
- # 🔍 وضع البحث (Scanning Mode) - يعمل فقط إذا لم توجد صفقات
242
  # ============================================================
243
 
244
  # --- 1. الغربلة الأولية (L1) ---
@@ -430,13 +440,13 @@ async def get_full_status():
430
  }
431
 
432
  # ==============================================================================
433
- # 📊 [ 💡 GEM-ARCHITECT FIX: UI LOGIC & GRAPH ]
434
  # ==============================================================================
435
 
436
  async def check_live_pnl_and_status():
437
  """
438
  [جديد] دالة يتم استدعاؤها كل 10 ثواني لتحديث الواجهة.
439
- (إصلاح: يعالج الأصفار 0.00 ويرسم المخطط بشكل صحيح باستخدام Figure)
440
  """
441
  global trade_manager, data_manager, sys_state
442
 
@@ -496,16 +506,22 @@ async def check_live_pnl_and_status():
496
  symbol_md = f"# {symbol}"
497
  pnl_md = f"<div style='font-size: 30px; color:{color}; text-align:center; font-weight:bold;'>{pnl_text}</div>"
498
 
 
 
 
 
 
 
499
  details_md = f"""
500
  <div style='background-color: #222; padding: 10px; border-radius: 5px;'>
501
- <b>سعر الدخول:</b> {float(trade['entry_price']):.4f}<br>
502
- <b>السعر الحالي:</b> {current_price:.4f}<br>
503
- <span style='color:#00ff00;'><b>TP:</b> {float(trade['tp_price']):.4f}</span><br>
504
- <span style='color:#ff0000;'><b>SL:</b> {float(trade['sl_price']):.4f}</span>
505
  </div>
506
  """
507
 
508
- # 5. [GEM-FIX] رسم المخطط (استخدام Figure مستقل)
509
  fig = None
510
  try:
511
  ohlcv = await data_manager.get_latest_ohlcv(symbol, '5m', 100)
@@ -513,11 +529,9 @@ async def check_live_pnl_and_status():
513
  df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
514
  df['datetime'] = pd.to_datetime(df['timestamp'], unit='ms')
515
 
516
- # إنشاء كائن شكل مستقل لتجنب تضارب الذاكرة
517
  fig = plt.figure(figsize=(10, 5))
518
  ax = fig.add_subplot(111)
519
 
520
- # تنسيق المخطط الداكن
521
  fig.patch.set_facecolor('#0b0f19')
522
  ax.set_facecolor('#0b0f19')
523
 
@@ -601,7 +615,7 @@ def create_gradio_ui():
601
  outputs=[cycle_logs_output, status_markdown, live_symbol, live_pnl, live_details, live_chart, watchlist_output]
602
  )
603
 
604
- timer = gr.Timer(10) # تحديث كل 10 ثواني
605
 
606
  timer.tick(
607
  fn=check_live_pnl_and_status,
 
1
+ # app.py (V17.6 - GEM-Architect Fix: Full Price Precision for Meme Coins)
2
  import os
3
  import sys
4
  import traceback
 
89
 
90
  sys_state = SystemState()
91
 
92
+ # ==============================================================================
93
+ # 🛠️ Helper Functions
94
+ # ==============================================================================
95
+ def format_crypto_price(price):
96
+ """
97
+ تنسيق السعر بذكاء ليظهر كاملاً بغض النظر عن عدد الأصفار.
98
+ """
99
+ if price is None: return "0.0"
100
+ try:
101
+ p = float(price)
102
+ if p == 0: return "0.0"
103
+ # استخدام 8 خانات عشرية وإزالة الأصفار الزائدة من اليمين
104
+ return "{:.8f}".format(p).rstrip('0').rstrip('.')
105
+ except:
106
+ return str(price)
107
+
108
  # ==============================================================================
109
  # 🚀 تهيئة التطبيق ودورة الحياة (Lifespan)
110
  # ==============================================================================
 
201
  # [ 🚀 🚀 🚀 ] الدورة الموحدة (معدلة: منطق الصفقة الواحدة + وضع الإدارة)
202
  # ==============================================================================
203
  async def run_unified_cycle():
 
 
 
 
 
 
204
 
205
  log_buffer = StringIO()
206
 
 
239
 
240
  if entry > 0:
241
  pnl = ((current_price - entry) / entry) * 100
242
+ log_and_print(f" 💰 PnL الحالي: {pnl:.2f}% | السعر: {format_crypto_price(current_price)}")
243
  else:
244
  log_and_print(f" ⚠️ خطأ في سعر الدخول المسجل.")
245
 
246
  log_and_print(f"✅ [Cycle END] تم تحديث حالة الصفقة المفتوحة.")
247
  sys_state.set_cycle_end(logs=log_buffer.getvalue())
248
+ return
249
 
250
  # ============================================================
251
+ # 🔍 وضع البحث (Scanning Mode)
252
  # ============================================================
253
 
254
  # --- 1. الغربلة الأولية (L1) ---
 
440
  }
441
 
442
  # ==============================================================================
443
+ # 📊 [ 💡 GEM-ARCHITECT FIX: FULL PRICE PRECISION ]
444
  # ==============================================================================
445
 
446
  async def check_live_pnl_and_status():
447
  """
448
  [جديد] دالة يتم استدعاؤها كل 10 ثواني لتحديث الواجهة.
449
+ (إصلاح: يستخدم 8 خانات عشرية لعرض العملات الصغيرة مثل SHIB)
450
  """
451
  global trade_manager, data_manager, sys_state
452
 
 
506
  symbol_md = f"# {symbol}"
507
  pnl_md = f"<div style='font-size: 30px; color:{color}; text-align:center; font-weight:bold;'>{pnl_text}</div>"
508
 
509
+ # 5. [GEM-FIX] تنسيق الأرقام باستخدام الدالة الجديدة (Full Precision)
510
+ entry_fmt = format_crypto_price(trade['entry_price'])
511
+ curr_fmt = format_crypto_price(current_price)
512
+ tp_fmt = format_crypto_price(trade['tp_price'])
513
+ sl_fmt = format_crypto_price(trade['sl_price'])
514
+
515
  details_md = f"""
516
  <div style='background-color: #222; padding: 10px; border-radius: 5px;'>
517
+ <b>سعر الدخول:</b> {entry_fmt}<br>
518
+ <b>السعر الحالي:</b> {curr_fmt}<br>
519
+ <span style='color:#00ff00;'><b>TP:</b> {tp_fmt}</span><br>
520
+ <span style='color:#ff0000;'><b>SL:</b> {sl_fmt}</span>
521
  </div>
522
  """
523
 
524
+ # 6. رسم المخ��ط
525
  fig = None
526
  try:
527
  ohlcv = await data_manager.get_latest_ohlcv(symbol, '5m', 100)
 
529
  df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
530
  df['datetime'] = pd.to_datetime(df['timestamp'], unit='ms')
531
 
 
532
  fig = plt.figure(figsize=(10, 5))
533
  ax = fig.add_subplot(111)
534
 
 
535
  fig.patch.set_facecolor('#0b0f19')
536
  ax.set_facecolor('#0b0f19')
537
 
 
615
  outputs=[cycle_logs_output, status_markdown, live_symbol, live_pnl, live_details, live_chart, watchlist_output]
616
  )
617
 
618
+ timer = gr.Timer(10)
619
 
620
  timer.tick(
621
  fn=check_live_pnl_and_status,