Nexo-S commited on
Commit
de4f4ea
·
verified ·
1 Parent(s): e09af54

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -17
app.py CHANGED
@@ -501,33 +501,53 @@ def mutate_agent(symbol, timeframe, regime, success=True):
501
  backup_db_to_hf()
502
  except Exception as e: print(f"🧬 Erreur Mutation: {e}")
503
 
504
- # --- 🌙 DREAM LOOP ---
505
  async def dream_simulation_loop():
506
  while True:
507
  if DREAM_MODE_ACTIVE:
508
- print("GO ALLER A LA SALLE🥊")
509
  for symbol in AUTO_SYMBOLS:
510
  for tf in AUTO_TIMEFRAMES:
511
  try:
512
  df = prepare_features_sync(symbol, timeframe=tf, limit_bars=200)
513
  if df.empty or len(df) < 50: continue
514
 
 
515
  idx = random.randint(10, len(df) - 30)
516
- pred = await predict_signal(symbol, timeframe=tf)
517
- if pred.get("status") == "success":
518
- current_scenario = pred.get("scenario", 3)
519
- future_data = df.iloc[idx+1 : idx+25]
520
- win = False
521
- for _, row in future_data.iterrows():
522
- if pred["final_score"] > 0.5:
523
- if row['high'] >= pred['tp']: win = True; break
524
- if row['low'] <= pred['sl']: win = False; break
525
- else:
526
- if row['low'] <= pred['tp']: win = True; break
527
- if row['high'] >= pred['sl']: win = False; break
528
- mutate_agent(symbol, tf, current_scenario, success=win)
529
- await asyncio.sleep(3)
530
- except: pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
  await asyncio.sleep(60)
532
 
533
  def should_send_signal(symbol, timeframe, proba):
 
501
  backup_db_to_hf()
502
  except Exception as e: print(f"🧬 Erreur Mutation: {e}")
503
 
504
+ # --- 🌙 DREAM LOOP V31 (CORRIGÉE) ---
505
  async def dream_simulation_loop():
506
  while True:
507
  if DREAM_MODE_ACTIVE:
508
+ print("🌙 [DREAM MODE] Le bot rêve et s'entraîne à la salle... 🥊")
509
  for symbol in AUTO_SYMBOLS:
510
  for tf in AUTO_TIMEFRAMES:
511
  try:
512
  df = prepare_features_sync(symbol, timeframe=tf, limit_bars=200)
513
  if df.empty or len(df) < 50: continue
514
 
515
+ # 1. On voyage dans le temps (une bougie au hasard)
516
  idx = random.randint(10, len(df) - 30)
517
+ row_actuelle = df.iloc[idx]
518
+ prix = float(row_actuelle['close'])
519
+ atr = float(row_actuelle['ATR'])
520
+
521
+ # 2. On récupère le régime de marché (Scénario)
522
+ # Pour le Dream Mode rapide, on utilise une valeur par défaut ou on pourrait la calculer.
523
+ current_scenario = 3
524
+
525
+ # 3. On extrait l'ADN actuel (les multiplicateurs)
526
+ with sqlite3.connect(DB_NAME) as conn:
527
+ res = conn.execute("SELECT tp_mult, sl_mult FROM agent_logic WHERE symbol = ? AND timeframe = ? AND regime = ?", (symbol, tf, current_scenario)).fetchone()
528
+ tp_m, sl_m = res if res else (1.5, 1.0)
529
+
530
+ # 4. Simulation de combat (Long ou Short) depuis CETTE époque
531
+ is_long = random.choice([True, False])
532
+ tp = prix + (atr * tp_m) if is_long else prix - (atr * tp_m)
533
+ sl = prix - (atr * sl_m) if is_long else prix + (atr * sl_m)
534
+
535
+ # 5. On regarde les 24 bougies suivantes pour voir qui gagne
536
+ future_data = df.iloc[idx+1 : idx+25]
537
+ win = False
538
+ for _, row in future_data.iterrows():
539
+ if is_long:
540
+ if row['high'] >= tp: win = True; break
541
+ if row['low'] <= sl: win = False; break
542
+ else:
543
+ if row['low'] <= tp: win = True; break
544
+ if row['high'] >= sl: win = False; break
545
+
546
+ # 6. 🧬 ÉVOLUTION : On récompense ou on punit l'ADN !
547
+ mutate_agent(symbol, tf, current_scenario, success=win)
548
+ await asyncio.sleep(2)
549
+ except Exception as e:
550
+ pass # On reste silencieux pendant le sommeil
551
  await asyncio.sleep(60)
552
 
553
  def should_send_signal(symbol, timeframe, proba):