diff --git a/app_streamlit.py b/app_streamlit.py index f15b7c1..0fb8985 100644 --- a/app_streamlit.py +++ b/app_streamlit.py @@ -55,6 +55,12 @@ KST = timedelta(hours=9) _last_alert = {"strong_long": 0, "strong_short": 0, "long": 0, "short": 0, "vol_long": 0, "vol_short": 0, "short_caution": 0} _last_fired_candle = {"strong_long": None, "strong_short": None, "long": None, "short": None, "vol_long": None, "vol_short": None, "short_caution": None} +STOP_LOSS_PCT = 0.10 +LONG_SIGNALS = {"strong_long_signal", "long_signal", "vol_long_signal"} +SHORT_SIGNALS = {"strong_short_signal", "short_signal", "vol_short_signal"} +_long_entry = None +_short_entry = None + # ────────────────────────────────────────────── # 텔레그램 # ────────────────────────────────────────────── @@ -66,6 +72,7 @@ def send_telegram(message: str): print(f"[텔레그램 오류] {e}") def check_and_alert(df, symbol, interval): + global _long_entry, _short_entry now = time.time() recent = df.tail(3) for sig, key, msg in [ @@ -91,6 +98,31 @@ def check_and_alert(df, symbol, interval): _last_alert[key] = now _last_fired_candle[key] = candle_time + if sig in LONG_SIGNALS: + entry_price = float(triggered.iloc[-1]["close"]) + _long_entry = {"price": entry_price, "stop": entry_price * (1 - STOP_LOSS_PCT), "open_time": candle_time} + elif sig in SHORT_SIGNALS: + entry_price = float(triggered.iloc[-1]["close"]) + _short_entry = {"price": entry_price, "stop": entry_price * (1 + STOP_LOSS_PCT), "open_time": candle_time} + + current_price = float(df.iloc[-1]["close"]) + if _long_entry is not None and current_price <= _long_entry["stop"]: + send_telegram( + f"🛑 롱 손절가 도달 (-{int(STOP_LOSS_PCT * 100)}%)\n{symbol} {interval}\n" + f"진입가: {_long_entry['price']:.2f}\n" + f"손절가: {_long_entry['stop']:.2f}\n" + f"현재가: {current_price:.2f}" + ) + _long_entry = None + if _short_entry is not None and current_price >= _short_entry["stop"]: + send_telegram( + f"🛑 숏 손절가 도달 (+{int(STOP_LOSS_PCT * 100)}%)\n{symbol} {interval}\n" + f"진입가: {_short_entry['price']:.2f}\n" + f"손절가: {_short_entry['stop']:.2f}\n" + f"현재가: {current_price:.2f}" + ) + _short_entry = None + # ────────────────────────────────────────────── # 데이터 수집 # ──────────────────────────────────────────────