fix: restore positions on restart and fix notify env loading
- restore_positions(): read Upbit balances on startup to prevent double-buying after restart - notify.py: read TOKEN/CHAT_ID inside _send() to avoid empty values when module is imported before load_dotenv() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,19 +9,19 @@ import requests
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_TOKEN = os.getenv("TELEGRAM_TRADE_TOKEN", "")
|
||||
_CHAT_ID = os.getenv("TELEGRAM_CHAT_ID", "")
|
||||
_API = "https://api.telegram.org/bot{token}/sendMessage"
|
||||
|
||||
|
||||
def _send(text: str) -> None:
|
||||
if not _TOKEN or not _CHAT_ID:
|
||||
token = os.getenv("TELEGRAM_TRADE_TOKEN", "")
|
||||
chat_id = os.getenv("TELEGRAM_CHAT_ID", "")
|
||||
if not token or not chat_id:
|
||||
logger.warning("Telegram 설정 없음, 알림 스킵")
|
||||
return
|
||||
try:
|
||||
requests.post(
|
||||
_API.format(token=_TOKEN),
|
||||
json={"chat_id": _CHAT_ID, "text": text, "parse_mode": "HTML"},
|
||||
_API.format(token=token),
|
||||
json={"chat_id": chat_id, "text": text, "parse_mode": "HTML"},
|
||||
timeout=5,
|
||||
)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user