first commit
This commit is contained in:
52
.gitignore
vendored
Normal file
52
.gitignore
vendored
Normal file
@@ -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
|
||||||
115
README.md
Normal file
115
README.md
Normal file
@@ -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 <repository-url>
|
||||||
|
|
||||||
|
# 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% 정확하지 않으며, 시장 상황에 따라 손실이 발생할 수 있습니다.
|
||||||
Reference in New Issue
Block a user