feat(crypto策略): 新增 AG 趋势、异动与波段跟踪信号支持

Motivation:
crypto-strategy 源新增 AG 趋势(AGTS)、异动(AMA)、波段跟踪(BTS) 三类量化策略信号,需与既有 trade.* 事件区分以避免和 AI crypto signals 精确匹配冲突,并为缺省方向提供兜底推导。

Changes:

* 事件名映射按 strategyCode 使用独立前缀(AGTS./AMA./BTS.,HLSS 保持不变)
* direction/side 缺失时依据 isSale 兜底推导为 LONG/SHORT
* 补充三类策略的模板、规则示例文档与渲染/转换测试
This commit is contained in:
2026-08-17 11:07:34 +08:00
parent a93078dc00
commit a2c0590353
4 changed files with 315 additions and 7 deletions
+97
View File
@@ -565,3 +565,100 @@ curl -X POST 'http://localhost:8080/api/v1/rules' \
"enabled": 1
}'
```
---
## AG 趋势 / 异动 / 波段跟踪(crypto-strategy
Source`crypto-strategy`。Convert 后事件为 `AGTS.*` / `AMA.*` / `BTS.*`(与 `trade.*` 分开,避免和 AI crypto signals 抢精确匹配)。
| 策略 | strategyCode | 样例 payload | Convert event |
|------|--------------|--------------|---------------|
| AG趋势 | `AGTS` | `isSale` 开仓,带 `gainPrices` / `openPrice2` / `lossPrice` | `AGTS.open` |
| 异动 | `AMA` | 开仓,仅 `price` | `AMA.open` |
| 波段跟踪 | `BTS` | `isClose=true`,仅 `price` | `BTS.close` |
有效期按样例写死:AG 6 天、异动 2-4 天、波段 17h。波段周期含 `2h``2小时`
### 创建 AG 趋势模板
```bash
curl -X POST 'http://localhost:8080/api/v1/templates' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "ag_trend",
"content": "监控告警提醒\n\n操作策略:AG趋势{{case .symbol \"BTCUSDT\" \"BTC\" \"ETHUSDT\" \"ETH\" \"SOLUSDT\" \"SOL\" \"BNBUSDT\" \"BNB\" .symbol}}-{{case .period \"1h\" \"1小时\" \"2h\" \"2小时\" \"4h\" \"4小时\" \"6h\" \"6小时\" \"15m\" \"15分钟\" \"5m\" \"5分钟\" \"30m\" \"30分钟\" \"1d\" \"1日\" .period}}周期{{case .side \"LONG\" \"做多\" \"SHORT\" \"做空\"}}\n\n提醒时间:{{.pushedAt}}\n\n{{with .takeProfitRange}}止盈目标:{{.}}\n\n{{else}}{{with .takeProfitPrice}}止盈目标:{{.}}\n\n{{end}}{{end}}{{with .entryRange}}介入区间:{{.}}\n\n{{else}}{{with .price}}介入区间:{{.}}\n\n{{end}}{{end}}{{with .stopLossPrice}}止损价位:{{.}}\n\n{{end}}有效期:6天"
}'
```
### 创建异动预警模板
```bash
curl -X POST 'http://localhost:8080/api/v1/templates' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "anomaly_alert",
"content": "监控告警提醒\n\n监控名称:异动预警\n\n监控时间:{{.pushedAt}}\n\n监控目标:{{case .symbol \"BTCUSDT\" \"BTC\" \"ETHUSDT\" \"ETH\" \"SOLUSDT\" \"SOL\" \"BNBUSDT\" \"BNB\" .symbol}}异动预警(暴涨/跌)生效\n\n监控提醒:异动发生概率v1(v1<v2<v3)\n\n有效期:2-4天"
}'
```
### 创建波段跟踪模板
```bash
curl -X POST 'http://localhost:8080/api/v1/templates' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "swing_track",
"content": "监控告警提醒\n\n监控名称:波段跟踪触发{{case .symbol \"BTCUSDT\" \"BTC\" \"ETHUSDT\" \"ETH\" \"SOLUSDT\" \"SOL\" \"BNBUSDT\" \"BNB\" .symbol}}-{{case .period \"1h\" \"1小时\" \"2h\" \"2小时\" \"4h\" \"4小时\" \"6h\" \"6小时\" \"15m\" \"15分钟\" \"5m\" \"5分钟\" \"30m\" \"30分钟\" \"1d\" \"1日\" .period}}周期{{case .side \"LONG\" \"做多\" \"SHORT\" \"做空\"}}\n\n监控时间:{{.pushedAt}}\n\n监控提醒:当前提醒价格{{with .takeProfitRange}}{{.}}{{else}}{{with .entryRange}}{{.}}{{else}}{{.price}}{{end}}{{end}}\n\n监控状态:等待量化信号平仓\n\n有效期: 17h"
}'
```
### 创建规则
```bash
curl -X POST 'http://localhost:8080/api/v1/rules' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "AG趋势",
"source_name": "crypto-strategy",
"event": "AGTS.*",
"template_name": "ag_trend",
"channels": ["safew_AG趋势", "safew_AG趋势02", "safew_AG趋势03"],
"conditions": [{"field": "strategyCode", "op": "eq", "value": "AGTS"}],
"enabled": 1
}'
```
```bash
curl -X POST 'http://localhost:8080/api/v1/rules' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "异动预警",
"source_name": "crypto-strategy",
"event": "AMA.*",
"template_name": "anomaly_alert",
"channels": ["safew_异动策略", "safew_异动策略02", "safew_异动策略03"],
"conditions": [{"field": "strategyCode", "op": "eq", "value": "AMA"}],
"enabled": 1
}'
```
```bash
curl -X POST 'http://localhost:8080/api/v1/rules' \
-H 'Authorization: Bearer admin-sk-change-me' \
-H 'Content-Type: application/json' \
-d '{
"name": "波段跟踪",
"source_name": "crypto-strategy",
"event": "BTS.*",
"template_name": "swing_track",
"channels": ["safew_波段跟踪02", "safew_波段跟踪03"],
"conditions": [{"field": "strategyCode", "op": "eq", "value": "BTS"}],
"enabled": 1
}'
```