Riy777 commited on
Commit
706140f
·
verified ·
1 Parent(s): e10266f

Update trade_manager.py

Browse files
Files changed (1) hide show
  1. trade_manager.py +29 -10
trade_manager.py CHANGED
@@ -1,5 +1,5 @@
1
  # ============================================================
2
- # 🛡️ trade_manager.py (V37.1 - GEM-Architect: Governance Data Loop)
3
  # ============================================================
4
 
5
  import asyncio
@@ -45,7 +45,7 @@ class TradeManager:
45
  }
46
 
47
  self.execution_lock = asyncio.Lock()
48
- print(f"🛡️ [TradeManager V37.1] Full System Online (Governance Learning Loop Active).")
49
 
50
  async def initialize_sentry_exchanges(self):
51
  """تهيئة المحفظة واستعادة الحالة"""
@@ -112,8 +112,9 @@ class TradeManager:
112
  print(f" -> ⚠️ [Skip] {symbol}: Insufficient 1m data.")
113
  continue
114
 
115
- # فحص Sniper
116
- sniper_result = await self.processor.check_sniper_entry(ohlcv_1m, order_book)
 
117
  sniper_signal = sniper_result.get('signal', 'WAIT')
118
  final_conf = sniper_result.get('confidence_prob', 0.0)
119
 
@@ -189,16 +190,19 @@ class TradeManager:
189
  if current_price <= 0.0: current_price = await self.data_manager.get_latest_price_async(symbol)
190
  entry_fee_usd = approved_size_usd * self.FEE_RATE
191
 
192
- # حفظ تفاصيل القرار كاملة من أجل التعلم
193
  decision_snapshot = {
194
  'components': signal_data.get('components', {}),
195
  'oracle_conf': signal_data.get('confidence', 0),
196
- 'governance_grade': gov_decision['grade'], # تسجيل الجودة
197
  'governance_score': gov_decision['governance_score'],
198
- 'governance_details': gov_decision['components'], # تفاصيل الـ 156 مؤشر (مختصرة في المجالات)
199
  'system_confidence': system_conf,
200
  'market_mood': market_mood,
201
- 'regime_at_entry': getattr(SystemLimits, 'CURRENT_REGIME', 'UNKNOWN')
 
 
 
202
  }
203
 
204
  new_trade = {
@@ -353,12 +357,27 @@ class TradeManager:
353
  if '1h' not in ohlcv_data: return
354
 
355
  curr_p = await self.data_manager.get_latest_price_async(symbol)
356
- l2 = await self.processor.process_compound_signal({'symbol': symbol, 'ohlcv': ohlcv_data, 'current_price': curr_p})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
357
  if not l2: return
358
 
359
  oracle = await self.processor.consult_oracle(l2)
360
  if oracle.get('action') == 'WAIT' or oracle.get('direction') == 'SHORT':
361
- print(f"🚨 [Oracle] Outlook Bearish. Exiting {symbol}...")
362
  await self.force_exit_by_manager(symbol, reason="Oracle_Bearish_Flip")
363
  return
364
  except Exception: pass
 
1
  # ============================================================
2
+ # 🛡️ trade_manager.py (V37.2 - GEM-Architect: Context Persistence)
3
  # ============================================================
4
 
5
  import asyncio
 
45
  }
46
 
47
  self.execution_lock = asyncio.Lock()
48
+ print(f"🛡️ [TradeManager V37.2] Full System Online (Context Aware).")
49
 
50
  async def initialize_sentry_exchanges(self):
51
  """تهيئة المحفظة واستعادة الحالة"""
 
112
  print(f" -> ⚠️ [Skip] {symbol}: Insufficient 1m data.")
113
  continue
114
 
115
+ # FIX: تمرير سياق الإشارة بالكامل لكي يرى Sniper الحدود الديناميكية
116
+ sniper_result = await self.processor.check_sniper_entry(ohlcv_1m, order_book, context_data=signal)
117
+
118
  sniper_signal = sniper_result.get('signal', 'WAIT')
119
  final_conf = sniper_result.get('confidence_prob', 0.0)
120
 
 
190
  if current_price <= 0.0: current_price = await self.data_manager.get_latest_price_async(symbol)
191
  entry_fee_usd = approved_size_usd * self.FEE_RATE
192
 
193
+ # ✅ FIX: حفظ الحدود الديناميكية والريجيم لاستخدامها لاحقاً
194
  decision_snapshot = {
195
  'components': signal_data.get('components', {}),
196
  'oracle_conf': signal_data.get('confidence', 0),
197
+ 'governance_grade': gov_decision['grade'],
198
  'governance_score': gov_decision['governance_score'],
199
+ 'governance_details': gov_decision['components'],
200
  'system_confidence': system_conf,
201
  'market_mood': market_mood,
202
+ 'regime_at_entry': getattr(SystemLimits, 'CURRENT_REGIME', 'UNKNOWN'),
203
+ # 🔥 Persist Critical Metadata for Guardians
204
+ 'dynamic_limits': signal_data.get('dynamic_limits', {}),
205
+ 'asset_regime': signal_data.get('asset_regime', 'UNKNOWN')
206
  }
207
 
208
  new_trade = {
 
357
  if '1h' not in ohlcv_data: return
358
 
359
  curr_p = await self.data_manager.get_latest_price_async(symbol)
360
+
361
+ # ✅ FIX: استرجاع السياق والحدود من بيانات الصفقة المحفوظة
362
+ decision_data = trade.get('decision_data', {})
363
+ saved_limits = decision_data.get('dynamic_limits', {})
364
+ saved_regime = decision_data.get('asset_regime', 'UNKNOWN')
365
+
366
+ # إعادة بناء raw_input مع السياق
367
+ raw_input = {
368
+ 'symbol': symbol,
369
+ 'ohlcv': ohlcv_data,
370
+ 'current_price': curr_p,
371
+ 'dynamic_limits': saved_limits, # Inject Context
372
+ 'asset_regime': saved_regime # Inject Context
373
+ }
374
+
375
+ l2 = await self.processor.process_compound_signal(raw_input)
376
  if not l2: return
377
 
378
  oracle = await self.processor.consult_oracle(l2)
379
  if oracle.get('action') == 'WAIT' or oracle.get('direction') == 'SHORT':
380
+ print(f"🚨 [Oracle] Outlook Bearish (Re-Check). Exiting {symbol}...")
381
  await self.force_exit_by_manager(symbol, reason="Oracle_Bearish_Flip")
382
  return
383
  except Exception: pass