From 41df1a38d3c8ac59f387c66584489ac74b4e1b49 Mon Sep 17 00:00:00 2001 From: gahusb Date: Wed, 4 Feb 2026 23:25:19 +0900 Subject: [PATCH] first commit --- .gitignore | 52 ++++++++++++++++++++++++ README.md | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 .gitignore create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9ae333b --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +# Environment Variables +.env +.env.local +.env.* + +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# Virtual Environment +venv/ +env/ +ENV/ +.venv/ + +# IDE settings +.vscode/ +.idea/ +*.swp +*.swo + +# Data & Logs (Runtime generated) +data/ +*.log +daily_trade_history.json +watchlist.json +bot_ipc.json + +# System +Thumbs.db +Desktop.ini diff --git a/README.md b/README.md new file mode 100644 index 0000000..5243a9b --- /dev/null +++ b/README.md @@ -0,0 +1,115 @@ +# πŸ€– AI Automated Trading System (Windows Server Edition) + +이 ν”„λ‘œμ νŠΈλŠ” **Python, PyTorch (Deep Learning), Ollama (LLM)**을 ν™œμš©ν•˜μ—¬ ν•œκ΅­ 주식 μ‹œμž₯(KIS)μ—μ„œ μžλ™μœΌλ‘œ λ§€λ§€λ₯Ό μˆ˜ν–‰ν•˜λŠ” κ³ μ„±λŠ₯ AI νŠΈλ ˆμ΄λ”© λ΄‡μž…λ‹ˆλ‹€. + +## πŸš€ Key Features + +* **Multi-Process Architecture**: 메인 μ„œλ²„(`main_server.py`)κ°€ νŠΈλ ˆμ΄λ”© 봇과 ν…”λ ˆκ·Έλž¨ 봇을 λ…λ¦½λœ ν”„λ‘œμ„ΈμŠ€λ‘œ κ΄€λ¦¬ν•˜μ—¬ μ•ˆμ •μ„± 확보. +* **Advanced AI Analysis**: **RTX 5070 Ti (16GB VRAM)** ν•˜λ“œμ›¨μ–΄ 가속을 ν™œμš©ν•œ κ³ μ„±λŠ₯ 예츑 λͺ¨λΈ νƒ‘μž¬. +* **Hybrid Strategy**: 기술적 뢄석 + λ‰΄μŠ€ 감성 뢄석(LLM) + 가격 예츑(LSTM)을 κ²°ν•©ν•œ 볡합 μΆ”λ‘ . +* **Telegram Control**: μ‹€μ‹œκ°„ μƒνƒœ 쑰회, 리포트 μˆ˜μ‹ , ν”„λ‘œμ„ΈμŠ€ μ œμ–΄(`/restart` λ“±) 지원. +* **Safe Trading**: 예수금 초과 맀수 λ°©μ§€, μ†μ ˆ/읡절 μžλ™ν™”, API 속도 μ œν•œ(Throttling) 적용. + +--- + +## πŸ—οΈ System Architecture & Directory Structure + +```plaintext +/ +β”œβ”€β”€ main_server.py # [Entry Point] ν”„λ‘œμ„ΈμŠ€ λ§€λ‹ˆμ € 및 μ„œλ²„ μ‹€ν–‰ +β”œβ”€β”€ watchlist_manager.py # [Automation] 맀일 μ•„μΉ¨ μ’…λͺ© μ„ μ • 및 Watchlist κ°±μ‹  +β”œβ”€β”€ modules/ +β”‚ β”œβ”€β”€ bot.py # [Core] 메인 νŠΈλ ˆμ΄λ”© 루프 및 사이클 관리 +β”‚ β”œβ”€β”€ config.py # [Config] ν™˜κ²½ λ³€μˆ˜ 및 μƒμˆ˜ 관리 +β”‚ β”œβ”€β”€ analysis/ # [Brain] 뢄석 λͺ¨λ“ˆ +β”‚ β”‚ β”œβ”€β”€ deep_learning.py # PyTorch 기반 Attention-LSTM λͺ¨λΈ +β”‚ β”‚ β”œβ”€β”€ technical.py # RSI, λ³Όλ¦°μ €λ°΄λ“œ λ“± λ³΄μ‘°μ§€ν‘œ 계산 +β”‚ β”‚ └── macro.py # κ±°μ‹œκ²½μ œ(ν™˜μœ¨, μœ κ°€, μ§€μˆ˜) 뢄석 +β”‚ β”œβ”€β”€ services/ # [I/O] μ™ΈλΆ€ μ„œλΉ„μŠ€ 연동 +β”‚ β”‚ β”œβ”€β”€ kis.py # ν•œκ΅­νˆ¬μžμ¦κΆŒ API ν΄λΌμ΄μ–ΈνŠΈ (Throttling 적용) +β”‚ β”‚ β”œβ”€β”€ telegram.py # ν…”λ ˆκ·Έλž¨ λ©”μ‹œμ§€ λ°œμ†‘ +β”‚ β”‚ β”œβ”€β”€ news.py # 넀이버 λ‰΄μŠ€ 크둀링 +β”‚ β”‚ β”œβ”€β”€ ollama.py # Local LLM (Llama 3) μΈν„°νŽ˜μ΄μŠ€ +β”‚ β”‚ └── telegram_bot/ # ν…”λ ˆκ·Έλž¨ 봇 μ„œλ²„ (Interactive Mode) +β”‚ β”œβ”€β”€ strategy/ # [Logic] 맀수/맀도 μ˜μ‚¬κ²°μ • 둜직 +β”‚ └── utils/ # [Util] IPC, μ‹œμŠ€ν…œ λͺ¨λ‹ˆν„°λ§ λ“± +β”œβ”€β”€ data/ # [Runtime Data] μ‹€ν–‰ 쀑 μƒμ„±λ˜λŠ” 데이터 (Git μ œμ™Έ) +β”‚ β”œβ”€β”€ bot_ipc.json # ν”„λ‘œμ„ΈμŠ€ κ°„ μƒνƒœ 곡유 +β”‚ β”œβ”€β”€ watchlist.json # κ°μ‹œ λŒ€μƒ μ’…λͺ© 리슀트 +β”‚ └── daily_trade_history.json # 당일 λ§€λ§€ 기둝 +└── tests/ # ν…ŒμŠ€νŠΈ 슀크립트 +``` + +--- + +## 🧠 AI Learning Structure (Deep Learning) + +λ³Έ μ‹œμŠ€ν…œμ€ λ‹¨μˆœν•œ μ•Œκ³ λ¦¬μ¦˜ λ§€λ§€λ₯Ό λ„˜μ–΄, **Deep Learning**을 톡해 μ‹œμž₯의 νŒ¨ν„΄μ„ μ‹€μ‹œκ°„μœΌλ‘œ ν•™μŠ΅ν•©λ‹ˆλ‹€. + +### 1. Model: Attention-LSTM (High Capacity) +* **Architecture**: LSTM(Long Short-Term Memory) + **Attention Mechanism** +* **Input**: 졜근 60일(μ•½ 3κ°œμ›”)κ°„μ˜ μ£Όκ°€(μ’…κ°€) μ‹œκ³„μ—΄ 데이터 +* **Core Logic**: + * **Feature Extraction**: 4-Layer Stacked LSTM (Hidden Size: 512)이 μ‹œκ³„μ—΄ νŠΉμ§• μΆ”μΆœ. + * **Attention Layer**: κ³Όκ±° 60일 쀑 ν˜„μž¬ μ˜ˆμΈ‘μ— κ°€μž₯ μ€‘μš”ν•œ μ‹œμ μ— κ°€μ€‘μΉ˜λ₯Ό λΆ€μ—¬. + * **Adaptive Training**: μ’…λͺ©λ³„λ‘œ 맀일 μ‹€μ‹œκ°„ ν•™μŠ΅(Online Learning)을 μˆ˜ν–‰ν•˜μ—¬ μ΅œμ‹  νŠΈλ Œλ“œ 반영. + +### 2. Hardware Acceleration (RTX 5070 Ti) +* **CUDA Optimization**: PyTorchλ₯Ό 톡해 GPU 가속 ν™œμ„±ν™”. +* **Specs**: + * Batch Size: 64 + * Epochs: 200 + * Precision: FP32 +* μ„œλ²„ μ‹œμž‘ μ‹œ `High Performance Mode`κ°€ μžλ™μœΌλ‘œ 감지 및 ν™œμ„±ν™”λ©λ‹ˆλ‹€. + +### 3. Integrated Decision Making (Quant Strategy) +AI λͺ¨λΈμ˜ 예츑 κ²°κ³ΌλŠ” λ‹¨λ…μœΌλ‘œ 쓰이지 μ•Šκ³ , λ‹€μŒ μš”μ†Œλ“€κ³Ό κ²°ν•©λ˜μ–΄ μ΅œμ’… 맀수 결정을 λ‚΄λ¦½λ‹ˆλ‹€. +1. **Technical Score (40%)**: RSI, κ±°λž˜λŸ‰, 변동성 μ§€ν‘œ. +2. **News Sentiment (30%)**: Ollama(LLM)κ°€ λΆ„μ„ν•œ μ΅œμ‹  λ‰΄μŠ€ 긍/λΆ€μ • 점수. +3. **AI Prediction (30% ~ 60%)**: LSTM λͺ¨λΈμ˜ μƒμŠΉ 예츑 신뒰도. + * *AI Confidence*κ°€ 85% 이상일 경우, AI 비쀑을 **60%**κΉŒμ§€ λ™μ μœΌλ‘œ 상ν–₯ μ‘°μ •. + +--- + +## πŸ› οΈ Setup & Installation + +### 1. Prerequisites +* Python 3.10+ +* NVIDIA GPU + CUDA Toolkit (Recommended for AI performance) +* Ollama (Local LLM Server running on port 11434) + +### 2. Installation +```bash +# Clone Repository +git clone + +# Install Dependencies +pip install -r requirements.txt +``` + +### 3. Configuration (.env) +ν”„λ‘œμ νŠΈ λ£¨νŠΈμ— `.env` νŒŒμΌμ„ μƒμ„±ν•˜κ³  μ•„λž˜ 정보λ₯Ό μž…λ ₯ν•˜μ„Έμš”. +```ini +# ν•œκ΅­νˆ¬μžμ¦κΆŒ (KIS) +KIS_APP_KEY=your_app_key +KIS_APP_SECRET=your_app_secret +KIS_ACCOUNT=12345678-01 +KIS_IS_VIRTUAL=True # True: λͺ¨μ˜νˆ¬μž, False: μ‹€μ „νˆ¬μž + +# Telegram +TELEGRAM_BOT_TOKEN=your_bot_token +TELEGRAM_CHAT_ID=your_chat_id + +# AI Server +OLLAMA_API_URL=http://localhost:11434 +``` + +### 4. Run +```bash +python main_server.py +``` + +--- + +## ⚠️ Disclaimer +λ³Έ μ†Œν”„νŠΈμ›¨μ–΄λŠ” 투자λ₯Ό λ³΄μ‘°ν•˜λŠ” 도ꡬ이며, 투자의 결과에 λŒ€ν•œ μ±…μž„μ€ μ „μ μœΌλ‘œ μ‚¬μš©μžμ—κ²Œ μžˆμŠ΅λ‹ˆλ‹€. AI의 μ˜ˆμΈ‘μ€ 100% μ •ν™•ν•˜μ§€ μ•ŠμœΌλ©°, μ‹œμž₯ 상황에 따라 손싀이 λ°œμƒν•  수 μžˆμŠ΅λ‹ˆλ‹€.