shaikhmarketing commited on
Commit
1127d4f
Β·
verified Β·
1 Parent(s): 6000759

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -28,7 +28,7 @@ telegram_lock = threading.Lock() # Prevents simultaneous multi-threaded socket
28
  # --- GLOBAL EXCHANGE MATRIX (INSTANTIATED EXACTLY ONCE AT BOOT) ---
29
  EXCHANGES = {
30
  'bitget': ccxt.bitget({'enableRateLimit': True}),
31
- 'gate': ccxt.gate({'enableRateLimit': True}), # Correct canonical class handle
32
  'kraken': ccxt.kraken({'enableRateLimit': True})
33
  }
34
 
@@ -176,19 +176,30 @@ def get_live_price(symbol):
176
  continue
177
  return 0.0
178
 
 
179
  def generate_human_binance_post(symbol, entry, tp1, tp2, tp3, sl, xgb_prob):
180
  coin = symbol.split('/')[0]
 
 
 
 
 
 
 
 
 
 
181
  hooks = [f"Watching the order books closely on ${coin} and something highly unusual just happened."]
182
  insights = [f"Our machine learning matrix flags an institutional liquidity absorption block. XGBoost is printing a sharp {xgb_prob:.1f}% upside probability score."]
183
  outros = ["Let's see how the next few 15-minute candles close out. Stick to your rules, emotionless execution always wins."]
184
 
185
  post = f"{random.choice(hooks)}\n\n{random.choice(insights)}\n\n" \
186
  f"🧠 Strategic Levels:\n" \
187
- f"πŸ“ Buy Trigger: {entry}\n" \
188
- f"🎯 Target 1: {tp1}\n" \
189
- f"🎯 Target 2: {tp2}\n" \
190
- f"🎯 Target 3 (Final): {tp3}\n" \
191
- f"πŸ›‘οΈ Risk Barrier: {sl}\n\n" \
192
  f"βš™οΈ Risk Management Protocol:\n" \
193
  f"⚑ Milestone Step-Lock Trailing Enabled. The safety floor automatically drags up to match the previous target -0.01% as soon as a milestone is cleared to guarantee zero round-tripping of realized profits.\n\n" \
194
  f"{random.choice(outros)}"
@@ -447,7 +458,7 @@ def quantum_scanner_loop():
447
  imbalance = get_global_imbalance(symbol)
448
  imb_str = f"{imbalance*100:.1f}%"
449
  except:
450
- imbalance = 0.00 # Default to zero liquidity to force skip if helper drops out
451
  imb_str = "UTILS_ERR"
452
 
453
  if imbalance < 0.52:
@@ -507,8 +518,8 @@ def quantum_scanner_loop():
507
  })
508
  save_wallet_state()
509
 
510
- entry_str = f"${current_price:,.4f}"
511
- SYSTEM_STATE["latest_binance_post"] = generate_human_binance_post(symbol, entry_str, f"${tp1:,.4f}", f"${tp2:,.4f}", f"${tp3:,.4f}", f"${sl_price:,.4f}", xgb_res)
512
 
513
  new_sig = pd.DataFrame([[time.strftime("%H:%M:%S"), symbol, "BUY", entry_str, f"{xgb_res:.1f}%", vision_result, rl_ratios]], columns=SIGNAL_HISTORY.columns)
514
  SIGNAL_HISTORY = pd.concat([new_sig, SIGNAL_HISTORY]).head(100)
@@ -606,10 +617,13 @@ def render_open_positions():
606
  for p in OPEN_POSITIONS:
607
  live_p = get_live_price(p["Symbol"])
608
  unrealized = (live_p * p["Qty"]) - p["Invested"] if live_p else 0
609
- tp1_status = "HIT βœ…" if p.get("TP1_hit") else f"${p['TP1']:.4f}"
610
- tp2_status = "HIT βœ…" if p.get("TP2_hit") else f"${p['TP2']:.4f}"
611
- sl_label = f"${p['SL']:.4f} πŸ”’" if (p.get("TP1_hit") or p.get("TP2_hit")) else f"${p['SL']:.4f}"
612
- data.append([p["Symbol"], f"${p['Entry']:.4f}", f"${live_p:.4f}", tp1_status, tp2_status, f"${p['TP3']:.4f}", sl_label, round(unrealized, 2)])
 
 
 
613
  return pd.DataFrame(data, columns=["Symbol", "Entry", "Live Price", "TP1 (1/3)", "TP2 (1/3)", "TP3 (Final)", "SL (LOCK)", "Unrealized PnL"])
614
 
615
  def render_trade_history():
 
28
  # --- GLOBAL EXCHANGE MATRIX (INSTANTIATED EXACTLY ONCE AT BOOT) ---
29
  EXCHANGES = {
30
  'bitget': ccxt.bitget({'enableRateLimit': True}),
31
+ 'gate': ccxt.gate({'enableRateLimit': True}),
32
  'kraken': ccxt.kraken({'enableRateLimit': True})
33
  }
34
 
 
176
  continue
177
  return 0.0
178
 
179
+ # --- SMART DYNAMIC DECIMAL GENERATOR FOR MEME COINS ---
180
  def generate_human_binance_post(symbol, entry, tp1, tp2, tp3, sl, xgb_prob):
181
  coin = symbol.split('/')[0]
182
+
183
+ def format_price(p):
184
+ try:
185
+ price_val = float(str(p).replace('$', '').replace(',', ''))
186
+ if price_val < 0.01:
187
+ return f"${price_val:,.8f}"
188
+ return f"${price_val:,.4f}"
189
+ except:
190
+ return str(p)
191
+
192
  hooks = [f"Watching the order books closely on ${coin} and something highly unusual just happened."]
193
  insights = [f"Our machine learning matrix flags an institutional liquidity absorption block. XGBoost is printing a sharp {xgb_prob:.1f}% upside probability score."]
194
  outros = ["Let's see how the next few 15-minute candles close out. Stick to your rules, emotionless execution always wins."]
195
 
196
  post = f"{random.choice(hooks)}\n\n{random.choice(insights)}\n\n" \
197
  f"🧠 Strategic Levels:\n" \
198
+ f"πŸ“ Buy Trigger: {format_price(entry)}\n" \
199
+ f"🎯 Target 1: {format_price(tp1)}\n" \
200
+ f"🎯 Target 2: {format_price(tp2)}\n" \
201
+ f"🎯 Target 3 (Final): {format_price(tp3)}\n" \
202
+ f"πŸ›‘οΈ Risk Barrier: {format_price(sl)}\n\n" \
203
  f"βš™οΈ Risk Management Protocol:\n" \
204
  f"⚑ Milestone Step-Lock Trailing Enabled. The safety floor automatically drags up to match the previous target -0.01% as soon as a milestone is cleared to guarantee zero round-tripping of realized profits.\n\n" \
205
  f"{random.choice(outros)}"
 
458
  imbalance = get_global_imbalance(symbol)
459
  imb_str = f"{imbalance*100:.1f}%"
460
  except:
461
+ imbalance = 0.00
462
  imb_str = "UTILS_ERR"
463
 
464
  if imbalance < 0.52:
 
518
  })
519
  save_wallet_state()
520
 
521
+ entry_str = f"${current_price:,.8f}" if current_price < 0.01 else f"${current_price:,.4f}"
522
+ SYSTEM_STATE["latest_binance_post"] = generate_human_binance_post(symbol, current_price, tp1, tp2, tp3, sl_price, xgb_res)
523
 
524
  new_sig = pd.DataFrame([[time.strftime("%H:%M:%S"), symbol, "BUY", entry_str, f"{xgb_res:.1f}%", vision_result, rl_ratios]], columns=SIGNAL_HISTORY.columns)
525
  SIGNAL_HISTORY = pd.concat([new_sig, SIGNAL_HISTORY]).head(100)
 
617
  for p in OPEN_POSITIONS:
618
  live_p = get_live_price(p["Symbol"])
619
  unrealized = (live_p * p["Qty"]) - p["Invested"] if live_p else 0
620
+
621
+ fmt = "${:.8f}" if p["Entry"] < 0.01 else "${:.4f}"
622
+ tp1_status = "HIT βœ…" if p.get("TP1_hit") else fmt.format(p['TP1'])
623
+ tp2_status = "HIT βœ…" if p.get("TP2_hit") else fmt.format(p['TP2'])
624
+ sl_label = (fmt + " πŸ”’").format(p['SL']) if (p.get("TP1_hit") or p.get("TP2_hit")) else fmt.format(p['SL'])
625
+
626
+ data.append([p["Symbol"], fmt.format(p["Entry"]), fmt.format(live_p), tp1_status, tp2_status, fmt.format(p["TP3"]), sl_label, round(unrealized, 2)])
627
  return pd.DataFrame(data, columns=["Symbol", "Entry", "Live Price", "TP1 (1/3)", "TP2 (1/3)", "TP3 (Final)", "SL (LOCK)", "Unrealized PnL"])
628
 
629
  def render_trade_history():