Files
crypto_monitor/manual_trading_hub/交易监管说明.md
T
dekun bfbd6879d6 Add AI trading supervisor with WeChat push and daily session
Proactive monitoring for manual/hub closes and new opens prevents overtrading via in-app alerts, configurable WeChat links, and supervisor chat.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 19:25:01 +08:00

85 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 交易监管(AI 教练)
中控 **交易监管** 用于防止过度交易与频繁手动操作:在 **手动/中控开平仓****新开仓** 时自动推送至 **今日监管长会话**,并可选 **企业微信** 提醒;程序止盈/止损按「正常执行」鼓励,不计入频繁交易统计。
入口:**AI 教练**`/ai`)→ Tab **交易监管**,或微信链接(在系统设置中配置)。
## 监管范围
| 类型 | 识别 | 页内推送 | 微信(P0) | 频率统计 |
|------|------|----------|------------|----------|
| 实例手动平仓 | `result = 手动平仓` | ✓ | ✓ | ✓ |
| 中控平仓 | `result = 强制清仓` 等 | ✓ | ✓ | ✓ |
| 新开仓 | 监控板持仓 diff(0→有仓 / 新合约) | ✓ | ✓ | ✓ |
| 程序止盈 | 止盈 / 保本止盈 / 移动止盈 | ✓ | 可选 | ✗ |
| 程序止损 | 止损 | ✓ | 可选 | ✗ |
| 外部平仓 | 外部平仓、时间平仓 | ✗ | ✗ | ✗ |
频率规则(间隔过短、30 分钟笔数、日笔数、连亏、平后快开)**只对手动/中控开平** 叠加 `[监管·频率]` 警告。
## 会话
- 每个交易日 **一条长会话**`bot_mode: supervisor`,标题 `今日监管 YYYY-MM-DD`)。
- 系统消息(`role: system`+ AI 短评(`assistant`+ 用户回复(`user`)同线程。
-**交易教练 / 普通聊天** 分离;监管会话不支持「新开对话」。
## 系统设置
路径:**系统设置** → **交易监管 · 企业微信**(写入 `hub_settings.json``supervisor`)。
| 字段 | 说明 |
|------|------|
| `enabled` | 总开关 |
| `wechat_webhook` | **监管专用** 企业微信机器人(与四所实例 `.env``WECHAT_WEBHOOK` 独立) |
| `wechat_link_base` | 微信消息末尾跳转链接(**可单独修改**,如 `https://域名/ai?mode=supervisor` |
| `wechat_prefix` | 消息前缀,默认 `【交易监管】` |
| `wechat_on_program_tp_sl` | 程序止盈/止损是否也发微信 |
| `manual_close_daily_warn` | 日手动平警告阈值(默认 2) |
| `interval_warn_minutes` | 两笔手动/中控平最短间隔(默认 15 分钟) |
| `freq_30m_count` | 30 分钟内笔数阈值(默认 2) |
| `reopen_after_close_minutes` | 手动平后再开仓警告间隔(默认 30 分钟) |
`.env` 兜底(设置页保存优先):
```env
SUPERVISOR_WECHAT_WEBHOOK=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=...
SUPERVISOR_WECHAT_LINK=https://你的域名/ai?mode=supervisor
SUPERVISOR_POLL_INTERVAL_SEC=30
```
## API
| 方法 | 路径 | 说明 |
|------|------|------|
| GET | `/api/ai/supervisor/session` | 今日监管会话 |
| GET | `/api/ai/supervisor/stream` | SSE 版本推送 |
| POST | `/api/ai/supervisor/chat/send` | 用户回聊(JSON `{ "message": "..." }` |
| GET | `/api/ai/supervisor/rules` | 当前阈值 |
| POST | `/api/ai/supervisor/refresh` | 立即扫描 |
## 存储
| 文件 | 内容 |
|------|------|
| `hub_supervisor_state.json` | 已处理事件、持仓快照、频率统计 |
| `hub_ai_chat.json` | 监管会话(`bot_mode: supervisor` |
| `hub_settings.json` | `supervisor` 配置节 |
**首次启用** 会对当前交易日已有平仓做 **种子同步**(不补发历史推送),避免部署瞬间刷屏。
## 与实例风控
实例 `account_risk_lib`(冷静期 / 日冻结)为 **硬拦截**;监管为 **软提醒 + 陪聊**,不绕过实例开仓限制。
## 代码位置
| 模块 | 路径 |
|------|------|
| 规则与推送 | `hub_supervisor_lib.py` |
| 后台扫描 | `hub_supervisor_cache.py` |
| 会话 | `hub_ai/supervisor_store.py` |
| AI 评语/回聊 | `hub_ai/supervisor.py` |
| 提示词 | `hub_ai/prompts.py``SUPERVISOR_SYSTEM` |
部署后重启中控:`pm2 restart manual-trading-hub`(或你的 hub 进程名)。