Nexo-S commited on
Commit
09f7d3b
·
verified ·
1 Parent(s): 4dd3bc0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -13
app.py CHANGED
@@ -432,25 +432,40 @@ async def auto_predict_loop():
432
  def keep_alive_ping():
433
  return {"status": "awake", "time": datetime.now(timezone.utc).isoformat()}
434
 
435
- def confirm_trade_api(trade_id):
436
  try:
437
- # On s'assure que l'ID est bien un entier
438
  t_id = int(trade_id)
 
439
 
440
  with sqlite3.connect(DB_NAME) as conn:
 
441
  cursor = conn.cursor()
442
- # On met à jour
443
- cursor.execute("UPDATE signals SET confirmed = 1 WHERE id = ?", (t_id,))
444
 
445
- if cursor.rowcount == 0:
446
- return {"status": "error", "message": f"Signal {t_id} introuvable dans la DB."}
447
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
448
  conn.commit()
449
 
450
- print(f"⚓ [HANDSHAKE] Signal {t_id} activé officiellement.")
451
- return {"status": "success", "message": f"Signal {t_id} confirmé et activé."}
452
  except Exception as e:
453
- print(f"❌ Erreur Handshake : {e}")
454
  return {"status": "error", "message": str(e)}
455
 
456
  async def check_data_count(symbol):
@@ -797,13 +812,14 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as iface:
797
  # =========================================================
798
  # --- ⚓ LE HANDSHAKE API (SECRET POUR PTERODACTYL) ---
799
  # =========================================================
800
- api_id_input = gr.Textbox(visible=False)
 
801
  api_confirm_btn = gr.Button(visible=False)
802
  api_confirm_btn.click(
803
  fn=confirm_trade_api,
804
- inputs=api_id_input,
805
  outputs=gr.JSON(),
806
- api_name="confirm_trade_api" # <--- LA CLÉ EST ICI
807
  )
808
  # =========================================================
809
 
 
432
  def keep_alive_ping():
433
  return {"status": "awake", "time": datetime.now(timezone.utc).isoformat()}
434
 
435
+ def confirm_trade_api(trade_id, real_price):
436
  try:
 
437
  t_id = int(trade_id)
438
+ r_price = float(real_price)
439
 
440
  with sqlite3.connect(DB_NAME) as conn:
441
+ conn.row_factory = sqlite3.Row
442
  cursor = conn.cursor()
 
 
443
 
444
+ # 1. On récupère les données Kucoin (théoriques)
445
+ cursor.execute("SELECT price, tp, sl FROM signals WHERE id = ?", (t_id,))
446
+ t = cursor.fetchone()
447
+
448
+ if not t: return {"status": "error", "message": "Signal non trouvé"}
449
+
450
+ # 2. On calcule l'écart (ex: +10$)
451
+ ecart = r_price - t['price']
452
+
453
+ # 3. On décale le TP et le SL du même montant pour garder le même profit cible
454
+ nouveau_tp = t['tp'] + ecart
455
+ nouveau_sl = t['sl'] + ecart
456
+
457
+ # 4. On met à jour la DB avec les chiffres RÉELS de Capital.com
458
+ cursor.execute("""
459
+ UPDATE signals
460
+ SET confirmed = 1, price = ?, tp = ?, sl = ?, peak_price = ?
461
+ WHERE id = ?
462
+ """, (r_price, nouveau_tp, nouveau_sl, r_price, t_id))
463
+
464
  conn.commit()
465
 
466
+ print(f"⚓ [SYNC-PRIX] Signal {t_id} aligné sur Capital.com : Entrée {r_price}")
467
+ return {"status": "success", "message": f"Prix aligné à {r_price}"}
468
  except Exception as e:
 
469
  return {"status": "error", "message": str(e)}
470
 
471
  async def check_data_count(symbol):
 
812
  # =========================================================
813
  # --- ⚓ LE HANDSHAKE API (SECRET POUR PTERODACTYL) ---
814
  # =========================================================
815
+ # Dans ton interface gr.Blocks :
816
+ api_inputs = [gr.Textbox(visible=False), gr.Textbox(visible=False)] # Deux entrées !
817
  api_confirm_btn = gr.Button(visible=False)
818
  api_confirm_btn.click(
819
  fn=confirm_trade_api,
820
+ inputs=api_inputs, # On lie les deux
821
  outputs=gr.JSON(),
822
+ api_name="confirm_trade_api"
823
  )
824
  # =========================================================
825