Spaces:
Paused
Paused
Update learning_hub/adaptive_hub.py
Browse files- learning_hub/adaptive_hub.py +15 -3
learning_hub/adaptive_hub.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# ==============================================================================
|
| 2 |
# 🧠 learning_hub/adaptive_hub.py
|
| 3 |
-
# (V61.
|
| 4 |
# ==============================================================================
|
| 5 |
|
| 6 |
import json
|
|
@@ -70,7 +70,9 @@ class StrategyDNA:
|
|
| 70 |
"model_weights": self.model_weights,
|
| 71 |
"ob_settings": self.ob_settings,
|
| 72 |
"backtest_performance": self.backtest_performance,
|
| 73 |
-
"stats": self.stats
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
|
| 76 |
class AdaptiveHub:
|
|
@@ -79,7 +81,7 @@ class AdaptiveHub:
|
|
| 79 |
self.dna_file_key = "learning/strategic_dna_v61_context.json"
|
| 80 |
self.current_market_regime = "RANGE"
|
| 81 |
self.strategies: Dict[str, StrategyDNA] = {}
|
| 82 |
-
print("🧠 [AdaptiveHub V61.
|
| 83 |
|
| 84 |
def get_learning_progress(self) -> str:
|
| 85 |
"""يعيد نسبة التقدم في التعلم السريع"""
|
|
@@ -169,6 +171,10 @@ class AdaptiveHub:
|
|
| 169 |
dna.delta_weekly = val.get("delta_weekly", dna.delta_weekly)
|
| 170 |
dna.delta_monthly = val.get("delta_monthly", dna.delta_monthly)
|
| 171 |
dna.stats = val.get("stats", {"wins":0, "losses":0})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
self.strategies[key] = dna
|
| 173 |
self.current_market_regime = data.get("current_regime", "RANGE")
|
| 174 |
|
|
@@ -240,12 +246,18 @@ class AdaptiveHub:
|
|
| 240 |
dna = self.strategies[self.current_market_regime]
|
| 241 |
dna.trade_buffer.append(trade_data)
|
| 242 |
|
|
|
|
|
|
|
|
|
|
| 243 |
if len(dna.trade_buffer) >= 100:
|
| 244 |
print(f"🎓 [Fast Learner] Batch of 100 trades reached. Analyzing...")
|
| 245 |
self._process_fast_learning_batch(dna)
|
| 246 |
dna.trade_buffer.clear()
|
| 247 |
await self._save_state_to_r2()
|
| 248 |
self._inject_current_parameters()
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
def _process_fast_learning_batch(self, dna: StrategyDNA):
|
| 251 |
models = ['l3_oracle_thresh', 'l4_sniper_thresh']
|
|
|
|
| 1 |
# ==============================================================================
|
| 2 |
# 🧠 learning_hub/adaptive_hub.py
|
| 3 |
+
# (V61.1 - GEM-Architect: Persistence Fix)
|
| 4 |
# ==============================================================================
|
| 5 |
|
| 6 |
import json
|
|
|
|
| 70 |
"model_weights": self.model_weights,
|
| 71 |
"ob_settings": self.ob_settings,
|
| 72 |
"backtest_performance": self.backtest_performance,
|
| 73 |
+
"stats": self.stats,
|
| 74 |
+
# ✅ FIX: Save the trade buffer to R2
|
| 75 |
+
"trade_buffer": self.trade_buffer
|
| 76 |
}
|
| 77 |
|
| 78 |
class AdaptiveHub:
|
|
|
|
| 81 |
self.dna_file_key = "learning/strategic_dna_v61_context.json"
|
| 82 |
self.current_market_regime = "RANGE"
|
| 83 |
self.strategies: Dict[str, StrategyDNA] = {}
|
| 84 |
+
print("🧠 [AdaptiveHub V61.1] Persistence & Context Engine Ready.")
|
| 85 |
|
| 86 |
def get_learning_progress(self) -> str:
|
| 87 |
"""يعيد نسبة التقدم في التعلم السريع"""
|
|
|
|
| 171 |
dna.delta_weekly = val.get("delta_weekly", dna.delta_weekly)
|
| 172 |
dna.delta_monthly = val.get("delta_monthly", dna.delta_monthly)
|
| 173 |
dna.stats = val.get("stats", {"wins":0, "losses":0})
|
| 174 |
+
|
| 175 |
+
# ✅ FIX: Load the trade buffer so progress is not lost (0/100)
|
| 176 |
+
dna.trade_buffer = val.get("trade_buffer", [])
|
| 177 |
+
|
| 178 |
self.strategies[key] = dna
|
| 179 |
self.current_market_regime = data.get("current_regime", "RANGE")
|
| 180 |
|
|
|
|
| 246 |
dna = self.strategies[self.current_market_regime]
|
| 247 |
dna.trade_buffer.append(trade_data)
|
| 248 |
|
| 249 |
+
# حفظ التقدم في كل مرة تضاف صفقة (اختياري للأمان) أو الاعتماد على الحفظ الدوري
|
| 250 |
+
# هنا سنعتمد على الحفظ عند الاكتمال أو عند الخروج الآمن
|
| 251 |
+
|
| 252 |
if len(dna.trade_buffer) >= 100:
|
| 253 |
print(f"🎓 [Fast Learner] Batch of 100 trades reached. Analyzing...")
|
| 254 |
self._process_fast_learning_batch(dna)
|
| 255 |
dna.trade_buffer.clear()
|
| 256 |
await self._save_state_to_r2()
|
| 257 |
self._inject_current_parameters()
|
| 258 |
+
else:
|
| 259 |
+
# حفظ جزئي كل صفقة لضمان عدم الضياع عند الريستارت
|
| 260 |
+
asyncio.create_task(self._save_state_to_r2())
|
| 261 |
|
| 262 |
def _process_fast_learning_batch(self, dna: StrategyDNA):
|
| 263 |
models = ['l3_oracle_thresh', 'l4_sniper_thresh']
|