c7e154d7cc
Motivation: 钉钉机器人的 webhook 前缀固定不变,要求用户填写完整 URL 冗余且容易出错。简化通道配置项,降低接入配置成本,同时保证存量配置不受影响。 Changes: * 钉钉通道配置改用 access_token,webhook 前缀由内部固定拼接 * 保留对旧 webhook_url 配置的兼容,access_token 存在时优先生效 * 新增 webhook 地址解析逻辑的单元测试,覆盖优先级与回退场景 * 同步更新 README、HTTP 请求示例及设计文档中的配置示例 * E2E 测试改用 E2E_DINGTALK_ACCESS_TOKEN 环境变量并按新格式创建通道
810 lines
22 KiB
Markdown
810 lines
22 KiB
Markdown
# HTTPie 可导入 cURL 集合
|
||
|
||
**推荐:** 直接导入 Postman 集合(一次导入全部)
|
||
|
||
```
|
||
docs/httpie/postman_collection.json
|
||
```
|
||
|
||
HTTPie → Import → Postman → 选择该文件。
|
||
|
||
**单条导入:** Import → cURL → 粘贴下方某一条完整 `curl`。
|
||
|
||
替换占位符:
|
||
|
||
| 占位符 | 说明 |
|
||
|--------|------|
|
||
| `http://localhost:8080` | 服务地址 |
|
||
| `admin-sk-change-me` | `config.yaml` 的 `server.admin_key` |
|
||
| `SOURCE_API_KEY` | 创建 Source 返回的 `api_key` |
|
||
| `:id` / `1` | 资源数字 ID |
|
||
|
||
---
|
||
|
||
## Health
|
||
|
||
### 健康检查
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/health'
|
||
```
|
||
|
||
---
|
||
|
||
## Notify
|
||
|
||
### 发送通知(JSON)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/notify' \
|
||
-H 'Authorization: Bearer SOURCE_API_KEY' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"event": "trade.open",
|
||
"data": {
|
||
"symbol": "BTC",
|
||
"price": 65000
|
||
}
|
||
}'
|
||
```
|
||
|
||
### 发送通知(Regex)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/notify' \
|
||
-H 'Authorization: Bearer SOURCE_API_KEY' \
|
||
-H 'Content-Type: text/plain' \
|
||
--data-binary 'trade.open BTC 开仓 价格:65000'
|
||
```
|
||
|
||
### 发送通知(Text,event=default)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/notify' \
|
||
-H 'Authorization: Bearer SOURCE_API_KEY' \
|
||
-H 'Content-Type: text/plain' \
|
||
--data-binary 'BTC 突破 68000,请注意风险'
|
||
```
|
||
|
||
---
|
||
|
||
## Sources
|
||
|
||
### 创建 Source(JSON)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/sources' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trading-system",
|
||
"parse_mode": "json",
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Source(Regex)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/sources' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "legacy-monitor",
|
||
"parse_mode": "regex",
|
||
"parse_pattern": "(?P<event>\\w+)\\s+(?P<message>.+)"
|
||
}'
|
||
```
|
||
|
||
### 创建 Source(Text)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/sources' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "alert-bot",
|
||
"parse_mode": "text"
|
||
}'
|
||
```
|
||
|
||
### 列出 Source
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/sources?page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 获取 Source
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/sources/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 更新 Source
|
||
|
||
```bash
|
||
curl -X PUT 'http://localhost:8080/api/v1/sources/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trading-system",
|
||
"parse_mode": "json",
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 删除 Source
|
||
|
||
```bash
|
||
curl -X DELETE 'http://localhost:8080/api/v1/sources/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## Templates
|
||
|
||
### 创建 Template
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/templates' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trade_open",
|
||
"content": "### {{.symbol}} 开仓\n价格: {{.price}}"
|
||
}'
|
||
```
|
||
|
||
### 列出 Template
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/templates?page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 获取 Template
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/templates/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 更新 Template
|
||
|
||
```bash
|
||
curl -X PUT 'http://localhost:8080/api/v1/templates/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trade_open",
|
||
"content": "### {{.symbol}} 开仓\n价格: {{.price}}"
|
||
}'
|
||
```
|
||
|
||
### 删除 Template
|
||
|
||
```bash
|
||
curl -X DELETE 'http://localhost:8080/api/v1/templates/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## Channels
|
||
|
||
### 创建 Channel(Email)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "email-ops",
|
||
"type": "email",
|
||
"config": {
|
||
"to": ["148516886@qq.com"]
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Channel(钉钉)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "dingtalk-prod",
|
||
"type": "dingtalk",
|
||
"config": {
|
||
"access_token": "xxx",
|
||
"secret": "SEC..."
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Channel(企业微信)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "wecom-ops",
|
||
"type": "wecom",
|
||
"config": {
|
||
"webhook_url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx"
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Channel(Bark)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "bark-phone",
|
||
"type": "bark",
|
||
"config": {
|
||
"url": "https://api.day.app/<device_key>"
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 创建 Channel(SafeW)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "safew-ops",
|
||
"type": "safew",
|
||
"config": {
|
||
"token": "<bot token>",
|
||
"chat_id": "123456789"
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 列出 SafeW 群(创建渠道时)
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/channels/safew/chats' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{"token":"<bot token>","q":"测试AI"}'
|
||
```
|
||
|
||
### 列出 SafeW 群(已有渠道)
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/channels/1/chats?q=' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 列出 Channel
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/channels?page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 获取 Channel
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/channels/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 更新 Channel
|
||
|
||
```bash
|
||
curl -X PUT 'http://localhost:8080/api/v1/channels/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "email-ops",
|
||
"type": "email",
|
||
"config": {
|
||
"to": ["148516886@qq.com"]
|
||
},
|
||
"status": 1
|
||
}'
|
||
```
|
||
|
||
### 删除 Channel
|
||
|
||
```bash
|
||
curl -X DELETE 'http://localhost:8080/api/v1/channels/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## Rules
|
||
|
||
### 创建 Rule
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/rules' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trade-open-alert",
|
||
"source_name": "trading-system",
|
||
"event": "trade.open",
|
||
"template_name": "trade_open",
|
||
"channels": ["email-ops"],
|
||
"conditions": [
|
||
{"field": "symbol", "op": "exists"},
|
||
{"field": "price", "op": "gt", "value": "0"}
|
||
],
|
||
"enabled": 1
|
||
}'
|
||
```
|
||
|
||
### 列出 Rule
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/rules?page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 获取 Rule
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/rules/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 更新 Rule
|
||
|
||
```bash
|
||
curl -X PUT 'http://localhost:8080/api/v1/rules/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "trade-open-alert",
|
||
"source_name": "trading-system",
|
||
"event": "trade.open",
|
||
"template_name": "trade_open",
|
||
"channels": ["email-ops"],
|
||
"enabled": 1
|
||
}'
|
||
```
|
||
|
||
### 删除 Rule
|
||
|
||
```bash
|
||
curl -X DELETE 'http://localhost:8080/api/v1/rules/1' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 启用 Rule
|
||
|
||
```bash
|
||
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/enable' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 禁用 Rule
|
||
|
||
```bash
|
||
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/disable' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 启用规则下某渠道
|
||
|
||
```bash
|
||
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/channels/1/enable' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
### 禁用规则下某渠道
|
||
|
||
```bash
|
||
curl -X PATCH 'http://localhost:8080/api/v1/rules/1/channels/1/disable' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## Message Logs
|
||
|
||
### 查询消息记录
|
||
|
||
```bash
|
||
curl -X GET 'http://localhost:8080/api/v1/message-logs?source=trading-system&event=trade.open&status=success&page=1&page_size=20' \
|
||
-H 'Authorization: Bearer admin-sk-change-me'
|
||
```
|
||
|
||
---
|
||
|
||
## AI crypto signals(crypto-strategy)
|
||
|
||
Source:`crypto-strategy`。渠道:`safew_ai_crypto_signals`。条件:`strategyCode = ai-crypto-signals`。
|
||
|
||
事件:开仓(多/空)→ `trade.open`;止盈 → `trade.gain`;止损 → `trade.close`。空单开仓不再发 `trade.sell`。
|
||
|
||
开仓渲染示例:
|
||
|
||
```
|
||
预警时间:2026-08-16 03:20:13
|
||
预警币种:APE
|
||
交易方向:做多
|
||
建议杠杆:31x
|
||
入场区域:0.1235
|
||
风险控制(止损):0.1223
|
||
止盈目标:
|
||
TP1:0.1241
|
||
TP2:0.1247
|
||
TP3:0.1253
|
||
TP4:0.1259
|
||
TP5:0.1265
|
||
推送时间:2026-08-16 03:20:13
|
||
```
|
||
|
||
止盈渲染示例:
|
||
|
||
```
|
||
止盈时间:2026-08-16 16:29:23
|
||
预警币种:LTC
|
||
执行操作:到达第一止盈 (TP1)
|
||
平仓点位:44.63
|
||
预警收益:+14.2793%
|
||
预警周期:53分钟
|
||
```
|
||
|
||
止损渲染示例:
|
||
|
||
```
|
||
止损时间:2026-08-16 16:17:15
|
||
预警币种:ETH
|
||
执行操作:触发止损
|
||
平仓点位:1887
|
||
最终损益:-30.1557%
|
||
```
|
||
|
||
### 创建开仓模板
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/templates' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "ai_crypto_signals_open",
|
||
"content": "预警时间:{{.pushedAt}}\n预警币种:{{.symbol}}\n交易方向:{{case .side \"LONG\" \"做多\" \"SHORT\" \"做空\"}}\n{{line \"建议杠杆\" .leverageText}}入场区域:{{.entryRange}}\n{{line \"风险控制(止损)\" .stopLossPrice}}止盈目标:\n{{with .tp1}}TP1:{{.}}\n{{end}}{{with .tp2}}TP2:{{.}}\n{{end}}{{with .tp3}}TP3:{{.}}\n{{end}}{{with .tp4}}TP4:{{.}}\n{{end}}{{with .tp5}}TP5:{{.}}\n{{end}}推送时间:{{.pushedAt}}"
|
||
}'
|
||
```
|
||
|
||
### 创建止盈模板
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/templates' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "ai_crypto_signals_gain",
|
||
"content": "止盈时间:{{.pushedAt}}\n预警币种:{{.symbol}}\n执行操作:{{.closeAction}}\n平仓点位:{{.price}}\n预警收益:{{.revenueDisplay}}\n{{line \"预警周期\" .holdPeriod}}"
|
||
}'
|
||
```
|
||
|
||
### 创建止损模板
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/templates' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "ai_crypto_signals_close",
|
||
"content": "止损时间:{{.pushedAt}}\n预警币种:{{.symbol}}\n执行操作:触发止损\n平仓点位:{{.price}}\n最终损益:{{.revenueDisplay}}\n{{line \"预警周期\" .holdPeriod}}"
|
||
}'
|
||
```
|
||
|
||
### 创建开仓 / 止盈 / 止损规则
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/rules' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "AI crypto signals 开仓",
|
||
"source_name": "crypto-strategy",
|
||
"event": "trade.open",
|
||
"template_name": "ai_crypto_signals_open",
|
||
"channels": ["safew_ai_crypto_signals"],
|
||
"conditions": [
|
||
{"field": "strategyCode", "op": "eq", "value": "ai-crypto-signals"}
|
||
],
|
||
"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": "AI crypto signals 止盈",
|
||
"source_name": "crypto-strategy",
|
||
"event": "trade.gain",
|
||
"template_name": "ai_crypto_signals_gain",
|
||
"channels": ["safew_ai_crypto_signals"],
|
||
"conditions": [
|
||
{"field": "strategyCode", "op": "eq", "value": "ai-crypto-signals"}
|
||
],
|
||
"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": "AI crypto signals 止损",
|
||
"source_name": "crypto-strategy",
|
||
"event": "trade.close",
|
||
"template_name": "ai_crypto_signals_close",
|
||
"channels": ["safew_ai_crypto_signals"],
|
||
"conditions": [
|
||
{"field": "strategyCode", "op": "eq", "value": "ai-crypto-signals"}
|
||
],
|
||
"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
|
||
}'
|
||
```
|
||
|
||
---
|
||
|
||
## 跟单策略(trade-signal)
|
||
|
||
Source:`trade-signal`。渠道:`safew_B龙策略`。条件:`strategyCode = BLONG`。
|
||
|
||
这是后续跟单策略的共用文案模板(开/加/平/减仓一套)。新跟单策略复用模板 `跟单策略`,再加一条 `trade.*` 规则(换 `strategyCode`、渠道,并在模板 `case .strategyCode` 里补中文名)。兜底规则 `rule-11`(测试AI)需 `strategyCode ne` 已拆出去的跟单 code,避免双发。
|
||
|
||
事件:`OPEN` → `trade.open`,`ADD` → `trade.add`,`CLOSE` → `trade.close`,`REDUCE` → `trade.reduce`;规则用 `trade.*` 全覆盖。
|
||
|
||
开仓渲染示例:
|
||
|
||
```
|
||
空单开仓
|
||
交易品种: ETH
|
||
开仓价格: 1898.76
|
||
开仓数量: 2.00
|
||
平均单价: 1898.76
|
||
杠杆: 100x
|
||
策略: B龙策略
|
||
推送时间: 2026.08.13 13:15:42
|
||
```
|
||
|
||
平仓 / 减仓不输出杠杆;加仓与开仓一样带杠杆。
|
||
|
||
### 创建跟单模板
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/templates' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "跟单策略",
|
||
"content": "{{case .side \"LONG\" \"多单\" \"SHORT\" \"空单\"}}{{case .action \"OPEN\" \"开仓\" \"ADD\" \"加仓\" \"CLOSE\" \"平仓\" \"REDUCE\" \"减仓\"}}\n交易品种: {{case .symbol \"ETHUSDT\" \"ETH\" \"BTCUSDT\" \"BTC\" \"SOLUSDT\" \"SOL\" \"BNBUSDT\" \"BNB\" .symbol}}\n{{case .action \"OPEN\" \"开仓价格\" \"ADD\" \"加仓价格\" \"CLOSE\" \"平仓价格\" \"REDUCE\" \"减仓价格\"}}: {{printf \"%.2f\" .price}}\n{{case .action \"OPEN\" \"开仓数量\" \"ADD\" \"加仓数量\" \"CLOSE\" \"平仓数量\" \"REDUCE\" \"减仓数量\"}}: {{printf \"%.2f\" .quantity}}\n平均单价: {{printf \"%.2f\" .avgPrice}}\n{{if or (eq .action \"OPEN\") (eq .action \"ADD\")}}{{if .leverage}}杠杆: {{.leverage}}x\n{{end}}{{end}}策略: {{case .strategyCode \"BLONG\" \"B龙策略\" .strategyCode}}\n推送时间: {{.pushedAt}}"
|
||
}'
|
||
```
|
||
|
||
### 创建 B龙规则
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/rules' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "B龙策略",
|
||
"source_name": "trade-signal",
|
||
"event": "trade.*",
|
||
"template_name": "跟单策略",
|
||
"channels": ["safew_B龙策略"],
|
||
"conditions": [
|
||
{"field": "strategyCode", "op": "eq", "value": "BLONG"}
|
||
],
|
||
"enabled": 1
|
||
}'
|
||
```
|
||
|
||
---
|
||
|
||
## 巴菲特激进 / 稳健(trade-signal)
|
||
|
||
Source:`trade-signal`。渠道:`safew_巴菲特策略`、`safew_巴菲特策略2`、`safew_巴菲特策略3`(三个不同群;`巴菲特02/03` 与策略2/3 是同一 chat,不要重复绑)。
|
||
|
||
策略 code:激进 `PUTEJJ`、稳健 `PUTEWJ`,共用上游 `rawMessage`(激进版 / 稳健版文案已在原文里)。加仓也是「市价开多/开空」,走开仓规则。
|
||
|
||
兜底 `rule-11` 需 `strategyCode ne PUTEJJ` 且 `ne PUTEWJ`,避免再发到测试AI。
|
||
|
||
启动文案(`普达特量化机器人…启动`)不含「市价开 / 平仓 / 本周期」,三条规则都匹配不上,等于过滤。
|
||
|
||
开仓 `rawMessage` 示例:
|
||
|
||
```
|
||
激进版AI 1.0
|
||
市价开空
|
||
交易品种: BTC
|
||
开空数量: 1.00
|
||
开空价格: 63578.00
|
||
持仓数量: 1.00
|
||
平均价格: 63578.00
|
||
浮动盈亏: 0.00
|
||
账户净值: 101286.40
|
||
账户余额:101286.40
|
||
Time: 2026.08.17 14:46:04
|
||
```
|
||
|
||
### 创建模板
|
||
|
||
```bash
|
||
curl -X POST 'http://localhost:8080/api/v1/templates' \
|
||
-H 'Authorization: Bearer admin-sk-change-me' \
|
||
-H 'Content-Type: application/json' \
|
||
-d '{
|
||
"name": "巴菲特策略",
|
||
"content": "{{if .rawMessage}}{{replace .rawMessage \"Time:\" \"推送时间:\"}}{{else}}{{.formatted}}{{end}}"
|
||
}'
|
||
```
|
||
|
||
线上若尚未部署 `replace`,先用 `{{if .rawMessage}}{{.rawMessage}}{{else}}{{.formatted}}{{end}}`。
|
||
|
||
### 创建开仓 / 平仓 / 提现规则
|
||
|
||
```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": "trade-signal",
|
||
"event": "trade.*",
|
||
"template_name": "巴菲特策略",
|
||
"channels": ["safew_巴菲特策略", "safew_巴菲特策略2", "safew_巴菲特策略3"],
|
||
"conditions": [{"field": "rawMessage", "op": "contains", "value": "市价开"}],
|
||
"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": "trade-signal",
|
||
"event": "trade.*",
|
||
"template_name": "巴菲特策略",
|
||
"channels": ["safew_巴菲特策略", "safew_巴菲特策略2", "safew_巴菲特策略3"],
|
||
"conditions": [{"field": "rawMessage", "op": "contains", "value": "平仓"}],
|
||
"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": "trade-signal",
|
||
"event": "trade.*",
|
||
"template_name": "巴菲特策略",
|
||
"channels": ["safew_巴菲特策略", "safew_巴菲特策略2", "safew_巴菲特策略3"],
|
||
"conditions": [{"field": "rawMessage", "op": "contains", "value": "本周期"}],
|
||
"enabled": 1
|
||
}'
|
||
```
|