docs(i18n): add English translations for core documentation (#254)

- Add full-guide_EN.md (complete configuration guide)
- Add FAQ_EN.md (frequently asked questions)
- Add DEPLOY_EN.md (deployment guide)
- Update README_EN.md with missing env vars (BOCHA_API_KEYS, WECHAT_MSG_TYPE)
- Update README_EN.md with WebUI section
- Update README_EN.md links to point to English docs
This commit is contained in:
[ZE]
2026-02-05 13:39:12 +01:00
committed by GitHub
parent dea246b9a7
commit 7a26de6798
4 changed files with 1330 additions and 2 deletions

439
docs/DEPLOY_EN.md Normal file
View File

@@ -0,0 +1,439 @@
# Deployment Guide
This document explains how to deploy the AI Stock Analysis System to a server.
## Deployment Options Comparison
| Option | Pros | Cons | Recommended For |
|------|------|------|----------|
| **Docker Compose** ⭐ | One-click deploy, isolated environment, easy migration, easy upgrade | Requires Docker installation | **Recommended**: Most scenarios |
| **Direct Deployment** | Simple, no extra dependencies | Environment dependencies, migration difficulties | Temporary testing |
| **Systemd Service** | System-level management, auto-start on boot | Complex configuration | Long-term stable operation |
| **Supervisor** | Process management, auto-restart | Requires additional installation | Multi-process management |
**Conclusion: Docker Compose is recommended for the fastest and most convenient migration!**
---
## Option 1: Docker Compose Deployment (Recommended)
### 1. Install Docker
```bash
# Ubuntu/Debian
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
# CentOS
sudo yum install -y docker docker-compose
sudo systemctl start docker
sudo systemctl enable docker
```
### 2. Prepare Configuration Files
```bash
# Clone code (or upload code to server)
git clone <your-repo-url> /opt/stock-analyzer
cd /opt/stock-analyzer
# Copy and edit configuration file
cp .env.example .env
vim .env # Fill in real API Keys and configuration
```
### 3. One-Click Start
```bash
# Build and start
docker-compose -f ./docker/docker-compose.yml up -d
# View logs
docker-compose -f ./docker/docker-compose.yml logs -f
# View running status
docker-compose -f ./docker/docker-compose.yml ps
```
### 4. Common Management Commands
```bash
# Stop services
docker-compose -f ./docker/docker-compose.yml down
# Restart services
docker-compose -f ./docker/docker-compose.yml restart
# Redeploy after code update
git pull
docker-compose -f ./docker/docker-compose.yml build --no-cache
docker-compose -f ./docker/docker-compose.yml up -d
# Enter container for debugging
docker-compose -f ./docker/docker-compose.yml exec stock-analyzer bash
# Manually run analysis once
docker-compose -f ./docker/docker-compose.yml exec stock-analyzer python main.py --no-notify
```
### 5. Data Persistence
Data is automatically saved to host directories:
- `./data/` - Database files
- `./logs/` - Log files
- `./reports/` - Analysis reports
---
## Option 2: Direct Deployment
### 1. Install Python Environment
```bash
# Install Python 3.10+
sudo apt update
sudo apt install -y python3.10 python3.10-venv python3-pip
# Create virtual environment
python3.10 -m venv /opt/stock-analyzer/venv
source /opt/stock-analyzer/venv/bin/activate
```
### 2. Install Dependencies
```bash
cd /opt/stock-analyzer
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
```
### 3. Configure Environment Variables
```bash
cp .env.example .env
vim .env # Fill in configuration
```
### 4. Run
```bash
# Single run
python main.py
# Scheduled task mode (foreground)
python main.py --schedule
# Background run (using nohup)
nohup python main.py --schedule > /dev/null 2>&1 &
```
---
## Option 3: Systemd Service
Create systemd service file for auto-start on boot and auto-restart:
### 1. Create Service File
```bash
sudo vim /etc/systemd/system/stock-analyzer.service
```
Contents:
```ini
[Unit]
Description=AI Stock Analysis System
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/stock-analyzer
Environment="PATH=/opt/stock-analyzer/venv/bin"
ExecStart=/opt/stock-analyzer/venv/bin/python main.py --schedule
Restart=always
RestartSec=30
[Install]
WantedBy=multi-user.target
```
### 2. Start Service
```bash
# Reload configuration
sudo systemctl daemon-reload
# Start service
sudo systemctl start stock-analyzer
# Enable auto-start on boot
sudo systemctl enable stock-analyzer
# View status
sudo systemctl status stock-analyzer
# View logs
journalctl -u stock-analyzer -f
```
---
## Configuration Guide
### Required Configuration
| Config Item | Description | How to Get |
|--------|------|----------|
| `GEMINI_API_KEY` | Required for AI analysis | [Google AI Studio](https://aistudio.google.com/) |
| `STOCK_LIST` | Watchlist | Comma-separated stock codes |
| `WECHAT_WEBHOOK_URL` | WeChat push | WeChat Work group bot |
### Optional Configuration
| Config Item | Default | Description |
|--------|--------|------|
| `SCHEDULE_ENABLED` | `false` | Enable scheduled tasks |
| `SCHEDULE_TIME` | `18:00` | Daily execution time |
| `MARKET_REVIEW_ENABLED` | `true` | Enable market review |
| `TAVILY_API_KEYS` | - | News search (optional) |
---
## Proxy Configuration
If server is in mainland China, accessing Gemini API requires proxy:
### Docker Method
Edit `docker-compose.yml`:
```yaml
environment:
- http_proxy=http://your-proxy:port
- https_proxy=http://your-proxy:port
```
### Direct Deployment Method
Edit top of `main.py`:
```python
os.environ["http_proxy"] = "http://your-proxy:port"
os.environ["https_proxy"] = "http://your-proxy:port"
```
---
## Monitoring & Maintenance
### View Logs
```bash
# Docker method
docker-compose -f ./docker/docker-compose.yml logs -f --tail=100
# Direct deployment
tail -f /opt/stock-analyzer/logs/stock_analysis_*.log
```
### Health Check
```bash
# Check process
ps aux | grep main.py
# Check recent reports
ls -la /opt/stock-analyzer/reports/
```
### Routine Maintenance
```bash
# Clean old logs (keep 7 days)
find /opt/stock-analyzer/logs -mtime +7 -delete
# Clean old reports (keep 30 days)
find /opt/stock-analyzer/reports -mtime +30 -delete
```
---
## FAQ
### 1. Docker build failed
```bash
# Clear cache and rebuild
docker-compose -f ./docker/docker-compose.yml build --no-cache
```
### 2. API access timeout
Check proxy configuration, ensure server can access Gemini API.
### 3. Database locked
```bash
# Stop service then delete lock file
rm /opt/stock-analyzer/data/*.lock
```
### 4. Insufficient memory
Adjust memory limits in `docker-compose.yml`:
```yaml
deploy:
resources:
limits:
memory: 1G
```
---
## Quick Migration
Migrate from one server to another:
```bash
# Source server: Package
cd /opt/stock-analyzer
tar -czvf stock-analyzer-backup.tar.gz .env data/ logs/ reports/
# Target server: Deploy
mkdir -p /opt/stock-analyzer
cd /opt/stock-analyzer
git clone <your-repo-url> .
tar -xzvf stock-analyzer-backup.tar.gz
docker-compose -f ./docker/docker-compose.yml up -d
```
---
## Option 4: GitHub Actions Deployment (Serverless)
**The simplest option!** No server needed, leverages GitHub's free compute resources.
### Advantages
-**Completely free** (2000 minutes/month)
-**No server needed**
-**Auto-scheduled execution**
-**Zero maintenance cost**
### Limitations
- ⚠️ Stateless (fresh environment each run)
- ⚠️ Scheduled timing may have few minutes delay
- ⚠️ Cannot provide HTTP API
### Deployment Steps
#### 1. Create GitHub Repository
```bash
# Initialize git (if not already)
cd /path/to/daily_stock_analysis
git init
git add .
git commit -m "Initial commit"
# Create GitHub repo and push
# After creating new repo on GitHub web:
git remote add origin https://github.com/your-username/daily_stock_analysis.git
git branch -M main
git push -u origin main
```
#### 2. Configure Secrets (Important!)
Go to repo page → **Settings****Secrets and variables****Actions****New repository secret**
Add these Secrets:
| Secret Name | Description | Required |
|------------|------|------|
| `GEMINI_API_KEY` | Gemini AI API Key | ✅ |
| `WECHAT_WEBHOOK_URL` | WeChat Work Bot Webhook | Optional* |
| `FEISHU_WEBHOOK_URL` | Feishu Bot Webhook | Optional* |
| `TELEGRAM_BOT_TOKEN` | Telegram Bot Token | Optional* |
| `TELEGRAM_CHAT_ID` | Telegram Chat ID | Optional* |
| `TELEGRAM_MESSAGE_THREAD_ID` | Telegram Topic ID | Optional* |
| `EMAIL_SENDER` | Sender email | Optional* |
| `EMAIL_PASSWORD` | Email authorization code | Optional* |
| `SERVERCHAN3_SENDKEY` | ServerChan v3 Sendkey | Optional* |
| `CUSTOM_WEBHOOK_URLS` | Custom Webhook (comma-separated for multiple) | Optional* |
| `STOCK_LIST` | Watchlist, e.g., `600519,300750` | ✅ |
| `TAVILY_API_KEYS` | Tavily Search API Key | Recommended |
| `SERPAPI_API_KEYS` | SerpAPI Key | Optional |
| `TUSHARE_TOKEN` | Tushare Token | Optional |
| `GEMINI_MODEL` | Model name (default gemini-2.0-flash) | Optional |
> *Note: Configure at least one notification channel, multiple channels supported for simultaneous push
#### 3. Verify Workflow File
Ensure `.github/workflows/daily_analysis.yml` file exists and is committed:
```bash
git add .github/workflows/daily_analysis.yml
git commit -m "Add GitHub Actions workflow"
git push
```
#### 4. Manual Test Run
1. Go to repo page → **Actions** tab
2. Select **"Daily Stock Analysis"** workflow
3. Click **"Run workflow"** button
4. Select run mode:
- `full` - Full analysis (stocks + market)
- `market-only` - Market review only
- `stocks-only` - Stock analysis only
5. Click green **"Run workflow"** button
#### 5. View Execution Logs
- Actions page shows run history
- Click specific run record to view detailed logs
- Analysis reports are saved as Artifacts for 30 days
### Schedule Details
Default configuration: **Monday to Friday, 18:00 Beijing Time** auto-execution
Modify time: Edit cron expression in `.github/workflows/daily_analysis.yml`:
```yaml
schedule:
- cron: '0 10 * * 1-5' # UTC time, +8 = Beijing time
```
Common cron examples:
| Expression | Description |
|--------|------|
| `'0 10 * * 1-5'` | Mon-Fri 18:00 (Beijing) |
| `'30 7 * * 1-5'` | Mon-Fri 15:30 (Beijing) |
| `'0 10 * * *'` | Daily 18:00 (Beijing) |
| `'0 2 * * 1-5'` | Mon-Fri 10:00 (Beijing) |
### Modify Watchlist
Method 1: Modify repo Secret `STOCK_LIST`
Method 2: Modify code directly then push:
```bash
# Modify .env.example or set default value in code
git commit -am "Update stock list"
git push
```
### FAQ
**Q: Why isn't the scheduled task running?**
A: GitHub Actions scheduled tasks may have 5-15 minute delays, and only trigger when repo has activity. Long periods without commits may cause workflow to be disabled.
**Q: How to view historical reports?**
A: Actions → Select run record → Artifacts → Download `analysis-reports-xxx`
**Q: Is the free quota enough?**
A: Each run takes about 2-5 minutes, 22 workdays per month = 44-110 minutes, well below the 2000 minute limit.
---
**Wishing you a smooth deployment!**

257
docs/FAQ_EN.md Normal file
View File

@@ -0,0 +1,257 @@
# Frequently Asked Questions (FAQ)
This document compiles common issues encountered by users and their solutions.
---
## Data Related
### Q1: US stock codes (e.g., AMD, AAPL) show incorrect prices during analysis?
**Symptom**: After entering US stock codes, displayed prices are clearly wrong (e.g., AMD showing 7.33 yuan), or being misidentified as A-shares.
**Cause**: Earlier version code matching logic prioritized A-share rules, causing code conflicts.
**Solution**:
1. Fixed in v2.3.0, system now supports automatic US stock code recognition
2. If issues persist, set in `.env`:
```bash
YFINANCE_PRIORITY=0
```
This prioritizes Yahoo Finance data source for US stock data
> Related Issue: [#153](https://github.com/ZhuLinsen/daily_stock_analysis/issues/153)
---
### Q2: "Volume Ratio" field shows empty or N/A in reports?
**Symptom**: Volume ratio data missing in analysis reports, affecting AI's judgment on volume changes.
**Cause**: Some default real-time quote sources (e.g., Sina interface) don't provide volume ratio field.
**Solution**:
1. Fixed in v2.3.0, Tencent interface now supports volume ratio parsing
2. Recommended real-time quote source priority:
```bash
REALTIME_SOURCE_PRIORITY=tencent,akshare_sina,efinance,akshare_em
```
3. System has built-in 5-day average volume calculation as fallback
> Related Issue: [#155](https://github.com/ZhuLinsen/daily_stock_analysis/issues/155)
---
### Q3: Tushare data fetch failed, showing Token error?
**Symptom**: Log shows `Tushare data fetch failed: Your token is incorrect, please verify`
**Solution**:
1. **No Tushare account**: No need to configure `TUSHARE_TOKEN`, system will automatically use free data sources (AkShare, Efinance)
2. **Have Tushare account**: Verify Token is correct, check in [Tushare Pro](https://tushare.pro/weborder/#/login?reg=834638) personal center
3. All core features of this project work normally without Tushare
---
### Q4: Data fetch rate-limited or returning empty?
**Symptom**: Log shows `Circuit breaker triggered` or data returns `None`
**Cause**: Free data sources (Eastmoney, Sina, etc.) have anti-scraping mechanisms, high-frequency requests get rate-limited.
**Solution**:
1. System has built-in multi-source auto-switching and circuit breaker protection
2. Reduce watchlist size, or increase request intervals
3. Avoid frequently manually triggering analysis
---
## Configuration Related
### Q5: GitHub Actions run failed, showing environment variable not found?
**Symptom**: Actions log shows `GEMINI_API_KEY` or `STOCK_LIST` undefined
**Cause**: GitHub distinguishes `Secrets` (encrypted) and `Variables` (regular variables), wrong configuration location causes read failure.
**Solution**:
1. Go to repo `Settings` → `Secrets and variables` → `Actions`
2. **Secrets** (click `New repository secret`): Store sensitive information
- `GEMINI_API_KEY`
- `OPENAI_API_KEY`
- `TELEGRAM_BOT_TOKEN`
- Various Webhook URLs
3. **Variables** (click `Variables` tab): Store non-sensitive configuration
- `STOCK_LIST`
- `GEMINI_MODEL`
- `REPORT_TYPE`
---
### Q6: Configuration not taking effect after modifying .env file?
**Solution**:
1. Ensure `.env` file is in project root directory
2. **Docker deployment**: Restart container after modification
```bash
docker-compose down && docker-compose up -d
```
3. **GitHub Actions**: `.env` file doesn't work, must configure in Secrets/Variables
4. Check if there are multiple `.env` files (e.g., `.env.local`) causing override
---
### Q7: How to configure proxy to access Gemini/OpenAI API?
**Solution**:
Configure in `.env`:
```bash
USE_PROXY=true
PROXY_HOST=127.0.0.1
PROXY_PORT=10809
```
> Note: Proxy configuration only works for local runs, GitHub Actions environment doesn't need proxy.
---
## Push Notification Related
### Q8: Bot push failed, showing message too long?
**Symptom**: Analysis succeeded but no notification received, log shows 400 error or `Message too long`
**Cause**: Different platforms have different message length limits:
- WeChat Work: 4KB
- Feishu: 20KB
- DingTalk: 20KB
**Solution**:
1. **Auto-chunking**: Latest version implements automatic long message splitting
2. **Single stock push mode**: Set `SINGLE_STOCK_NOTIFY=true`, push immediately after each stock analysis
3. **Brief report**: Set `REPORT_TYPE=simple` for simplified format
---
### Q9: Not receiving Telegram push messages?
**Solution**:
1. Confirm both `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID` are configured
2. How to get Chat ID:
- Send any message to the Bot
- Visit `https://api.telegram.org/bot<TOKEN>/getUpdates`
- Find `chat.id` in the returned JSON
3. Ensure Bot has been added to target group (if group chat)
4. When running locally, need to be able to access Telegram API (may need proxy)
---
### Q10: WeChat Work Markdown format not displaying correctly?
**Solution**:
1. WeChat Work has limited Markdown support, try setting:
```bash
WECHAT_MSG_TYPE=text
```
2. This will send plain text format messages
---
## AI Model Related
### Q11: Gemini API returns 429 error (too many requests)?
**Symptom**: Log shows `Resource has been exhausted` or `429 Too Many Requests`
**Solution**:
1. Gemini free tier has rate limits (about 15 RPM)
2. Reduce number of stocks analyzed simultaneously
3. Increase request delay:
```bash
GEMINI_REQUEST_DELAY=5
ANALYSIS_DELAY=10
```
4. Or switch to OpenAI-compatible API as backup
---
### Q12: How to use DeepSeek and other Chinese models?
**Configuration method**:
```bash
# No need to configure GEMINI_API_KEY
OPENAI_API_KEY=sk-xxxxxxxx
OPENAI_BASE_URL=https://api.deepseek.com/v1
OPENAI_MODEL=deepseek-chat
```
Supported model services:
- DeepSeek: `https://api.deepseek.com/v1`
- Qwen (Tongyi Qianwen): `https://dashscope.aliyuncs.com/compatible-mode/v1`
- Moonshot: `https://api.moonshot.cn/v1`
---
## Docker Related
### Q13: Docker container exits immediately after starting?
**Solution**:
1. View container logs:
```bash
docker logs <container_id>
```
2. Common causes:
- Environment variables not correctly configured
- `.env` file format error (e.g., extra spaces)
- Dependency package version conflicts
---
### Q14: WebUI inaccessible in Docker?
**Solution**:
1. Ensure `WEBUI_HOST=0.0.0.0` (cannot be 127.0.0.1)
2. Check port mapping is correct:
```yaml
ports:
- "8000:8000"
```
---
## Other Issues
### Q15: How to run only market review, without stock analysis?
**Method**:
```bash
# Local run
python main.py --market-only
# GitHub Actions
# Select mode: market-only when manually triggering
```
---
### Q16: Buy/Hold/Sell counts in analysis results are incorrect?
**Cause**: Earlier versions used regex matching for statistics, may not match actual recommendations.
**Solution**: Fixed in latest version, AI model now directly outputs `decision_type` field for accurate statistics.
---
## Still Have Questions?
If the above content doesn't solve your issue, welcome to:
1. Check [Complete Configuration Guide](full-guide_EN.md)
2. Search or submit [GitHub Issue](https://github.com/ZhuLinsen/daily_stock_analysis/issues)
3. Check [Changelog](CHANGELOG.md) for latest fixes
---
*Last updated: 2026-02-01*

View File

@@ -15,7 +15,7 @@ Analyze your watchlist daily → generate a decision dashboard → push to multi
**Zero-cost deployment** · Runs on GitHub Actions · No server required
[**Quick Start**](#-quick-start) · [**Key Features**](#-key-features) · [**Sample Output**](#-sample-output) · [**Full Guide**](full-guide.md) · [**FAQ**](FAQ.md) · [**Changelog**](CHANGELOG.md)
[**Quick Start**](#-quick-start) · [**Key Features**](#-key-features) · [**Sample Output**](#-sample-output) · [**Full Guide**](full-guide_EN.md) · [**FAQ**](FAQ_EN.md) · [**Changelog**](CHANGELOG.md)
English | [简体中文](../README.md) | [繁體中文](README_CHT.md)
@@ -118,7 +118,9 @@ Go to your forked repo → `Settings` → `Secrets and variables` → `Actions`
| `STOCK_LIST` | Watchlist codes, e.g., `600519,AAPL,hk00700` | ✅ |
| `TAVILY_API_KEYS` | [Tavily](https://tavily.com/) Search API (for news) | Recommended |
| `SERPAPI_API_KEYS` | [SerpAPI](https://serpapi.com/baidu-search-api?utm_source=github_daily_stock_analysis) Backup search | Optional |
| `BOCHA_API_KEYS` | [Bocha Search](https://open.bocha.cn/) Web Search API (Chinese search optimized, supports AI summaries, multiple keys comma-separated) | Optional |
| `TUSHARE_TOKEN` | [Tushare Pro](https://tushare.pro/weborder/#/login?reg=834638 ) Token | Optional |
| `WECHAT_MSG_TYPE` | WeChat Work message type, default `markdown`, set to `text` for plain markdown text | Optional |
**Stock Code Format**
@@ -381,9 +383,24 @@ DEBUG=false # Enable debug logging
---
## 🖥️ Local WebUI (Optional)
```bash
python main.py --webui # Start WebUI + run analysis
python main.py --webui-only # Start WebUI only
```
Visit `http://127.0.0.1:8000` for configuration management, triggering analysis, and viewing task status.
> For detailed instructions, see [Full Guide - WebUI](full-guide_EN.md#local-webui-management-interface)
---
## 📖 Documentation
- [Complete Configuration Guide](full-guide.md)
- [Complete Configuration Guide](full-guide_EN.md)
- [FAQ](FAQ_EN.md)
- [Deployment Guide](DEPLOY_EN.md)
- [Bot Command Reference](bot-command.md)
- [Feishu Bot Setup](bot/feishu-bot-config.md)
- [DingTalk Bot Setup](bot/dingding-bot-config.md)

615
docs/full-guide_EN.md Normal file
View File

@@ -0,0 +1,615 @@
# Complete Configuration & Deployment Guide
This document contains the complete configuration guide for the AI Stock Analysis System, intended for users who need advanced features or special deployment methods.
> Quick start guide available in [README_EN.md](README_EN.md). This document covers advanced configuration.
## Project Structure
```
daily_stock_analysis/
├── main.py # Main entry point
├── src/ # Core business logic
│ ├── analyzer.py # AI analyzer
│ ├── config.py # Configuration management
│ ├── notification.py # Message push notifications
│ └── ...
├── data_provider/ # Multi-source data adapters
├── bot/ # Bot interaction module
├── web/ # WebUI module
├── docker/ # Docker configuration
├── docs/ # Project documentation
└── .github/workflows/ # GitHub Actions
```
## Table of Contents
- [Project Structure](#project-structure)
- [GitHub Actions Configuration](#github-actions-configuration)
- [Complete Environment Variables List](#complete-environment-variables-list)
- [Docker Deployment](#docker-deployment)
- [Local Deployment](#local-deployment)
- [Scheduled Task Configuration](#scheduled-task-configuration)
- [Notification Channel Configuration](#notification-channel-configuration)
- [Data Source Configuration](#data-source-configuration)
- [Advanced Features](#advanced-features)
- [Local WebUI Management Interface](#local-webui-management-interface)
---
## GitHub Actions Configuration
### 1. Fork this Repository
Click the `Fork` button in the upper right corner.
### 2. Configure Secrets
Go to your forked repo → `Settings``Secrets and variables``Actions``New repository secret`
<div align="center">
<img src="../sources/secret_config.png" alt="GitHub Secrets Configuration" width="600">
</div>
#### AI Model Configuration (Choose One)
| Secret Name | Description | Required |
|------------|------|:----:|
| `GEMINI_API_KEY` | Get free key from [Google AI Studio](https://aistudio.google.com/) | ✅* |
| `OPENAI_API_KEY` | OpenAI-compatible API Key (supports DeepSeek, Qwen, etc.) | Optional |
| `OPENAI_BASE_URL` | OpenAI-compatible API endpoint (e.g., `https://api.deepseek.com/v1`) | Optional |
| `OPENAI_MODEL` | Model name (e.g., `deepseek-chat`) | Optional |
> *Note: Configure at least one of `GEMINI_API_KEY` or `OPENAI_API_KEY`
#### Notification Channels (Multiple can be configured, all will receive notifications)
| Secret Name | Description | Required |
|------------|------|:----:|
| `WECHAT_WEBHOOK_URL` | WeChat Work Webhook URL | Optional |
| `FEISHU_WEBHOOK_URL` | Feishu Webhook URL | Optional |
| `TELEGRAM_BOT_TOKEN` | Telegram Bot Token (get from @BotFather) | Optional |
| `TELEGRAM_CHAT_ID` | Telegram Chat ID | Optional |
| `TELEGRAM_MESSAGE_THREAD_ID` | Telegram Topic ID (for sending to topics) | Optional |
| `DISCORD_WEBHOOK_URL` | Discord Webhook URL ([How to create](https://support.discord.com/hc/en-us/articles/228383668)) | Optional |
| `DISCORD_BOT_TOKEN` | Discord Bot Token (choose one with Webhook) | Optional |
| `DISCORD_CHANNEL_ID` | Discord Channel ID (required when using Bot) | Optional |
| `EMAIL_SENDER` | Sender email (e.g., `xxx@qq.com`) | Optional |
| `EMAIL_PASSWORD` | Email authorization code (not login password) | Optional |
| `EMAIL_RECEIVERS` | Receiver emails (comma-separated, leave empty to send to self) | Optional |
| `PUSHPLUS_TOKEN` | PushPlus Token ([Get here](https://www.pushplus.plus), Chinese push service) | Optional |
| `SERVERCHAN3_SENDKEY` | ServerChan v3 Sendkey ([Get here](https://sc3.ft07.com/), mobile app push service) | Optional |
| `CUSTOM_WEBHOOK_URLS` | Custom Webhook (supports DingTalk, etc., comma-separated) | Optional |
| `CUSTOM_WEBHOOK_BEARER_TOKEN` | Bearer Token for custom webhooks (for authenticated webhooks) | Optional |
> *Note: Configure at least one channel; multiple channels will all receive notifications
#### Push Behavior Configuration
| Secret Name | Description | Required |
|------------|------|:----:|
| `SINGLE_STOCK_NOTIFY` | Single stock push mode: set to `true` to push immediately after each stock analysis | Optional |
| `REPORT_TYPE` | Report type: `simple` (brief) or `full` (complete), Docker environment recommended: `full` | Optional |
| `ANALYSIS_DELAY` | Delay between stock analysis and market review (seconds) to avoid API rate limits, e.g., `10` | Optional |
#### Other Configuration
| Secret Name | Description | Required |
|------------|------|:----:|
| `STOCK_LIST` | Watchlist codes, e.g., `600519,300750,002594` | ✅ |
| `TAVILY_API_KEYS` | [Tavily](https://tavily.com/) Search API (for news search) | Recommended |
| `BOCHA_API_KEYS` | [Bocha Search](https://open.bocha.cn/) Web Search API (Chinese search optimized, supports AI summaries, multiple keys comma-separated) | Optional |
| `SERPAPI_API_KEYS` | [SerpAPI](https://serpapi.com/baidu-search-api?utm_source=github_daily_stock_analysis) Backup search | Optional |
| `TUSHARE_TOKEN` | [Tushare Pro](https://tushare.pro/weborder/#/login?reg=834638) Token | Optional |
#### ✅ Minimum Configuration Example
To get started quickly, you need at minimum:
1. **AI Model**: `GEMINI_API_KEY` (recommended) or `OPENAI_API_KEY`
2. **Notification Channel**: At least one, e.g., `WECHAT_WEBHOOK_URL` or `EMAIL_SENDER` + `EMAIL_PASSWORD`
3. **Stock List**: `STOCK_LIST` (required)
4. **Search API**: `TAVILY_API_KEYS` (strongly recommended for news search)
> Configure these 4 items and you're ready to go!
### 3. Enable Actions
1. Go to your forked repository
2. Click the `Actions` tab at the top
3. If prompted, click `I understand my workflows, go ahead and enable them`
### 4. Manual Test
1. Go to `Actions` tab
2. Select `Daily Stock Analysis` workflow on the left
3. Click `Run workflow` button on the right
4. Select run mode
5. Click green `Run workflow` to confirm
### 5. Done!
Default schedule: Every weekday at **18:00 (Beijing Time)** automatic execution.
---
## Complete Environment Variables List
### AI Model Configuration
| Variable | Description | Default | Required |
|--------|------|--------|:----:|
| `GEMINI_API_KEY` | Google Gemini API Key | - | ✅* |
| `GEMINI_MODEL` | Primary model name | `gemini-3-flash-preview` | No |
| `GEMINI_MODEL_FALLBACK` | Fallback model | `gemini-2.5-flash` | No |
| `OPENAI_API_KEY` | OpenAI-compatible API Key | - | Optional |
| `OPENAI_BASE_URL` | OpenAI-compatible API endpoint | - | Optional |
| `OPENAI_MODEL` | OpenAI model name | `gpt-4o` | Optional |
> *Note: Configure at least one of `GEMINI_API_KEY` or `OPENAI_API_KEY`
### Notification Channel Configuration
| Variable | Description | Required |
|--------|------|:----:|
| `WECHAT_WEBHOOK_URL` | WeChat Work Bot Webhook URL | Optional |
| `FEISHU_WEBHOOK_URL` | Feishu Bot Webhook URL | Optional |
| `TELEGRAM_BOT_TOKEN` | Telegram Bot Token | Optional |
| `TELEGRAM_CHAT_ID` | Telegram Chat ID | Optional |
| `TELEGRAM_MESSAGE_THREAD_ID` | Telegram Topic ID | Optional |
| `DISCORD_WEBHOOK_URL` | Discord Webhook URL | Optional |
| `DISCORD_BOT_TOKEN` | Discord Bot Token (choose one with Webhook) | Optional |
| `DISCORD_CHANNEL_ID` | Discord Channel ID (required when using Bot) | Optional |
| `EMAIL_SENDER` | Sender email | Optional |
| `EMAIL_PASSWORD` | Email authorization code (not login password) | Optional |
| `EMAIL_RECEIVERS` | Receiver emails (comma-separated, leave empty to send to self) | Optional |
| `CUSTOM_WEBHOOK_URLS` | Custom Webhook (comma-separated) | Optional |
| `CUSTOM_WEBHOOK_BEARER_TOKEN` | Custom Webhook Bearer Token | Optional |
| `PUSHOVER_USER_KEY` | Pushover User Key | Optional |
| `PUSHOVER_API_TOKEN` | Pushover API Token | Optional |
| `PUSHPLUS_TOKEN` | PushPlus Token (Chinese push service) | Optional |
| `SERVERCHAN3_SENDKEY` | ServerChan v3 Sendkey | Optional |
#### Feishu Cloud Document Configuration (Optional, solves message truncation issues)
| Variable | Description | Required |
|--------|------|:----:|
| `FEISHU_APP_ID` | Feishu App ID | Optional |
| `FEISHU_APP_SECRET` | Feishu App Secret | Optional |
| `FEISHU_FOLDER_TOKEN` | Feishu Cloud Drive Folder Token | Optional |
> Feishu Cloud Document setup steps:
> 1. Create an app in [Feishu Developer Console](https://open.feishu.cn/app)
> 2. Configure GitHub Secrets
> 3. Create a group and add the app bot
> 4. Add the group as a collaborator to the cloud drive folder (with manage permissions)
### Search Service Configuration
| Variable | Description | Required |
|--------|------|:----:|
| `TAVILY_API_KEYS` | Tavily Search API Key (recommended) | Recommended |
| `BOCHA_API_KEYS` | Bocha Search API Key (Chinese optimized) | Optional |
| `SERPAPI_API_KEYS` | SerpAPI Backup search | Optional |
### Data Source Configuration
| Variable | Description | Required |
|--------|------|:----:|
| `TUSHARE_TOKEN` | Tushare Pro Token | Optional |
### Other Configuration
| Variable | Description | Default |
|--------|------|--------|
| `STOCK_LIST` | Watchlist codes (comma-separated) | - |
| `MAX_WORKERS` | Concurrent threads | `3` |
| `MARKET_REVIEW_ENABLED` | Enable market review | `true` |
| `SCHEDULE_ENABLED` | Enable scheduled tasks | `false` |
| `SCHEDULE_TIME` | Scheduled execution time | `18:00` |
| `LOG_DIR` | Log directory | `./logs` |
---
## Docker Deployment
### Quick Start
```bash
# 1. Clone repository
git clone https://github.com/ZhuLinsen/daily_stock_analysis.git
cd daily_stock_analysis
# 2. Configure environment variables
cp .env.example .env
vim .env # Fill in API Keys and configuration
# 3. Start container
docker-compose -f ./docker/docker-compose.yml up -d webui # WebUI mode (recommended)
docker-compose -f ./docker/docker-compose.yml up -d analyzer # Scheduled task mode
docker-compose -f ./docker/docker-compose.yml up -d # Start both modes
# 4. Access WebUI
# http://localhost:8000
# 5. View logs
docker-compose -f ./docker/docker-compose.yml logs -f webui
```
### Run Mode Description
| Command | Description | Port |
|------|------|------|
| `docker-compose -f ./docker/docker-compose.yml up -d webui` | WebUI mode, manually trigger analysis | 8000 |
| `docker-compose -f ./docker/docker-compose.yml up -d analyzer` | Scheduled task mode, daily auto execution | - |
| `docker-compose -f ./docker/docker-compose.yml up -d` | Start both modes simultaneously | 8000 |
### Docker Compose Configuration
`docker-compose.yml` uses YAML anchors to reuse configuration:
```yaml
version: '3.8'
x-common: &common
build: .
restart: unless-stopped
env_file:
- .env
environment:
- TZ=Asia/Shanghai
volumes:
- ./data:/app/data
- ./logs:/app/logs
- ./reports:/app/reports
- ./.env:/app/.env
services:
# Scheduled task mode
analyzer:
<<: *common
container_name: stock-analyzer
# WebUI mode
webui:
<<: *common
container_name: stock-webui
command: ["python", "main.py", "--webui-only"]
ports:
- "8000:8000"
```
### Common Commands
```bash
# View running status
docker-compose -f ./docker/docker-compose.yml ps
# View logs
docker-compose -f ./docker/docker-compose.yml logs -f webui
# Stop services
docker-compose -f ./docker/docker-compose.yml down
# Rebuild image (after code update)
docker-compose -f ./docker/docker-compose.yml build --no-cache
docker-compose -f ./docker/docker-compose.yml up -d webui
```
### Manual Image Build
```bash
docker build -t stock-analysis .
docker run -d --env-file .env -p 8000:8000 -v ./data:/app/data stock-analysis python main.py --webui-only
```
---
## Local Deployment
### Install Dependencies
```bash
# Python 3.10+ recommended
pip install -r requirements.txt
# Or use conda
conda create -n stock python=3.10
conda activate stock
pip install -r requirements.txt
```
### Command Line Arguments
```bash
python main.py # Full analysis (stocks + market review)
python main.py --market-review # Market review only
python main.py --no-market-review # Stock analysis only
python main.py --stocks 600519,300750 # Specify stocks
python main.py --dry-run # Fetch data only, no AI analysis
python main.py --no-notify # Don't send notifications
python main.py --schedule # Scheduled task mode
python main.py --debug # Debug mode (verbose logging)
python main.py --workers 5 # Specify concurrency
```
---
## Scheduled Task Configuration
### GitHub Actions Schedule
Edit `.github/workflows/daily_analysis.yml`:
```yaml
schedule:
# UTC time, Beijing time = UTC + 8
- cron: '0 10 * * 1-5' # Monday to Friday 18:00 (Beijing Time)
```
Common time reference:
| Beijing Time | UTC cron expression |
|---------|----------------|
| 09:30 | `'30 1 * * 1-5'` |
| 12:00 | `'0 4 * * 1-5'` |
| 15:00 | `'0 7 * * 1-5'` |
| 18:00 | `'0 10 * * 1-5'` |
| 21:00 | `'0 13 * * 1-5'` |
### Local Scheduled Tasks
```bash
# Start scheduled mode (default 18:00 execution)
python main.py --schedule
# Or use crontab
crontab -e
# Add: 0 18 * * 1-5 cd /path/to/project && python main.py
```
---
## Notification Channel Configuration
### WeChat Work
1. Add "Group Bot" in WeChat Work group chat
2. Copy Webhook URL
3. Set `WECHAT_WEBHOOK_URL`
### Feishu
1. Add "Custom Bot" in Feishu group chat
2. Copy Webhook URL
3. Set `FEISHU_WEBHOOK_URL`
### Telegram
1. Talk to @BotFather to create a Bot
2. Get Bot Token
3. Get Chat ID (via @userinfobot)
4. Set `TELEGRAM_BOT_TOKEN` and `TELEGRAM_CHAT_ID`
5. (Optional) To send to Topic, set `TELEGRAM_MESSAGE_THREAD_ID` (get from Topic link)
### Email
1. Enable SMTP service for your email
2. Get authorization code (not login password)
3. Set `EMAIL_SENDER`, `EMAIL_PASSWORD`, `EMAIL_RECEIVERS`
Supported email providers:
- QQ Mail: smtp.qq.com:465
- 163 Mail: smtp.163.com:465
- Gmail: smtp.gmail.com:587
### Custom Webhook
Supports any POST JSON Webhook, including:
- DingTalk Bot
- Discord Webhook
- Slack Webhook
- Bark (iOS push)
- Self-hosted services
Set `CUSTOM_WEBHOOK_URLS`, separate multiple with commas.
### Discord
Discord supports two push methods:
**Method 1: Webhook (Recommended, Simple)**
1. Create Webhook in Discord channel settings
2. Copy Webhook URL
3. Configure environment variable:
```bash
DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/xxx/yyy
```
**Method 2: Bot API (Requires more permissions)**
1. Create application in [Discord Developer Portal](https://discord.com/developers/applications)
2. Create Bot and get Token
3. Invite Bot to server
4. Get Channel ID (right-click channel in developer mode)
5. Configure environment variables:
```bash
DISCORD_BOT_TOKEN=your_bot_token
DISCORD_CHANNEL_ID=your_channel_id
```
### Pushover (iOS/Android Push)
[Pushover](https://pushover.net/) is a cross-platform push service supporting iOS and Android.
1. Register Pushover account and download App
2. Get User Key from [Pushover Dashboard](https://pushover.net/)
3. Create Application to get API Token
4. Configure environment variables:
```bash
PUSHOVER_USER_KEY=your_user_key
PUSHOVER_API_TOKEN=your_api_token
```
Features:
- Supports iOS/Android
- Supports notification priority and sound settings
- Free quota sufficient for personal use (10,000 messages/month)
- Messages retained for 7 days
---
## Data Source Configuration
System defaults to AkShare (free), also supports other data sources:
### AkShare (Default)
- Free, no configuration needed
- Data source: Eastmoney scraper
### Tushare Pro
- Requires registration to get Token
- More stable, more comprehensive data
- Set `TUSHARE_TOKEN`
### Baostock
- Free, no configuration needed
- Used as backup data source
### YFinance
- Free, no configuration needed
- Supports US/HK stock data
---
## Advanced Features
### Hong Kong Stock Support
Use `hk` prefix for HK stock codes:
```bash
STOCK_LIST=600519,hk00700,hk01810
```
### Multi-Model Switching
Configure multiple models, system auto-switches:
```bash
# Gemini (primary)
GEMINI_API_KEY=xxx
GEMINI_MODEL=gemini-3-flash-preview
# OpenAI compatible (backup)
OPENAI_API_KEY=xxx
OPENAI_BASE_URL=https://api.deepseek.com/v1
OPENAI_MODEL=deepseek-chat
```
### Debug Mode
```bash
python main.py --debug
```
Log file locations:
- Regular logs: `logs/stock_analysis_YYYYMMDD.log`
- Debug logs: `logs/stock_analysis_debug_YYYYMMDD.log`
---
## Local WebUI Management Interface
WebUI provides configuration management and quick analysis features, supporting single stock analysis triggered from the page.
### Startup Methods
| Command | Description |
|------|------|
| `python main.py --webui` | Start WebUI + run full analysis once |
| `python main.py --webui-only` | Start WebUI only, manually trigger analysis |
**Permanently enable**: Set in `.env`:
```env
WEBUI_ENABLED=true
```
### Features
- **Configuration Management** - View/modify watchlist in `.env`
- **Quick Analysis** - Enter stock code on page, one-click trigger analysis
- **Real-time Progress** - Analysis task status updates in real-time, supports parallel tasks
- **API Interface** - Supports programmatic calls
### API Endpoints
| Endpoint | Method | Description |
|------|------|------|
| `/` | GET | Configuration management page |
| `/health` | GET | Health check |
| `/analysis?code=xxx` | GET | Trigger async analysis for single stock |
| `/analysis/history` | GET | Query analysis history |
| `/tasks` | GET | Query all task statuses |
| `/task?id=xxx` | GET | Query single task status |
**Usage examples**:
```bash
# Health check
curl http://127.0.0.1:8000/health
# Trigger analysis (A-shares)
curl "http://127.0.0.1:8000/analysis?code=600519"
# Trigger analysis (HK stocks)
curl "http://127.0.0.1:8000/analysis?code=hk00700"
# Query task status
curl "http://127.0.0.1:8000/task?id=<task_id>"
```
### Custom Configuration
Modify default port or allow LAN access:
```env
WEBUI_HOST=0.0.0.0 # Default 127.0.0.1
WEBUI_PORT=8888 # Default 8000
```
### Supported Stock Code Formats
| Type | Format | Examples |
|------|------|------|
| A-shares | 6-digit number | `600519`, `000001`, `300750` |
| HK stocks | hk + 5-digit number | `hk00700`, `hk09988` |
### Notes
- Browser access: `http://127.0.0.1:8000` (or your configured port)
- After analysis completion, notifications are automatically pushed to configured channels
- This feature is automatically disabled in GitHub Actions environment
---
## FAQ
### Q: Push messages getting truncated?
A: WeChat Work/Feishu have message length limits, system already auto-segments messages. For complete content, configure Feishu Cloud Document feature.
### Q: Data fetch failed?
A: AkShare uses scraping mechanism, may be temporarily rate-limited. System has retry mechanism configured, usually just wait a few minutes and retry.
### Q: How to add watchlist stocks?
A: Modify `STOCK_LIST` environment variable, separate multiple codes with commas.
### Q: GitHub Actions not executing?
A: Check if Actions is enabled, and if cron expression is correct (note it's UTC time).
---
For more questions, please [submit an Issue](https://github.com/ZhuLinsen/daily_stock_analysis/issues)