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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -11
app.py CHANGED
@@ -84,7 +84,10 @@ except:
84
  try:
85
  from ensemble import combine_scores
86
  except:
87
- def combine_scores(symbol, timeframe, t, m, l, sent, r): return (t+m+l+sent)/4, 0.25, 0.25, 0.25, 0.25
 
 
 
88
 
89
  # --- DB, SYNC & HUGGING FACE BACKUP ---
90
  DB_NAME = "alphatrade_v31_dino.db"
@@ -231,6 +234,7 @@ init_db()
231
 
232
  # --- 🛡️ STATE MANAGER ---
233
  active_signals_state = {}
 
234
 
235
  def clean_old_db_signals(symbol, timeframe):
236
  try:
@@ -277,19 +281,31 @@ try:
277
  except:
278
  dino_brain = None
279
 
280
- # --- 📊 FEATURES ENGINE ---
 
 
 
 
 
 
 
 
281
  async def fetch_kucoin_futures_data(symbol):
282
  try:
283
  ku_sym = symbol.replace("/", "").replace("BTC", "XBT") + "M"
284
- async with aiohttp.ClientSession() as session:
285
- oi_url = f"https://api-futures.kucoin.com/api/v1/open-interest?symbol={ku_sym}"
286
- trade_url = f"https://api-futures.kucoin.com/api/v1/trade/history?symbol={ku_sym}"
287
- async with session.get(oi_url) as r1, session.get(trade_url) as r2:
288
- oi_json = await r1.json()
289
- trades = (await r2.json()).get("data", [])
290
- cvd = sum([float(t.get("size", 0)) if t.get("side") == "buy" else -float(t.get("size", 0)) for t in trades])
291
- return {"oi": float(oi_json.get("data", {}).get("value", 0)), "cvd": cvd}
292
- except: return {"oi": 0, "cvd": 0}
 
 
 
 
293
 
294
  def prepare_features_sync(symbol, timeframe='1h', limit_bars=600):
295
  try:
 
84
  try:
85
  from ensemble import combine_scores
86
  except:
87
+ def combine_scores(symbol, timeframe, t, m, l, sent, r):
88
+ # Formule PRO : 30% Time, 30% ML, 30% LightGBM, 10% Sentiment
89
+ score = (t * 0.30) + (m * 0.30) + (l * 0.30) + (sent * 0.10)
90
+ return score, 0.30, 0.30, 0.30, 0.10
91
 
92
  # --- DB, SYNC & HUGGING FACE BACKUP ---
93
  DB_NAME = "alphatrade_v31_dino.db"
 
234
 
235
  # --- 🛡️ STATE MANAGER ---
236
  active_signals_state = {}
237
+ last_signals_sent = {} # ⬅️ LA RUSTINE CRITIQUE EST LÀ
238
 
239
  def clean_old_db_signals(symbol, timeframe):
240
  try:
 
281
  except:
282
  dino_brain = None
283
 
284
+ # --- 🌐 HTTP SESSION MANAGER ---
285
+ global_aio_session = None
286
+
287
+ async def get_aio_session():
288
+ global global_aio_session
289
+ if global_aio_session is None or global_aio_session.closed:
290
+ global_aio_session = aiohttp.ClientSession()
291
+ return global_aio_session
292
+
293
  async def fetch_kucoin_futures_data(symbol):
294
  try:
295
  ku_sym = symbol.replace("/", "").replace("BTC", "XBT") + "M"
296
+ session = await get_aio_session() # On utilise la session globale ouverte
297
+
298
+ oi_url = f"https://api-futures.kucoin.com/api/v1/open-interest?symbol={ku_sym}"
299
+ trade_url = f"https://api-futures.kucoin.com/api/v1/trade/history?symbol={ku_sym}"
300
+
301
+ async with session.get(oi_url) as r1, session.get(trade_url) as r2:
302
+ oi_json = await r1.json()
303
+ trades = (await r2.json()).get("data", [])
304
+ cvd = sum([float(t.get("size", 0)) if t.get("side") == "buy" else -float(t.get("size", 0)) for t in trades])
305
+ return {"oi": float(oi_json.get("data", {}).get("value", 0)), "cvd": cvd}
306
+ except Exception as e:
307
+ print(f"⚠️ Erreur Flux KuCoin ({symbol}) : {e}")
308
+ return {"oi": 0, "cvd": 0}
309
 
310
  def prepare_features_sync(symbol, timeframe='1h', limit_bars=600):
311
  try: