feat: add Portfolio Management module with AI monitoring

This commit is contained in:
TIANHE
2026-01-12 22:36:10 +08:00
parent bb45248982
commit ec56b59530
24 changed files with 7940 additions and 90 deletions
+230
View File
@@ -0,0 +1,230 @@
# 📧 邮箱 SMTP 通知配置指南
> QuantDinger 支持通过邮件推送策略信号通知,适合需要详细通知记录的用户。
---
## 📋 目录
- [前置要求](#前置要求)
- [支持的邮件服务商](#支持的邮件服务商)
- [配置步骤](#配置步骤)
- [第一步:获取 SMTP 服务信息](#第一步获取-smtp-服务信息)
- [第二步:配置环境变量](#第二步配置环境变量)
- [第三步:策略中启用邮件通知](#第三步策略中启用邮件通知)
- [常见邮件服务商配置示例](#常见邮件服务商配置示例)
- [常见问题](#常见问题)
---
## 前置要求
- 拥有一个支持 SMTP 发送的邮箱账号
- 邮箱已开启 SMTP 服务(部分服务商需手动开启)
- 获取邮箱的授权码或应用专用密码(非登录密码)
- QuantDinger 后端服务已部署并运行
---
## 支持的邮件服务商
QuantDinger 支持任何标准 SMTP 协议的邮件服务商,包括但不限于:
| 服务商 | SMTP 服务器 | 端口 | 加密方式 |
|--------|------------|------|----------|
| Gmail | smtp.gmail.com | 587 (TLS) / 465 (SSL) | TLS / SSL |
| Outlook/Hotmail | smtp.office365.com | 587 | TLS |
| QQ 邮箱 | smtp.qq.com | 587 (TLS) / 465 (SSL) | TLS / SSL |
| 163 邮箱 | smtp.163.com | 465 (SSL) / 25 | SSL |
| 阿里企业邮箱 | smtp.qiye.aliyun.com | 465 | SSL |
| 腾讯企业邮箱 | smtp.exmail.qq.com | 465 | SSL |
| SendGrid | smtp.sendgrid.net | 587 | TLS |
| Mailgun | smtp.mailgun.org | 587 | TLS |
| Amazon SES | email-smtp.{region}.amazonaws.com | 587 | TLS |
---
## 配置步骤
### 第一步:获取 SMTP 服务信息
**QQ 邮箱** 为例:
1. 登录 QQ 邮箱网页版 → 设置 → 账户
2. 找到「POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务」
3. 开启「SMTP 服务」
4. 按提示生成**授权码**(16位字母)
> ⚠️ **重要**:授权码不是 QQ 密码,请妥善保管。
**Gmail** 为例:
1. 访问 [Google 账号安全设置](https://myaccount.google.com/security)
2. 开启两步验证
3. 生成「应用专用密码」(App Password
4. 选择「邮件」和设备类型,获取 16 位密码
---
### 第二步:配置环境变量
`backend_api_python/.env` 文件中配置 SMTP 参数:
```bash
# =========================
# Email / SMTP 配置
# =========================
# SMTP 服务器地址(必填)
SMTP_HOST=smtp.qq.com
# SMTP 端口(必填)
# 常用端口:587 (TLS) / 465 (SSL) / 25 (不加密,不推荐)
SMTP_PORT=465
# SMTP 登录用户名(必填,通常是邮箱地址)
SMTP_USER=your_email@qq.com
# SMTP 密码或授权码(必填)
SMTP_PASSWORD=your_authorization_code
# 发件人地址(可选,默认使用 SMTP_USER)
SMTP_FROM=your_email@qq.com
# 是否使用 STARTTLS(端口 587 通常设为 true
SMTP_USE_TLS=false
# 是否使用 SSL(端口 465 通常设为 true
SMTP_USE_SSL=true
```
配置完成后重启后端服务使配置生效。
---
### 第三步:策略中启用邮件通知
在策略配置页面的「信号通知」设置中:
1. 勾选启用 **Email** 通知渠道
2.**收件邮箱** 字段填入接收通知的邮箱地址
> 💡 **提示**:支持填入多个邮箱地址(逗号分隔),实现多人通知。
---
## 常见邮件服务商配置示例
### QQ 邮箱
```bash
SMTP_HOST=smtp.qq.com
SMTP_PORT=465
SMTP_USER=123456789@qq.com
SMTP_PASSWORD=abcdefghijklmnop # 16位授权码
SMTP_FROM=123456789@qq.com
SMTP_USE_TLS=false
SMTP_USE_SSL=true
```
### 163 邮箱
```bash
SMTP_HOST=smtp.163.com
SMTP_PORT=465
SMTP_USER=your_email@163.com
SMTP_PASSWORD=your_authorization_code # 授权码
SMTP_FROM=your_email@163.com
SMTP_USE_TLS=false
SMTP_USE_SSL=true
```
### Gmail
```bash
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASSWORD=your_app_password # 应用专用密码
SMTP_FROM=your_email@gmail.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### Outlook / Office 365
```bash
SMTP_HOST=smtp.office365.com
SMTP_PORT=587
SMTP_USER=your_email@outlook.com
SMTP_PASSWORD=your_password
SMTP_FROM=your_email@outlook.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### SendGrid
```bash
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASSWORD=SG.xxxxxxxxxxxxxxxxxxxxx # API Key
SMTP_FROM=verified_sender@yourdomain.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### Amazon SES
```bash
SMTP_HOST=email-smtp.us-east-1.amazonaws.com # 替换为您的区域
SMTP_PORT=587
SMTP_USER=AKIAIOSFODNN7EXAMPLE # SMTP 凭证用户名
SMTP_PASSWORD=your_smtp_password # SMTP 凭证密码
SMTP_FROM=verified@yourdomain.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
---
## 常见问题
### Q: 发送失败,提示认证错误?
1. 检查用户名和密码(授权码)是否正确
2. 确认已开启邮箱的 SMTP 服务
3. 部分邮箱需要使用授权码而非登录密码
### Q: 连接超时?
1. 检查 SMTP 服务器地址和端口是否正确
2. 确认服务器防火墙是否放行对应端口
3. 如使用代理,确认代理配置正确
### Q: TLS 和 SSL 如何选择?
| 端口 | 加密方式 | 配置 |
|------|---------|------|
| 587 | STARTTLS | `SMTP_USE_TLS=true`, `SMTP_USE_SSL=false` |
| 465 | 隐式 SSL | `SMTP_USE_TLS=false`, `SMTP_USE_SSL=true` |
| 25 | 无加密 | `SMTP_USE_TLS=false`, `SMTP_USE_SSL=false` (不推荐)|
### Q: 邮件被标记为垃圾邮件?
1. 使用与 `SMTP_USER` 一致的 `SMTP_FROM` 地址
2. 考虑使用专业邮件服务(如 SendGrid、Mailgun
3. 配置域名 SPF、DKIM、DMARC 记录(企业邮箱)
### Q: 可以发送 HTML 格式邮件吗?
是的,QuantDinger 自动发送包含格式化信息的 HTML 邮件,同时附带纯文本备选内容以确保兼容性。
---
## 相关文档
- [Telegram 通知配置](./NOTIFICATION_TELEGRAM_CONFIG_CH.md)
- [手机短信通知配置](./NOTIFICATION_SMS_CONFIG_CH.md)
- [策略开发指南](./STRATEGY_DEV_GUIDE_CN.md)
+252
View File
@@ -0,0 +1,252 @@
# 📧 Email SMTP Notification Configuration Guide
> QuantDinger supports strategy signal notifications via email, ideal for users who need detailed notification records.
---
## 📋 Table of Contents
- [Prerequisites](#prerequisites)
- [Supported Email Providers](#supported-email-providers)
- [Configuration Steps](#configuration-steps)
- [Step 1: Obtain SMTP Service Information](#step-1-obtain-smtp-service-information)
- [Step 2: Configure Environment Variables](#step-2-configure-environment-variables)
- [Step 3: Enable Email Notifications in Strategy](#step-3-enable-email-notifications-in-strategy)
- [Provider Configuration Examples](#provider-configuration-examples)
- [Troubleshooting](#troubleshooting)
---
## Prerequisites
- An email account with SMTP sending capability
- SMTP service enabled (some providers require manual activation)
- App password or authorization code (not your login password)
- QuantDinger backend service deployed and running
---
## Supported Email Providers
QuantDinger supports any standard SMTP protocol email provider, including:
| Provider | SMTP Server | Port | Encryption |
|----------|-------------|------|------------|
| Gmail | smtp.gmail.com | 587 (TLS) / 465 (SSL) | TLS / SSL |
| Outlook/Hotmail | smtp.office365.com | 587 | TLS |
| Yahoo Mail | smtp.mail.yahoo.com | 587 | TLS |
| SendGrid | smtp.sendgrid.net | 587 | TLS |
| Mailgun | smtp.mailgun.org | 587 | TLS |
| Amazon SES | email-smtp.{region}.amazonaws.com | 587 | TLS |
| Zoho Mail | smtp.zoho.com | 587 | TLS |
| ProtonMail Bridge | 127.0.0.1 | 1025 | STARTTLS |
---
## Configuration Steps
### Step 1: Obtain SMTP Service Information
**For Gmail:**
1. Visit [Google Account Security Settings](https://myaccount.google.com/security)
2. Enable 2-Step Verification
3. Generate an "App Password"
4. Select "Mail" and your device type to get a 16-character password
**For Outlook/Hotmail:**
1. Use your regular email and password
2. Ensure "SMTP AUTH" is enabled in account settings
3. May require app password if 2FA is enabled
> ⚠️ **Important**: App passwords are different from your login password. Keep them secure.
---
### Step 2: Configure Environment Variables
Add SMTP parameters to your `backend_api_python/.env` file:
```bash
# =========================
# Email / SMTP Configuration
# =========================
# SMTP server address (required)
SMTP_HOST=smtp.gmail.com
# SMTP port (required)
# Common ports: 587 (TLS) / 465 (SSL) / 25 (unencrypted, not recommended)
SMTP_PORT=587
# SMTP username (required, usually your email address)
SMTP_USER=your_email@gmail.com
# SMTP password or app password (required)
SMTP_PASSWORD=your_app_password
# Sender address (optional, defaults to SMTP_USER)
SMTP_FROM=your_email@gmail.com
# Enable STARTTLS (typically true for port 587)
SMTP_USE_TLS=true
# Enable implicit SSL (typically true for port 465)
SMTP_USE_SSL=false
```
Restart the backend service after configuration to apply changes.
---
### Step 3: Enable Email Notifications in Strategy
In the strategy configuration page under "Signal Notifications":
1. Enable the **Email** notification channel
2. Enter the recipient email address in the designated field
> 💡 **Tip**: You can enter multiple email addresses (comma-separated) for multi-recipient notifications.
---
## Provider Configuration Examples
### Gmail
```bash
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your_email@gmail.com
SMTP_PASSWORD=your_app_password # 16-character app password
SMTP_FROM=your_email@gmail.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### Outlook / Office 365
```bash
SMTP_HOST=smtp.office365.com
SMTP_PORT=587
SMTP_USER=your_email@outlook.com
SMTP_PASSWORD=your_password
SMTP_FROM=your_email@outlook.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### Yahoo Mail
```bash
SMTP_HOST=smtp.mail.yahoo.com
SMTP_PORT=587
SMTP_USER=your_email@yahoo.com
SMTP_PASSWORD=your_app_password
SMTP_FROM=your_email@yahoo.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### SendGrid
```bash
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASSWORD=SG.xxxxxxxxxxxxxxxxxxxxx # Your API Key
SMTP_FROM=verified_sender@yourdomain.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### Mailgun
```bash
SMTP_HOST=smtp.mailgun.org
SMTP_PORT=587
SMTP_USER=postmaster@your-domain.mailgun.org
SMTP_PASSWORD=your_mailgun_smtp_password
SMTP_FROM=noreply@yourdomain.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### Amazon SES
```bash
SMTP_HOST=email-smtp.us-east-1.amazonaws.com # Replace with your region
SMTP_PORT=587
SMTP_USER=AKIAIOSFODNN7EXAMPLE # SMTP credential username
SMTP_PASSWORD=your_smtp_password # SMTP credential password
SMTP_FROM=verified@yourdomain.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
### Zoho Mail
```bash
SMTP_HOST=smtp.zoho.com
SMTP_PORT=587
SMTP_USER=your_email@zoho.com
SMTP_PASSWORD=your_password
SMTP_FROM=your_email@zoho.com
SMTP_USE_TLS=true
SMTP_USE_SSL=false
```
---
## Troubleshooting
### Q: Authentication error?
1. Verify username and password (app password) are correct
2. Confirm SMTP service is enabled in your email settings
3. Some providers require app passwords instead of login passwords
4. Check if "Less secure app access" needs to be enabled (legacy option)
### Q: Connection timeout?
1. Verify SMTP server address and port are correct
2. Check if server firewall allows the port
3. If using a proxy, ensure proxy configuration is correct
4. Some networks block SMTP ports; try port 587 or 465
### Q: How to choose between TLS and SSL?
| Port | Encryption | Configuration |
|------|------------|---------------|
| 587 | STARTTLS | `SMTP_USE_TLS=true`, `SMTP_USE_SSL=false` |
| 465 | Implicit SSL | `SMTP_USE_TLS=false`, `SMTP_USE_SSL=true` |
| 25 | None | `SMTP_USE_TLS=false`, `SMTP_USE_SSL=false` (not recommended) |
### Q: Emails marked as spam?
1. Use a `SMTP_FROM` address matching your `SMTP_USER`
2. Consider professional email services (SendGrid, Mailgun, Amazon SES)
3. Configure SPF, DKIM, DMARC records for your domain (business email)
4. Avoid spam trigger words in subject/content
### Q: Does it support HTML emails?
Yes, QuantDinger automatically sends formatted HTML emails with a plain text fallback for maximum compatibility.
### Q: Rate limits?
Most providers have sending limits:
- Gmail: ~500/day (personal), 2000/day (Workspace)
- Outlook: ~300/day
- SendGrid: Based on your plan
For high-volume notifications, consider dedicated email services.
---
## Related Documentation
- [Telegram Notification Configuration](./NOTIFICATION_TELEGRAM_CONFIG_EN.md)
- [SMS Notification Configuration](./NOTIFICATION_SMS_CONFIG_EN.md)
- [Strategy Development Guide](./STRATEGY_DEV_GUIDE.md)
+211
View File
@@ -0,0 +1,211 @@
# 📲 手机短信通知配置指南
> QuantDinger 支持通过 Twilio 发送 SMS 短信通知,确保您在任何情况下都能收到重要的交易信号。
---
## 📋 目录
- [前置要求](#前置要求)
- [Twilio 简介](#twilio-简介)
- [配置步骤](#配置步骤)
- [第一步:注册 Twilio 账号](#第一步注册-twilio-账号)
- [第二步:获取 API 凭证](#第二步获取-api-凭证)
- [第三步:获取发送号码](#第三步获取发送号码)
- [第四步:配置环境变量](#第四步配置环境变量)
- [第五步:策略中启用短信通知](#第五步策略中启用短信通知)
- [费用说明](#费用说明)
- [常见问题](#常见问题)
---
## 前置要求
- 有效的手机号码用于接收短信
- 可用的信用卡/借记卡用于 Twilio 充值(试用账户有免费额度)
- QuantDinger 后端服务已部署并运行
---
## Twilio 简介
[Twilio](https://www.twilio.com) 是全球领先的云通信平台,提供可靠的 SMS 短信服务。
**为什么选择 Twilio**
- ✅ 全球覆盖 180+ 国家和地区
- ✅ 高送达率和可靠性
- ✅ 按量计费,无月费
- ✅ 新用户有免费试用额度
- ✅ 完善的 API 文档和技术支持
---
## 配置步骤
### 第一步:注册 Twilio 账号
1. 访问 [Twilio 官网](https://www.twilio.com/try-twilio)
2. 点击 **Sign Up** 注册新账号
3. 填写邮箱、密码等基本信息
4. 验证您的邮箱和手机号码
5. 完成账号激活
> 💡 **提示**:新注册用户可获得 $15 美元的免费试用额度。
---
### 第二步:获取 API 凭证
注册完成后,进入 Twilio 控制台:
1. 登录 [Twilio Console](https://console.twilio.com)
2. 在 Dashboard 页面找到 **Account Info** 区域
3. 记录以下信息:
- **Account SID**:格式为 `ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
- **Auth Token**:点击显示后复制(妥善保管)
![Twilio Console](https://www.twilio.com/docs/static/img/console-account-info.png)
> ⚠️ **安全提示**Auth Token 相当于 API 密码,请勿泄露。如泄露请立即在控制台重新生成。
---
### 第三步:获取发送号码
您需要一个 Twilio 电话号码作为短信发送方:
1. 在 Twilio Console 左侧菜单选择 **Phone Numbers****Manage****Buy a number**
2. 选择国家/地区,勾选 **SMS** 功能
3. 选择一个号码并购买(试用账户可免费获取一个号码)
4. 记录您的 Twilio 电话号码(格式:`+1xxxxxxxxxx`
**号码选择建议:**
- 选择与接收方同一国家的号码可降低费用
- 如需发送到中国大陆,建议使用 Alphanumeric Sender ID 或购买支持中国的号码
---
### 第四步:配置环境变量
`backend_api_python/.env` 文件中配置 Twilio 参数:
```bash
# =========================
# Phone / SMS 配置 (Twilio)
# =========================
# Twilio Account SID(必填)
# 格式:ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Twilio Auth Token(必填)
# 从 Twilio Console 获取
TWILIO_AUTH_TOKEN=your_auth_token_here
# Twilio 发送号码(必填)
# 格式:+国家代码+号码,如 +14155552671
TWILIO_FROM_NUMBER=+14155552671
```
配置完成后重启后端服务使配置生效。
---
### 第五步:策略中启用短信通知
在策略配置页面的「信号通知」设置中:
1. 勾选启用 **Phone** 通知渠道
2.**手机号码** 字段填入接收短信的号码
**号码格式要求:**
- 必须包含国家代码
- 格式:`+国家代码号码`
- 示例:
- 美国:`+14155552671`
- 中国大陆:`+8613812345678`
- 香港:`+85212345678`
> 💡 **提示**:支持填入多个号码(逗号分隔),实现多人通知。
---
## 费用说明
Twilio 采用按量计费模式,不同国家/地区的短信费用不同:
| 接收地区 | 大约费用(美元/条) |
|---------|-------------------|
| 美国 | $0.0079 |
| 加拿大 | $0.0075 |
| 英国 | $0.04 |
| 德国 | $0.07 |
| 日本 | $0.08 |
| 中国大陆 | $0.06 - $0.10 |
| 香港 | $0.05 |
> 💰 **提示**:实际费用请参考 [Twilio 定价页面](https://www.twilio.com/sms/pricing),价格可能随时调整。
**试用账户限制:**
- $15 美元免费额度
- 只能发送到已验证的手机号码
- 短信会带有 "Sent from your Twilio trial account" 前缀
升级为正式账户后可解除这些限制。
---
## 常见问题
### Q: 试用账户可以发短信到任意号码吗?
不可以。试用账户只能发送到已验证的手机号码。您需要在 Twilio Console 的 **Verified Caller IDs** 中添加并验证接收号码。升级为正式账户后可发送到任意号码。
### Q: 发送失败,提示号码无效?
1. 确保号码格式正确(含国家代码,如 `+8613812345678`
2. 去掉号码中的空格、横线等特殊字符
3. 确认接收号码可以接收国际短信
### Q: 中国大陆号码收不到短信?
1. 部分运营商可能拦截国际短信
2. 尝试使用 Alphanumeric Sender ID
3. 确认手机未开启国际短信拦截
4. 联系 Twilio 支持确认中国短信服务状态
### Q: 如何查看发送记录和状态?
登录 Twilio Console → **Monitor****Logs****Messaging** 可查看所有短信发送记录、状态和错误信息。
### Q: Auth Token 泄露了怎么办?
立即登录 Twilio Console → **Account****API Credentials** → 点击 **Regenerate Auth Token** 重新生成。
### Q: 有替代 Twilio 的方案吗?
QuantDinger 目前仅支持 Twilio 作为 SMS 提供商。如需其他服务商支持,可通过 Webhook 通道自行集成:
- 阿里云短信
- 腾讯云短信
- Nexmo (Vonage)
- AWS SNS
---
## 环境变量完整参考
```bash
# Twilio SMS Configuration
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Account SID
TWILIO_AUTH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Auth Token
TWILIO_FROM_NUMBER=+14155552671 # 发送号码
```
---
## 相关文档
- [Telegram 通知配置](./NOTIFICATION_TELEGRAM_CONFIG_CH.md)
- [邮箱 SMTP 通知配置](./NOTIFICATION_EMAIL_CONFIG_CH.md)
- [策略开发指南](./STRATEGY_DEV_GUIDE_CN.md)
- [Twilio 官方文档](https://www.twilio.com/docs/sms)
+211
View File
@@ -0,0 +1,211 @@
# 📲 SMS Notification Configuration Guide
> QuantDinger supports SMS notifications via Twilio, ensuring you receive critical trading signals anywhere.
---
## 📋 Table of Contents
- [Prerequisites](#prerequisites)
- [About Twilio](#about-twilio)
- [Configuration Steps](#configuration-steps)
- [Step 1: Create a Twilio Account](#step-1-create-a-twilio-account)
- [Step 2: Obtain API Credentials](#step-2-obtain-api-credentials)
- [Step 3: Get a Phone Number](#step-3-get-a-phone-number)
- [Step 4: Configure Environment Variables](#step-4-configure-environment-variables)
- [Step 5: Enable SMS Notifications in Strategy](#step-5-enable-sms-notifications-in-strategy)
- [Pricing Information](#pricing-information)
- [Troubleshooting](#troubleshooting)
---
## Prerequisites
- A valid phone number to receive SMS messages
- A credit/debit card for Twilio billing (trial accounts include free credits)
- QuantDinger backend service deployed and running
---
## About Twilio
[Twilio](https://www.twilio.com) is a leading cloud communications platform providing reliable SMS services worldwide.
**Why Twilio?**
- ✅ Global coverage in 180+ countries
- ✅ High deliverability and reliability
- ✅ Pay-as-you-go pricing, no monthly fees
- ✅ Free trial credits for new users
- ✅ Comprehensive API documentation and support
---
## Configuration Steps
### Step 1: Create a Twilio Account
1. Visit [Twilio Sign Up](https://www.twilio.com/try-twilio)
2. Click **Sign Up** to create a new account
3. Fill in your email, password, and basic information
4. Verify your email and phone number
5. Complete account activation
> 💡 **Tip**: New users receive $15 USD in free trial credits.
---
### Step 2: Obtain API Credentials
After registration, access the Twilio Console:
1. Log in to [Twilio Console](https://console.twilio.com)
2. Locate the **Account Info** section on the Dashboard
3. Note the following information:
- **Account SID**: Format `ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`
- **Auth Token**: Click to reveal and copy (keep this secure)
> ⚠️ **Security Notice**: The Auth Token is essentially your API password. Never share it publicly. If compromised, regenerate it immediately in the console.
---
### Step 3: Get a Phone Number
You need a Twilio phone number as the SMS sender:
1. In Twilio Console, navigate to **Phone Numbers****Manage****Buy a number**
2. Select a country and check the **SMS** capability
3. Choose and purchase a number (trial accounts get one free number)
4. Note your Twilio phone number (format: `+1xxxxxxxxxx`)
**Number Selection Tips:**
- Choose a number from the same country as recipients to reduce costs
- For international recipients, consider the destination country's regulations
- Some countries require sender ID registration
---
### Step 4: Configure Environment Variables
Add Twilio parameters to your `backend_api_python/.env` file:
```bash
# =========================
# Phone / SMS Configuration (Twilio)
# =========================
# Twilio Account SID (required)
# Format: ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Twilio Auth Token (required)
# Obtained from Twilio Console
TWILIO_AUTH_TOKEN=your_auth_token_here
# Twilio Sender Number (required)
# Format: +CountryCodeNumber, e.g., +14155552671
TWILIO_FROM_NUMBER=+14155552671
```
Restart the backend service after configuration to apply changes.
---
### Step 5: Enable SMS Notifications in Strategy
In the strategy configuration page under "Signal Notifications":
1. Enable the **Phone** notification channel
2. Enter the recipient phone number in the designated field
**Number Format Requirements:**
- Must include country code
- Format: `+CountryCodeNumber`
- Examples:
- United States: `+14155552671`
- United Kingdom: `+447911123456`
- Germany: `+4915112345678`
- Australia: `+61412345678`
> 💡 **Tip**: You can enter multiple numbers (comma-separated) for multi-recipient notifications.
---
## Pricing Information
Twilio uses pay-as-you-go pricing. SMS costs vary by destination:
| Destination | Approx. Cost (USD/message) |
|-------------|---------------------------|
| United States | $0.0079 |
| Canada | $0.0075 |
| United Kingdom | $0.04 |
| Germany | $0.07 |
| Australia | $0.05 |
| Japan | $0.08 |
| India | $0.04 |
> 💰 **Note**: For current pricing, visit [Twilio SMS Pricing](https://www.twilio.com/sms/pricing). Prices may change.
**Trial Account Limitations:**
- $15 USD free credits
- Can only send to verified phone numbers
- Messages include "Sent from your Twilio trial account" prefix
Upgrade to a paid account to remove these limitations.
---
## Troubleshooting
### Q: Can trial accounts send to any number?
No. Trial accounts can only send to verified phone numbers. Add and verify recipient numbers in Twilio Console under **Verified Caller IDs**. Upgrade to a paid account for unrestricted sending.
### Q: Send failed with invalid number error?
1. Ensure correct format with country code (e.g., `+14155552671`)
2. Remove spaces, dashes, or special characters from the number
3. Verify the recipient can receive international SMS
### Q: Messages not delivered to certain countries?
1. Some carriers may block international SMS
2. Check country-specific regulations (some require sender ID registration)
3. Verify the destination country is supported by Twilio
4. Contact Twilio support for country-specific issues
### Q: How to check delivery status?
Log in to Twilio Console → **Monitor****Logs****Messaging** to view all SMS records, delivery status, and error details.
### Q: Auth Token was compromised?
Immediately log in to Twilio Console → **Account****API Credentials** → Click **Regenerate Auth Token**.
### Q: Are there alternatives to Twilio?
QuantDinger currently only supports Twilio as the SMS provider. For other services, use the Webhook channel to integrate:
- Nexmo (Vonage)
- AWS SNS
- MessageBird
- Plivo
---
## Complete Environment Variable Reference
```bash
# Twilio SMS Configuration
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Account SID
TWILIO_AUTH_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Auth Token
TWILIO_FROM_NUMBER=+14155552671 # Sender number
```
---
## Related Documentation
- [Telegram Notification Configuration](./NOTIFICATION_TELEGRAM_CONFIG_EN.md)
- [Email SMTP Notification Configuration](./NOTIFICATION_EMAIL_CONFIG_EN.md)
- [Strategy Development Guide](./STRATEGY_DEV_GUIDE.md)
- [Twilio Official Documentation](https://www.twilio.com/docs/sms)
+122 -10
View File
@@ -1,14 +1,126 @@
# TELEGRAM通知配置
# 📱 Telegram 通知配置指南
## 1.创建telegram机器人并且获取token
<img src="./screenshots/notification_telegram_token.png" alt="QuantDinger Dashboard" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
> QuantDinger 支持通过 Telegram Bot 推送策略信号通知,实时获取交易提醒。
## 2.1 在策略中配置UserID
<img src="./screenshots/notification_telegram_userid.png" alt="QuantDinger Dashboard" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
---
## 📋 目录
- [前置要求](#前置要求)
- [第一步:创建 Telegram Bot](#第一步创建-telegram-bot)
- [第二步:获取 Bot Token](#第二步获取-bot-token)
- [第三步:获取您的 User ID](#第三步获取您的-user-id)
- [第四步:配置环境变量](#第四步配置环境变量)
- [第五步:策略中启用 Telegram 通知](#第五步策略中启用-telegram-通知)
- [常见问题](#常见问题)
---
## 前置要求
- 已安装 Telegram 客户端(手机或桌面版)
- 拥有 Telegram 账号
- QuantDinger 后端服务已部署并运行
---
## 第一步:创建 Telegram Bot
1. 在 Telegram 中搜索 **@BotFather**(官方机器人管理工具)
2. 发送 `/newbot` 命令开始创建新机器人
3. 按照提示输入机器人名称(如:`QuantDinger Signal Bot`
4. 输入机器人用户名(必须以 `bot` 结尾,如:`quantdinger_signal_bot`
<img src="./screenshots/notification_telegram_token.png" alt="创建 Telegram Bot" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
---
## 第二步:获取 Bot Token
创建成功后,BotFather 会返回一个 **HTTP API Token**,格式如下:
## 2.2 UserID的获取
```aiignore
https://api.telegram.org/bot【你的哪个token】/getUpdates
```
UserID从这个链接获取,把你的token填进去,token格式是【123:abc】
![notification_telegram_userid_get.png](screenshots/notification_telegram_userid_get.png)
123456789:ABCdefGHIjklMNOpqrsTUVwxyz
```
> ⚠️ **安全提示**:请妥善保管此 Token,不要泄露给他人。如果 Token 泄露,请立即在 BotFather 中使用 `/revoke` 命令重新生成。
---
## 第三步:获取您的 User ID
### 方法一:通过 API 获取(推荐)
1. 先向您刚创建的 Bot 发送任意消息(如 `/start`
2. 在浏览器中访问以下 URL(将 `YOUR_BOT_TOKEN` 替换为您的 Token):
```
https://api.telegram.org/bot{YOUR_BOT_TOKEN}/getUpdates
```
**示例**
```
https://api.telegram.org/bot123456789:ABCdefGHIjklMNOpqrsTUVwxyz/getUpdates
```
3. 在返回的 JSON 中找到 `chat.id` 字段,这就是您的 User ID
<img src="./screenshots/notification_telegram_userid_get.png" alt="获取 User ID" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
### 方法二:通过 @userinfobot 获取
1. 在 Telegram 中搜索 **@userinfobot**
2. 发送任意消息,机器人会返回您的 User ID
---
## 第四步:配置环境变量
`backend_api_python/.env` 文件中配置 Bot Token
```bash
# Telegram Bot Token(必填)
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
```
配置完成后重启后端服务使配置生效。
---
## 第五步:策略中启用 Telegram 通知
在策略配置页面的「信号通知」设置中:
1. 勾选启用 **Telegram** 通知渠道
2.**User ID** 字段填入您的 Telegram User ID
<img src="./screenshots/notification_telegram_userid.png" alt="配置 User ID" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
> 💡 **提示**:支持填入多个 User ID(逗号分隔)或群组/频道 ID,实现多人通知。
---
## 常见问题
### Q: 收不到通知怎么办?
1. 确认已向 Bot 发送过消息(Bot 需要先被激活)
2. 检查 `TELEGRAM_BOT_TOKEN` 环境变量是否正确配置
3. 确认 User ID 填写正确
4. 查看后端日志是否有错误信息
### Q: 可以发送到群组吗?
可以。将 Bot 添加到群组后,使用群组 ID(负数)作为 User ID 即可。获取群组 ID 的方法与获取个人 ID 类似。
### Q: Token 格式是什么?
Token 格式为 `数字:字母数字字符串`,例如 `123456789:ABCdefGHIjklMNOpqrsTUVwxyz`
---
## 相关文档
- [邮箱 SMTP 通知配置](./NOTIFICATION_EMAIL_CONFIG_CH.md)
- [手机短信通知配置](./NOTIFICATION_SMS_CONFIG_CH.md)
- [策略开发指南](./STRATEGY_DEV_GUIDE_CN.md)
+122 -10
View File
@@ -1,14 +1,126 @@
# TELEGRAM NOTIFICATION CONFIG
# 📱 Telegram Notification Configuration Guide
## 1.Create telegram Bot and get Bot token
<img src="./screenshots/notification_telegram_token.png" alt="QuantDinger Dashboard" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
> QuantDinger supports real-time strategy signal notifications via Telegram Bot.
## 2.1 configuration UserID in signal config
<img src="./screenshots/notification_telegram_userid.png" alt="QuantDinger Dashboard" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
---
## 📋 Table of Contents
- [Prerequisites](#prerequisites)
- [Step 1: Create a Telegram Bot](#step-1-create-a-telegram-bot)
- [Step 2: Obtain Bot Token](#step-2-obtain-bot-token)
- [Step 3: Get Your User ID](#step-3-get-your-user-id)
- [Step 4: Configure Environment Variables](#step-4-configure-environment-variables)
- [Step 5: Enable Telegram Notifications in Strategy](#step-5-enable-telegram-notifications-in-strategy)
- [Troubleshooting](#troubleshooting)
---
## Prerequisites
- Telegram client installed (mobile or desktop)
- Active Telegram account
- QuantDinger backend service deployed and running
---
## Step 1: Create a Telegram Bot
1. Search for **@BotFather** in Telegram (official bot management tool)
2. Send the `/newbot` command to create a new bot
3. Enter a display name for your bot (e.g., `QuantDinger Signal Bot`)
4. Choose a unique username ending with `bot` (e.g., `quantdinger_signal_bot`)
<img src="./screenshots/notification_telegram_token.png" alt="Create Telegram Bot" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
---
## Step 2: Obtain Bot Token
Upon successful creation, BotFather will provide an **HTTP API Token** in this format:
## 2.2 UserID edit and get
```aiignore
https://api.telegram.org/bot【your bot token】/getUpdates
```
UserID from this urlreplace your bot tokentoken like【123:abc】
![notification_telegram_userid_get.png](screenshots/notification_telegram_userid_get.png)
123456789:ABCdefGHIjklMNOpqrsTUVwxyz
```
> ⚠️ **Security Notice**: Keep this token secure and never share it publicly. If compromised, use `/revoke` command in BotFather to regenerate immediately.
---
## Step 3: Get Your User ID
### Method 1: Via Telegram API (Recommended)
1. First, send any message to your newly created bot (e.g., `/start`)
2. Visit the following URL in your browser (replace `YOUR_BOT_TOKEN` with your actual token):
```
https://api.telegram.org/bot{YOUR_BOT_TOKEN}/getUpdates
```
**Example**:
```
https://api.telegram.org/bot123456789:ABCdefGHIjklMNOpqrsTUVwxyz/getUpdates
```
3. Locate the `chat.id` field in the JSON response — this is your User ID
<img src="./screenshots/notification_telegram_userid_get.png" alt="Get User ID" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
### Method 2: Via @userinfobot
1. Search for **@userinfobot** in Telegram
2. Send any message, and it will reply with your User ID
---
## Step 4: Configure Environment Variables
Add the Bot Token to your `backend_api_python/.env` file:
```bash
# Telegram Bot Token (required)
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrsTUVwxyz
```
Restart the backend service after configuration to apply changes.
---
## Step 5: Enable Telegram Notifications in Strategy
In the strategy configuration page under "Signal Notifications":
1. Enable the **Telegram** notification channel
2. Enter your Telegram User ID in the designated field
<img src="./screenshots/notification_telegram_userid.png" alt="Configure User ID" width="100%" style="border-radius: 10px; box-shadow: 0 4px 8px rgba(0,0,0,0.1);">
> 💡 **Tip**: You can enter multiple User IDs (comma-separated) or group/channel IDs for multi-recipient notifications.
---
## Troubleshooting
### Q: Not receiving notifications?
1. Ensure you've sent a message to the bot first (bot must be activated)
2. Verify `TELEGRAM_BOT_TOKEN` environment variable is correctly configured
3. Double-check the User ID is correct
4. Review backend logs for error messages
### Q: Can I send to groups?
Yes. Add the bot to a group, then use the group ID (negative number) as the target. Obtain the group ID using the same method as personal ID.
### Q: What's the token format?
Token format is `numbers:alphanumeric_string`, e.g., `123456789:ABCdefGHIjklMNOpqrsTUVwxyz`
---
## Related Documentation
- [Email SMTP Notification Configuration](./NOTIFICATION_EMAIL_CONFIG_EN.md)
- [SMS Notification Configuration](./NOTIFICATION_SMS_CONFIG_EN.md)
- [Strategy Development Guide](./STRATEGY_DEV_GUIDE.md)