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:
joungmin
2026-02-28 10:36:17 +09:00
parent a799fbebbd
commit a287e48522
3 changed files with 41 additions and 5 deletions

View File

@@ -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: