Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -355,6 +355,22 @@ async def predict_signal(symbol, timeframe="1h"):
|
|
| 355 |
}
|
| 356 |
except Exception as e: return {"status": "error", "message": str(e)}
|
| 357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
# --- 🧬 FONCTION D'ÉVOLUTION (MUTATION) ---
|
| 359 |
def mutate_agent(symbol, timeframe, success=True):
|
| 360 |
try:
|
|
@@ -448,20 +464,34 @@ def set_bot_mode(mode):
|
|
| 448 |
return {"status": "success", "mode": "DREAM" if DREAM_MODE_ACTIVE else "LIVE", "message": msg}
|
| 449 |
|
| 450 |
async def auto_predict_loop():
|
|
|
|
| 451 |
while True:
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
|
| 466 |
async def dream_simulation_loop():
|
| 467 |
"""Le Spinosaurus rêve sur TOUS les terrains (Multi-Timeframe)"""
|
|
@@ -654,13 +684,15 @@ def run_auto_pilot():
|
|
| 654 |
try:
|
| 655 |
loop = asyncio.new_event_loop()
|
| 656 |
asyncio.set_event_loop(loop)
|
| 657 |
-
|
| 658 |
-
|
|
|
|
| 659 |
loop.create_task(dream_simulation_loop())
|
| 660 |
loop.run_forever()
|
| 661 |
except Exception as e:
|
| 662 |
print(f"⚠️ Erreur boucle Auto-Pilote : {e}")
|
| 663 |
_auto_pilot_started = False
|
|
|
|
| 664 |
|
| 665 |
if __name__ == "__main__":
|
| 666 |
try: threading.Thread(target=run_auto_pilot, daemon=True).start()
|
|
|
|
| 355 |
}
|
| 356 |
except Exception as e: return {"status": "error", "message": str(e)}
|
| 357 |
|
| 358 |
+
# --- 🛡️ STATE MANAGER : LE DICTIONNAIRE D'ÉTAT GLOBAL ---
|
| 359 |
+
# Clé : (symbol, timeframe) -> Valeur : Les données du dernier signal
|
| 360 |
+
active_signals_state = {}
|
| 361 |
+
|
| 362 |
+
def clean_old_db_signals(symbol, timeframe):
|
| 363 |
+
"""Passe les anciens signaux non résolus en statut REMPLACÉ pour laisser la place aux nouveaux."""
|
| 364 |
+
try:
|
| 365 |
+
with sqlite3.connect(DB_NAME) as conn:
|
| 366 |
+
conn.execute(
|
| 367 |
+
"UPDATE signals SET status = 'REMPLACÉ ♻️', confirmed = 0 "
|
| 368 |
+
"WHERE symbol = ? AND timeframe = ? AND status = 'EN_COURS'",
|
| 369 |
+
(symbol, timeframe)
|
| 370 |
+
)
|
| 371 |
+
conn.commit()
|
| 372 |
+
except Exception as e:
|
| 373 |
+
print(f"⚠️ Erreur nettoyage DB : {e}")
|
| 374 |
# --- 🧬 FONCTION D'ÉVOLUTION (MUTATION) ---
|
| 375 |
def mutate_agent(symbol, timeframe, success=True):
|
| 376 |
try:
|
|
|
|
| 464 |
return {"status": "success", "mode": "DREAM" if DREAM_MODE_ACTIVE else "LIVE", "message": msg}
|
| 465 |
|
| 466 |
async def auto_predict_loop():
|
| 467 |
+
print("👁️ [SCANNER] Le Cerveau Global est en ligne (H24)...")
|
| 468 |
while True:
|
| 469 |
+
for symbol in AUTO_SYMBOLS:
|
| 470 |
+
for tf in AUTO_TIMEFRAMES:
|
| 471 |
+
try:
|
| 472 |
+
# 1️⃣ L'IA RÉFLÉCHIT EN CONTINU (Aucun blocage)
|
| 473 |
+
pred = await predict_signal(symbol, timeframe=tf)
|
| 474 |
+
|
| 475 |
+
if pred and pred.get("status") == "success":
|
| 476 |
+
# 2️⃣ NETTOYAGE DB : On archive l'ancien signal avant d'enregistrer le nouveau
|
| 477 |
+
clean_old_db_signals(symbol, tf)
|
| 478 |
+
|
| 479 |
+
# 3️⃣ ÉCRASEMENT MATHÉMATIQUE : Le nouveau signal tue l'ancien instantanément en RAM
|
| 480 |
+
active_signals_state[(symbol, tf)] = pred
|
| 481 |
+
|
| 482 |
+
# 4️⃣ ACTION : C'est ici que le mode intervient !
|
| 483 |
+
if not DREAM_MODE_ACTIVE:
|
| 484 |
+
print(f"🎯 [LIVE] Nouveau signal maître pris en compte : {symbol} [{tf}]")
|
| 485 |
+
# C'est ici que tu déclencheras l'API KuCoin/MT5 pour prendre le trade
|
| 486 |
+
else:
|
| 487 |
+
# En mode DREAM, on log juste ou on laisse le backtest tourner
|
| 488 |
+
pass
|
| 489 |
+
|
| 490 |
+
await asyncio.sleep(5) # Sécurité anti-spam API KuCoin
|
| 491 |
+
except Exception as e:
|
| 492 |
+
print(f"⚠️ Erreur Scanner sur {symbol} [{tf}] : {e}")
|
| 493 |
+
|
| 494 |
+
await asyncio.sleep(60) # Pause entre deux scans complets du marché
|
| 495 |
|
| 496 |
async def dream_simulation_loop():
|
| 497 |
"""Le Spinosaurus rêve sur TOUS les terrains (Multi-Timeframe)"""
|
|
|
|
| 684 |
try:
|
| 685 |
loop = asyncio.new_event_loop()
|
| 686 |
asyncio.set_event_loop(loop)
|
| 687 |
+
|
| 688 |
+
# Le Cerveau (H24) + Le Rêve (Mutations) tournent en parallèle
|
| 689 |
+
loop.create_task(auto_predict_loop())
|
| 690 |
loop.create_task(dream_simulation_loop())
|
| 691 |
loop.run_forever()
|
| 692 |
except Exception as e:
|
| 693 |
print(f"⚠️ Erreur boucle Auto-Pilote : {e}")
|
| 694 |
_auto_pilot_started = False
|
| 695 |
+
_auto_pilot_started = False
|
| 696 |
|
| 697 |
if __name__ == "__main__":
|
| 698 |
try: threading.Thread(target=run_auto_pilot, daemon=True).start()
|