Riy777 commited on
Commit
e3314ff
·
verified ·
1 Parent(s): 20dcc06

Update learning_hub/adaptive_hub.py

Browse files
Files changed (1) hide show
  1. learning_hub/adaptive_hub.py +30 -2
learning_hub/adaptive_hub.py CHANGED
@@ -1,6 +1,6 @@
1
  # ==============================================================================
2
  # 🧠 learning_hub/adaptive_hub.py
3
- # (V54.0 - GEM-Architect: Time Lord Support)
4
  # ==============================================================================
5
 
6
  import json
@@ -35,7 +35,7 @@ class AdaptiveHub:
35
  self.dna_file_key = "learning/strategic_dna_v5_struct.json"
36
  self.current_market_regime = "RANGE"
37
  self.strategies: Dict[str, StrategyDNA] = {}
38
- print("🧠 [AdaptiveHub V54.0] Time Lord Core Initialized.")
39
 
40
  async def initialize(self):
41
  try:
@@ -65,6 +65,34 @@ class AdaptiveHub:
65
  self.strategies[key] = StrategyDNA(val["name"], val["model_weights"], val["ob_settings"], val["filters"], val.get("guard_settings", {}))
66
  self.current_market_regime = data.get("current_regime", "RANGE")
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  def _inject_current_parameters(self):
69
  if self.current_market_regime not in self.strategies: return
70
  active_dna = self.strategies[self.current_market_regime]
 
1
  # ==============================================================================
2
  # 🧠 learning_hub/adaptive_hub.py
3
+ # (V54.1 - GEM-Architect: Fix Missing Method)
4
  # ==============================================================================
5
 
6
  import json
 
35
  self.dna_file_key = "learning/strategic_dna_v5_struct.json"
36
  self.current_market_regime = "RANGE"
37
  self.strategies: Dict[str, StrategyDNA] = {}
38
+ print("🧠 [AdaptiveHub V54.1] Core Initialized (Method Restored).")
39
 
40
  async def initialize(self):
41
  try:
 
65
  self.strategies[key] = StrategyDNA(val["name"], val["model_weights"], val["ob_settings"], val["filters"], val.get("guard_settings", {}))
66
  self.current_market_regime = data.get("current_regime", "RANGE")
67
 
68
+ # ✅ الدالة المفقودة تمت استعادتها هنا
69
+ async def register_trade_outcome(self, trade_data: Dict[str, Any]):
70
+ try:
71
+ # نتأكد من وجود البيانات، أحياناً قد تأتي كائن Trade وأحياناً Dict
72
+ # إذا كانت كائن، نحولها لـ dict أو نصل للخاصية مباشرة
73
+ pnl = 0.0
74
+ if isinstance(trade_data, dict):
75
+ pnl = trade_data.get('profit_pct', 0.0)
76
+ # دعم للتسميات المختلفة
77
+ if 'pnl_percent' in trade_data: pnl = trade_data['pnl_percent']
78
+ else:
79
+ # في حال كان كائناً (Object)
80
+ pnl = getattr(trade_data, 'profit_pct', 0.0)
81
+
82
+ is_win = pnl > 0
83
+
84
+ if self.current_market_regime in self.strategies:
85
+ active_dna = self.strategies[self.current_market_regime]
86
+ if is_win: active_dna.stats["wins"] += 1
87
+ else: active_dna.stats["losses"] += 1
88
+
89
+ # طباعة خفيفة للتأكد
90
+ # print(f"🧠 [AdaptiveHub] Learned: {self.current_market_regime} | Win? {is_win}")
91
+
92
+ except Exception as e:
93
+ print(f"❌ [AdaptiveHub] Trade Analysis Error: {e}")
94
+ traceback.print_exc()
95
+
96
  def _inject_current_parameters(self):
97
  if self.current_market_regime not in self.strategies: return
98
  active_dna = self.strategies[self.current_market_regime]