Spaces:
Running
Running
saadrizvi09
commited on
Commit
Β·
5456a82
1
Parent(s):
eee8483
Fix auto-training import error
Browse files- Use correct function name: train_and_save_model instead of train_model
- Improve error handling with detailed messages
- Model training now works on first bot start
- simulated_trading.py +7 -6
simulated_trading.py
CHANGED
|
@@ -78,22 +78,23 @@ class SimulatedTradingSession:
|
|
| 78 |
def _ensure_model_trained(self):
|
| 79 |
"""Check if model exists, train if not"""
|
| 80 |
try:
|
| 81 |
-
from model_manager import load_model,
|
| 82 |
|
| 83 |
# Check if model exists
|
| 84 |
model_data = load_model(self.base_asset)
|
| 85 |
|
| 86 |
if model_data is None:
|
| 87 |
print(f"[HMM-SVR Bot] π No model found for {self.base_asset}, training now...")
|
| 88 |
-
print(f"[HMM-SVR Bot] β³ Training on
|
| 89 |
|
| 90 |
-
# Train model
|
| 91 |
-
|
| 92 |
|
| 93 |
-
if
|
| 94 |
print(f"[HMM-SVR Bot] β
Model trained successfully for {self.base_asset}")
|
| 95 |
else:
|
| 96 |
-
|
|
|
|
| 97 |
else:
|
| 98 |
print(f"[HMM-SVR Bot] β
Model already trained for {self.base_asset}")
|
| 99 |
|
|
|
|
| 78 |
def _ensure_model_trained(self):
|
| 79 |
"""Check if model exists, train if not"""
|
| 80 |
try:
|
| 81 |
+
from model_manager import load_model, train_and_save_model
|
| 82 |
|
| 83 |
# Check if model exists
|
| 84 |
model_data = load_model(self.base_asset)
|
| 85 |
|
| 86 |
if model_data is None:
|
| 87 |
print(f"[HMM-SVR Bot] π No model found for {self.base_asset}, training now...")
|
| 88 |
+
print(f"[HMM-SVR Bot] β³ Training on historical data (this may take 30-60 seconds)...")
|
| 89 |
|
| 90 |
+
# Train model
|
| 91 |
+
result = train_and_save_model(self.base_asset, n_states=3)
|
| 92 |
|
| 93 |
+
if result and 'error' not in result:
|
| 94 |
print(f"[HMM-SVR Bot] β
Model trained successfully for {self.base_asset}")
|
| 95 |
else:
|
| 96 |
+
error_msg = result.get('error', 'Unknown error') if result else 'Training failed'
|
| 97 |
+
print(f"[HMM-SVR Bot] β οΈ Model training failed: {error_msg}")
|
| 98 |
else:
|
| 99 |
print(f"[HMM-SVR Bot] β
Model already trained for {self.base_asset}")
|
| 100 |
|