feat: add Telegram notifications and configurable stop loss
- notify.py: buy/sell/error alerts via upbit_trading_jm_bot - STOP_LOSS_PCT: trailing stop configurable via .env (default -5%) - notify_buy/notify_sell called on every trade execution Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ from typing import Optional
|
||||
|
||||
import pyupbit
|
||||
from dotenv import load_dotenv
|
||||
from .notify import notify_buy, notify_sell, notify_error
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@@ -80,9 +81,11 @@ def buy(ticker: str) -> bool:
|
||||
f"[매수] {ticker} @ {current:,.0f}원 | "
|
||||
f"수량={amount} | 투자금={order_krw:,}원"
|
||||
)
|
||||
notify_buy(ticker, current, amount, order_krw)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"매수 예외 {ticker}: {e}")
|
||||
notify_error(f"매수 실패 {ticker}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
@@ -106,10 +109,12 @@ def sell(ticker: str, reason: str = "") -> bool:
|
||||
f"[매도] {ticker} @ {current:,.0f}원 | "
|
||||
f"수익률={pnl:+.1f}% | 사유={reason}"
|
||||
)
|
||||
notify_sell(ticker, current, pnl, reason)
|
||||
del _positions[ticker]
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"매도 예외 {ticker}: {e}")
|
||||
notify_error(f"매도 실패 {ticker}: {e}")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user