Discord 장전분석 알림을 morning.py --send-discord로 이동
Headless Claude가 one-liner 실행을 건너뛰고 텍스트만 출력하는 문제 수정. daily_context.json을 읽어 전송하는 send_discord() 함수를 morning.py에 추가. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -46,22 +46,9 @@ python app/ai/morning.py --print
|
||||
```
|
||||
|
||||
### 4. Discord 알림 전송
|
||||
아래 Python 코드를 실행해 분석 결과를 Discord로 전송한다:
|
||||
아래 명령을 실행해 분석 결과를 Discord로 전송한다:
|
||||
```bash
|
||||
python -c "
|
||||
import asyncio, json, os, sys
|
||||
sys.path.insert(0, '.')
|
||||
from app.main import load_env; load_env()
|
||||
from app.monitor.notifier import send
|
||||
ctx = json.load(open('data/daily_context.json', encoding='utf-8'))
|
||||
hot = ', '.join(ctx.get('hot_sectors', [])) or '없음'
|
||||
avoid = ', '.join(ctx.get('avoid_sectors', [])) or '없음'
|
||||
boosted = ', '.join(ctx.get('boosted_tickers', [])) or '없음'
|
||||
flag = '✅ 거래허용' if ctx.get('trade_allowed', True) else '🚫 거래중단'
|
||||
msg = f'[장전분석] {ctx[\"date\"]} {ctx.get(\"generated_at\",\"\")}\n시장: {ctx[\"market_sentiment\"]}({ctx[\"sentiment_score\"]}점) | 리스크: {ctx[\"risk_level\"]} | {flag}\n주목 섹터: {hot}\n회피 섹터: {avoid}\n관심 종목: {boosted}\n비중 배율: x{ctx.get(\"position_size_multiplier\",1.0)}\n📝 {ctx.get(\"reason\",\"\")}'
|
||||
asyncio.run(send(msg))
|
||||
print('Discord 전송 완료')
|
||||
"
|
||||
python app/ai/morning.py --send-discord
|
||||
```
|
||||
|
||||
### 5. 완료
|
||||
|
||||
+34
-1
@@ -60,6 +60,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
import aiohttp
|
||||
from app.execution.kis_client import KISClient
|
||||
from app.monitor.notifier import send as discord_send
|
||||
|
||||
TODAY = datetime.now().strftime("%Y-%m-%d")
|
||||
NEWS_PATH = f"data/news/{TODAY}.json"
|
||||
@@ -225,8 +226,11 @@ async def main(print_mode: bool = False):
|
||||
# 1. RSS 뉴스 수집 (4개 언론사)
|
||||
news = await fetch_rss_news()
|
||||
|
||||
# 2. KIS 시장 데이터
|
||||
# 2. KIS 시장 데이터 — 데이터 수집 전용이므로 실거래 API 사용 (주문 없음)
|
||||
_orig_mock = os.environ.get("KIS_MOCK", "true")
|
||||
os.environ["KIS_MOCK"] = "false"
|
||||
kis = KISClient()
|
||||
os.environ["KIS_MOCK"] = _orig_mock
|
||||
market: dict = {"volume_rank": [], "foreign_buy": [], "institution_buy": [], "sectors": []}
|
||||
try:
|
||||
await kis.get_access_token()
|
||||
@@ -265,6 +269,35 @@ async def main(print_mode: bool = False):
|
||||
))
|
||||
|
||||
|
||||
async def send_discord():
|
||||
"""daily_context.json을 읽어 Discord로 장전 분석 요약 전송"""
|
||||
ctx_path = Path("data/daily_context.json")
|
||||
if not ctx_path.exists():
|
||||
logger.error("daily_context.json 없음 — Discord 전송 스킵")
|
||||
return
|
||||
ctx = json.loads(ctx_path.read_text(encoding="utf-8"))
|
||||
hot = ", ".join(ctx.get("hot_sectors", [])) or "없음"
|
||||
avoid = ", ".join(ctx.get("avoid_sectors", [])) or "없음"
|
||||
boosted = ", ".join(ctx.get("boosted_tickers", [])) or "없음"
|
||||
flag = "✅ 거래허용" if ctx.get("trade_allowed", True) else "🚫 거래중단"
|
||||
msg = (
|
||||
f"[장전분석] {ctx['date']} {ctx.get('generated_at', '')}\n"
|
||||
f"시장: {ctx['market_sentiment']}({ctx['sentiment_score']}점) | 리스크: {ctx['risk_level']} | {flag}\n"
|
||||
f"주목 섹터: {hot}\n"
|
||||
f"회피 섹터: {avoid}\n"
|
||||
f"관심 종목: {boosted}\n"
|
||||
f"비중 배율: x{ctx.get('position_size_multiplier', 1.0)}\n"
|
||||
f"📝 {ctx.get('reason', '')}"
|
||||
)
|
||||
await discord_send(msg)
|
||||
logger.info("Discord 장전 분석 전송 완료")
|
||||
print("Discord 알림 전송 완료.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print_mode = "--print" in sys.argv
|
||||
discord_mode = "--send-discord" in sys.argv
|
||||
if discord_mode:
|
||||
asyncio.run(send_discord())
|
||||
else:
|
||||
asyncio.run(main(print_mode=print_mode))
|
||||
|
||||
Reference in New Issue
Block a user