- deep_learning.py: INPUT_SIZE=7 (close/open/high/low/volume/rsi/macd), feature_scaler/target_scaler 분리, ModelRegistry LRU 종목별 격리 (v3 체크포인트) - kis.py: get_daily_ohlcv() OHLCV 전체 반환, KISAsyncClient 비동기 배치 조회 추가, order() 지정가/조건부 주문 지원 - strategy/process.py: ATR/ADX 기반 동적 손절익절, 트레일링 스탑, 포지션 사이징 강화 - config.py: OLLAMA_NUM_THREAD=8 (9800X3D 최적화), LSTM_COOLDOWN/FAST_EPOCHS 환경변수화 - macro.py: 거시경제 지표 계산 개선 - ollama.py: VRAM 여유량 기반 선택적 언로드 - monitor.py: CPU 서킷 브레이커 연속 횟수 조건 추가 - ipc.py: IPC_STALENESS 600초로 확대 - news.py: 비동기 뉴스 수집 개선 - telegram.py, runner.py: 안정성 개선 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
import requests
|
|
import os
|
|
import threading
|
|
|
|
from modules.config import Config
|
|
|
|
class TelegramMessenger:
|
|
def __init__(self, token=None, chat_id=None):
|
|
# 환경 변수에서 로드하거나 인자로 받음
|
|
self.token = token or Config.TELEGRAM_BOT_TOKEN
|
|
self.chat_id = chat_id or Config.TELEGRAM_CHAT_ID
|
|
|
|
if not self.token or not self.chat_id:
|
|
print("⚠️ [Telegram] Token or Chat ID not found.")
|
|
|
|
def send_message(self, message):
|
|
"""별도 스레드로 메시지를 전송하여 메인 루프 블로킹 방지"""
|
|
if not self.token or not self.chat_id:
|
|
return
|
|
|
|
def _send():
|
|
url = f"https://api.telegram.org/bot{self.token}/sendMessage"
|
|
payload = {
|
|
"chat_id": self.chat_id,
|
|
"text": message,
|
|
"parse_mode": "HTML"
|
|
}
|
|
try:
|
|
requests.post(url, json=payload, timeout=5)
|
|
except Exception as e:
|
|
print(f"⚠️ [Telegram] Error: {e}")
|
|
|
|
# 스레드 실행 (Fire-and-forget)
|
|
threading.Thread(target=_send, daemon=True).start()
|