Files
upbit-trader/main.py
joungmin 2585d47140 feat: add hourly position status report via Telegram
Run status reporter thread every 60 minutes, sends current price,
PnL, drop from peak, and holding time for each position.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 10:39:30 +09:00

63 lines
1.7 KiB
Python

"""Upbit 자동 트레이딩 봇 진입점."""
import logging
import threading
import time
from dotenv import load_dotenv
load_dotenv()
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
handlers=[
logging.StreamHandler(),
logging.FileHandler("trading.log", encoding="utf-8"),
],
)
from core.monitor import run_monitor
from core.notify import notify_status
from core.trader import get_positions, restore_positions
from daemon.runner import run_scanner
STATUS_INTERVAL = 3600 # 1시간마다 요약 전송
def run_status_reporter(interval: int = STATUS_INTERVAL) -> None:
"""주기적으로 포지션 현황을 Telegram으로 전송."""
logger = logging.getLogger("status")
logger.info(f"상태 리포터 시작 (주기={interval//60}분)")
time.sleep(interval) # 첫 전송은 1시간 후
while True:
try:
notify_status(dict(get_positions()))
except Exception as e:
logger.error(f"상태 리포트 오류: {e}")
time.sleep(interval)
def main() -> None:
# 재시작 시 기존 잔고 복원 (이중 매수 방지)
restore_positions()
# 트레일링 스탑 감시 스레드 (10초 주기)
monitor_thread = threading.Thread(
target=run_monitor, args=(10,), daemon=True, name="monitor"
)
monitor_thread.start()
# 1시간 주기 상태 리포트 스레드
status_thread = threading.Thread(
target=run_status_reporter, daemon=True, name="status"
)
status_thread.start()
# 매수 스캔 루프 (60초 주기, 메인 스레드)
run_scanner()
if __name__ == "__main__":
main()