Update app.py
Browse files
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}),
|
| 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
|
| 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,
|
| 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 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
|
|
|
|
|
|
|
|
|
| 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():
|