Spaces:
Sleeping
Sleeping
Update learning_hub/adaptive_hub.py
Browse files- learning_hub/adaptive_hub.py +26 -21
learning_hub/adaptive_hub.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# ==============================================================================
|
| 2 |
# 🧠 learning_hub/adaptive_hub.py
|
| 3 |
-
# (V68.
|
| 4 |
# ==============================================================================
|
| 5 |
|
| 6 |
import json
|
|
@@ -55,21 +55,28 @@ class AdaptiveHub:
|
|
| 55 |
self.dna_file_key = "learning/coin_type_dna_v2.json"
|
| 56 |
self.strategies: Dict[str, StrategyDNA] = {}
|
| 57 |
self.tuner = None
|
| 58 |
-
print("🧠 [AdaptiveHub V68.
|
| 59 |
|
| 60 |
async def initialize(self):
|
| 61 |
try:
|
| 62 |
-
# ⚠️ هام:
|
| 63 |
-
#
|
| 64 |
-
# نصيحة: بعد هذا التحديث، يفضل عمل "Reset" من الواجهة لمسح الذاكرة القديمة الصارمة.
|
| 65 |
if self.r2:
|
|
|
|
|
|
|
| 66 |
data = await self.r2.get_file_json_async(self.dna_file_key)
|
| 67 |
if data:
|
| 68 |
self._load_from_dict(data)
|
| 69 |
print(" 🧠 Loaded existing DNA from R2.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
else:
|
| 71 |
self._create_coin_type_defaults()
|
| 72 |
-
print(" 🧠 Created NEW
|
| 73 |
else:
|
| 74 |
self._create_coin_type_defaults()
|
| 75 |
except Exception:
|
|
@@ -77,21 +84,19 @@ class AdaptiveHub:
|
|
| 77 |
|
| 78 |
def _create_coin_type_defaults(self):
|
| 79 |
"""
|
| 80 |
-
Implements the '
|
| 81 |
-
|
|
|
|
| 82 |
"""
|
| 83 |
-
# 1. SAFE_BOTTOM (
|
| 84 |
-
# Old: Titan 0.70 -> New: 0.60
|
| 85 |
-
# Old: Pattern 0.60 -> New: 0.50
|
| 86 |
-
# Old: Min Score 0.75 -> New: 0.65
|
| 87 |
self.strategies["SAFE_BOTTOM"] = StrategyDNA(
|
| 88 |
"SAFE_BOTTOM",
|
| 89 |
model_weights={"titan": 0.40, "patt": 0.40, "mc": 0.20},
|
| 90 |
-
ob_settings={"wall_ratio_limit": 0.40},
|
| 91 |
filters={
|
| 92 |
"l2_gate_titan": 0.60, "l2_gate_pattern": 0.50, "l2_gate_mc": 0.50,
|
| 93 |
"l2_min_score": 0.65,
|
| 94 |
-
"l3_oracle_thresh": 0.
|
| 95 |
"l4_sniper_thresh": 0.40
|
| 96 |
},
|
| 97 |
guards={
|
|
@@ -99,7 +104,7 @@ class AdaptiveHub:
|
|
| 99 |
}
|
| 100 |
)
|
| 101 |
|
| 102 |
-
# 2. MOMENTUM_LAUNCH (
|
| 103 |
self.strategies["MOMENTUM_LAUNCH"] = StrategyDNA(
|
| 104 |
"MOMENTUM_LAUNCH",
|
| 105 |
model_weights={"titan": 0.40, "patt": 0.40, "mc": 0.20},
|
|
@@ -107,7 +112,7 @@ class AdaptiveHub:
|
|
| 107 |
filters={
|
| 108 |
"l2_gate_titan": 0.60, "l2_gate_pattern": 0.50, "l2_gate_mc": 0.50,
|
| 109 |
"l2_min_score": 0.65,
|
| 110 |
-
"l3_oracle_thresh": 0.
|
| 111 |
"l4_sniper_thresh": 0.40
|
| 112 |
},
|
| 113 |
guards={
|
|
@@ -115,7 +120,7 @@ class AdaptiveHub:
|
|
| 115 |
}
|
| 116 |
)
|
| 117 |
|
| 118 |
-
# 3. ACCUMULATION_SQUEEZE (
|
| 119 |
self.strategies["ACCUMULATION_SQUEEZE"] = StrategyDNA(
|
| 120 |
"ACCUMULATION_SQUEEZE",
|
| 121 |
model_weights={"titan": 0.40, "patt": 0.40, "mc": 0.20},
|
|
@@ -123,7 +128,7 @@ class AdaptiveHub:
|
|
| 123 |
filters={
|
| 124 |
"l2_gate_titan": 0.60, "l2_gate_pattern": 0.50, "l2_gate_mc": 0.50,
|
| 125 |
"l2_min_score": 0.65,
|
| 126 |
-
"l3_oracle_thresh": 0.
|
| 127 |
"l4_sniper_thresh": 0.40
|
| 128 |
},
|
| 129 |
guards={
|
|
@@ -156,14 +161,14 @@ class AdaptiveHub:
|
|
| 156 |
"w_patt": mw.get("patt", 0.40),
|
| 157 |
"w_mc": mw.get("mc", 0.20),
|
| 158 |
|
| 159 |
-
# Gates & Scores
|
| 160 |
"l2_gate_titan": f.get("l2_gate_titan", 0.60),
|
| 161 |
"l2_gate_pattern": f.get("l2_gate_pattern", 0.50),
|
| 162 |
"l2_gate_mc": f.get("l2_gate_mc", 0.50),
|
| 163 |
"l2_min_score": f.get("l2_min_score", 0.65),
|
| 164 |
|
| 165 |
# Oracle & Sniper
|
| 166 |
-
"l3_oracle_thresh": f.get("l3_oracle_thresh", 0.
|
| 167 |
"l4_sniper_thresh": f.get("l4_sniper_thresh", 0.40),
|
| 168 |
"l4_ob_wall_ratio": dna.ob_settings.get("wall_ratio_limit", 0.35),
|
| 169 |
|
|
@@ -181,4 +186,4 @@ class AdaptiveHub:
|
|
| 181 |
def get_status(self) -> str:
|
| 182 |
dna = self.strategies.get("SAFE_BOTTOM")
|
| 183 |
if not dna: return "Initializing..."
|
| 184 |
-
return f"
|
|
|
|
| 1 |
# ==============================================================================
|
| 2 |
# 🧠 learning_hub/adaptive_hub.py
|
| 3 |
+
# (V68.1 - GEM-Architect: Realistic Oracle Calibration [0.60])
|
| 4 |
# ==============================================================================
|
| 5 |
|
| 6 |
import json
|
|
|
|
| 55 |
self.dna_file_key = "learning/coin_type_dna_v2.json"
|
| 56 |
self.strategies: Dict[str, StrategyDNA] = {}
|
| 57 |
self.tuner = None
|
| 58 |
+
print("🧠 [AdaptiveHub V68.1] Realistic Oracle Calibration (0.60) Loaded.")
|
| 59 |
|
| 60 |
async def initialize(self):
|
| 61 |
try:
|
| 62 |
+
# ⚠️ هام: التحديث الإجباري لتطبيق العتبات الجديدة الواقعية
|
| 63 |
+
# سنقوم بإنشاء القيم الافتراضية الجديدة وتجاهل القديمة الصارمة جداً لهذه الجلسة
|
|
|
|
| 64 |
if self.r2:
|
| 65 |
+
# محاولة قراءة الملف، لكن إذا كانت العتبات قديمة (0.90) يفضل استبدالها
|
| 66 |
+
# هنا سأقوم بتحميلها، والموالف (Tuner) سيقوم بالتعديل، أو يمكنك عمل Reset من الواجهة
|
| 67 |
data = await self.r2.get_file_json_async(self.dna_file_key)
|
| 68 |
if data:
|
| 69 |
self._load_from_dict(data)
|
| 70 |
print(" 🧠 Loaded existing DNA from R2.")
|
| 71 |
+
|
| 72 |
+
# 🔥 Auto-Correction: If Oracle thresh is too high, force lower it
|
| 73 |
+
for k, strat in self.strategies.items():
|
| 74 |
+
if strat.filters.get("l3_oracle_thresh", 0.90) > 0.70:
|
| 75 |
+
print(f" ⚠️ [Correction] Lowering Oracle for {k} to 0.60")
|
| 76 |
+
strat.filters["l3_oracle_thresh"] = 0.60
|
| 77 |
else:
|
| 78 |
self._create_coin_type_defaults()
|
| 79 |
+
print(" 🧠 Created NEW Realistic Defaults.")
|
| 80 |
else:
|
| 81 |
self._create_coin_type_defaults()
|
| 82 |
except Exception:
|
|
|
|
| 84 |
|
| 85 |
def _create_coin_type_defaults(self):
|
| 86 |
"""
|
| 87 |
+
Implements the 'Realistic' Profile based on user diagnostics.
|
| 88 |
+
Oracle Max: 0.75 -> Set Threshold: 0.60
|
| 89 |
+
L2 Gates: Lowered to allow flow.
|
| 90 |
"""
|
| 91 |
+
# 1. SAFE_BOTTOM (Realistic)
|
|
|
|
|
|
|
|
|
|
| 92 |
self.strategies["SAFE_BOTTOM"] = StrategyDNA(
|
| 93 |
"SAFE_BOTTOM",
|
| 94 |
model_weights={"titan": 0.40, "patt": 0.40, "mc": 0.20},
|
| 95 |
+
ob_settings={"wall_ratio_limit": 0.40},
|
| 96 |
filters={
|
| 97 |
"l2_gate_titan": 0.60, "l2_gate_pattern": 0.50, "l2_gate_mc": 0.50,
|
| 98 |
"l2_min_score": 0.65,
|
| 99 |
+
"l3_oracle_thresh": 0.60, # ✅ Corrected: Realistic (>55, <75)
|
| 100 |
"l4_sniper_thresh": 0.40
|
| 101 |
},
|
| 102 |
guards={
|
|
|
|
| 104 |
}
|
| 105 |
)
|
| 106 |
|
| 107 |
+
# 2. MOMENTUM_LAUNCH (Realistic)
|
| 108 |
self.strategies["MOMENTUM_LAUNCH"] = StrategyDNA(
|
| 109 |
"MOMENTUM_LAUNCH",
|
| 110 |
model_weights={"titan": 0.40, "patt": 0.40, "mc": 0.20},
|
|
|
|
| 112 |
filters={
|
| 113 |
"l2_gate_titan": 0.60, "l2_gate_pattern": 0.50, "l2_gate_mc": 0.50,
|
| 114 |
"l2_min_score": 0.65,
|
| 115 |
+
"l3_oracle_thresh": 0.60, # ✅ Corrected
|
| 116 |
"l4_sniper_thresh": 0.40
|
| 117 |
},
|
| 118 |
guards={
|
|
|
|
| 120 |
}
|
| 121 |
)
|
| 122 |
|
| 123 |
+
# 3. ACCUMULATION_SQUEEZE (Realistic)
|
| 124 |
self.strategies["ACCUMULATION_SQUEEZE"] = StrategyDNA(
|
| 125 |
"ACCUMULATION_SQUEEZE",
|
| 126 |
model_weights={"titan": 0.40, "patt": 0.40, "mc": 0.20},
|
|
|
|
| 128 |
filters={
|
| 129 |
"l2_gate_titan": 0.60, "l2_gate_pattern": 0.50, "l2_gate_mc": 0.50,
|
| 130 |
"l2_min_score": 0.65,
|
| 131 |
+
"l3_oracle_thresh": 0.60, # ✅ Corrected
|
| 132 |
"l4_sniper_thresh": 0.40
|
| 133 |
},
|
| 134 |
guards={
|
|
|
|
| 161 |
"w_patt": mw.get("patt", 0.40),
|
| 162 |
"w_mc": mw.get("mc", 0.20),
|
| 163 |
|
| 164 |
+
# Gates & Scores
|
| 165 |
"l2_gate_titan": f.get("l2_gate_titan", 0.60),
|
| 166 |
"l2_gate_pattern": f.get("l2_gate_pattern", 0.50),
|
| 167 |
"l2_gate_mc": f.get("l2_gate_mc", 0.50),
|
| 168 |
"l2_min_score": f.get("l2_min_score", 0.65),
|
| 169 |
|
| 170 |
# Oracle & Sniper
|
| 171 |
+
"l3_oracle_thresh": f.get("l3_oracle_thresh", 0.60), # ✅ Ensure Value is Passed
|
| 172 |
"l4_sniper_thresh": f.get("l4_sniper_thresh", 0.40),
|
| 173 |
"l4_ob_wall_ratio": dna.ob_settings.get("wall_ratio_limit", 0.35),
|
| 174 |
|
|
|
|
| 186 |
def get_status(self) -> str:
|
| 187 |
dna = self.strategies.get("SAFE_BOTTOM")
|
| 188 |
if not dna: return "Initializing..."
|
| 189 |
+
return f"Realistic Mode (Oracle>0.60) | SB: {dna.trade_count}/30 | ML: {self.strategies['MOMENTUM_LAUNCH'].trade_count}/30"
|