Files
qihuo/docs/STRATEGY.md
T
dekun 169136dd4a Add modular docs with index, WeChat templates, and AI guide.
Document per-module order logic, risk rules, and WeChat message templates with a central INDEX for navigation.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 10:49:10 +08:00

118 lines
2.8 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.
# 策略交易
**页面路径**`/strategy``/strategy/records`
**相关文件**`install_trading.py`(趋势回调、顺势加仓/滚仓)
---
## 功能概述
| 策略 | 说明 |
|------|------|
| 趋势回调 | 首仓 + 网格补仓 + 统一止盈 |
| 顺势加仓(滚仓) | 对已有 active 持仓加仓,单独保证金上限 |
均需 **CTP 已连接** 且有对应持仓监控。
---
## 趋势回调 — 下单逻辑
### 1. 创建计划(预览 → 确认首仓)
用户填写:品种、方向、止损、补仓上沿、止盈、风险比例等 → 系统预览手数/网格 → 确认后 **市价开首仓**
**校验**(与下单监控相同):
- 交易时段、CTP 连接
- `assert_can_open()`、[RISK.md](./RISK.md)
- 品种范围、保证金上限
**成交后**
- 写入 `trend_pullback_plans`status=active
- 创建/关联 `trade_order_monitors`monitor_type=trend
- 微信:`趋势回调首仓 {sym} {first_lots}手`
### 2. 运行中监控
后台扫描 active 计划:
| 条件 | 动作 |
|------|------|
| 价格触及 **take_profit** | 全部平仓,计划结案 |
| 价格回落至 **网格档位** | 按档位补仓(不超过 remainder_lots |
**补仓**:市价加仓,更新均价与监控。
**止盈**:市价全平。
微信:
- 止盈 → `趋势回调止盈 {sym}`
- 补仓 → `趋势回调补仓 {sym} +{add_lots}手 @档位{N}`
### 3. 策略记录
`/strategy/records` 单独归档已结束计划。
---
## 顺势加仓(滚仓)— 下单逻辑
针对 **已有 active 持仓** 的加仓预览与执行。
**特殊风控**
| 项 | 说明 |
|----|------|
| 仓位上限冻结 | **仍允许滚仓**`can_roll=True` |
| `roll_max_margin_pct` | 滚仓后总保证金占用单独上限 |
| 手数收紧 | `cap_lots_for_margin_budget()` 按滚仓上限裁剪 |
流程:预览加仓价/手数/新止损 → 确认 → CTP 市价加仓 → 更新 monitor。
---
## 风控规则
| 规则 | 趋势首仓 | 滚仓 |
|------|----------|------|
| assert_can_open | ✓ | 仓位冻结时仍可 |
| max_margin_pct | ✓ 首仓 | — |
| roll_max_margin_pct | — | ✓ |
| 交易时段 | ✓ | ✓ |
| 品种范围 | ✓ | ✓ |
| 单笔 50 手 | ✓ | ✓ |
全局规则见 [RISK.md](./RISK.md)。
---
## 止盈止损
趋势持仓纳入 `sl_tp_guard` 本地监控(与下单监控相同机制)。
- monitor_type = `trend` / `roll`
- 平仓写入 `trade_logs`,来源标签「趋势回调」「顺势加仓」
---
## 微信推送
| 事件 | 模板 |
|------|------|
| 首仓 | [WECHAT §11](./WECHAT.md#11-策略趋势回调) |
| 止盈 | 同上 |
| 补仓 | 同上 |
| 结构化平仓 | [WECHAT §4](./WECHAT.md#4-平仓完成) |
---
## 相关文档
- [ORDER_MONITOR.md](./ORDER_MONITOR.md)
- [RISK.md](./RISK.md)
- [WECHAT.md](./WECHAT.md)