Files
Hermes-Skills/okx-auto-position/references/v4.5.41-xau-execute-fallback-and-user-impatience-rule.md
T

118 lines
5.0 KiB
Markdown

# v4.5.41 (2026-07-08) XAU advisor execute 静默失败 + 用户"快跟单啊"硬动作规则
## 实测事件
熬鹰连续推 8 条 XAU 多头信号 (166→291→479→527→634 张 @10x → 熬鹰后改为 @20x)。
- `process_signal.py` 推送了 QQ ✅
- `okx_position_advisor.py --symbol XAU --execute --json` 返回完整 JSON 包含 `auto_execute: true`
- **但实际未下单**: raw REST `/api/v5/account/positions` 查询无 XAU 持仓; USDT 余额不变
- 用户连发 "快跟单啊" / "我靠,这么久了还不赶紧推"
- 最终手动 raw REST POST `/api/v5/trade/order` 下单成功 (order_id: 3748482336059482112)
## 根因 (与 SPCX/1000PEPE/MU 同模式)
`okx_position_advisor.py` 的 execute 路径依赖 `ccxt.exchange.create_market_buy_order()`
该方法对 XAU/SPCX/1000PEPE/MU 等"新币种 + 小流动性 + 高单价"组合会隐性失败:
- 不抛异常
- 返回的 order 对象无 `id` 字段或被 advisor 静默忽略
- advisor 输出 JSON 含 `auto_execute: true` 但实际无 fill
**已知失效币种清单 (2026-07-08)**:
- SPCX (USDT-SWAP)
- 1000PEPE / PEPE (包装币归一化后)
- MU (USDT-SWAP)
- XAU (USDT-SWAP, 实测新增)
## 修复路径
### 1. **主流程硬动作规则 (本次用户强烈反馈)**
用户原话:
- "我靠,你为什么不重试,这么久了,还不赶紧推"
- "快跟单啊"
**规则**: 收到信号 → 30 秒内必须出现"可见动作"(跑脚本或 manual raw REST)。
如果 advisor execute 静默失败,**不允许**等待用户指示或问"要不要手动",
必须**立即**自己手动 raw REST POST `/api/v5/trade/order` 重试 (用 signal 里的方向/张数/leverage)。
失败后再 fallback 到手动,失败后再 push 错误到 QQ。**禁止**: 静默等待 / 反问用户。
### 2. **execute 反查检查 (写代码层)**
`process_signal.py` 主流程的 execute 后,加 1-3 秒延迟后用 raw REST 查 `/api/v5/account/positions`:
- 如果 signal 里币种无持仓但 advisor 返回 success → **立即推 QQ "execute 失败,需手动"**
- 如果有持仓 → 推成功 (现状)
- 已知失效币种清单 (SPCX/1000PEPE/MU/XAU) → 直接走 manual raw REST 路径,不走 ccxt
### 3. **manual raw REST execute 模板**
```python
import requests, time, hmac, hashlib, base64, json
def okx_post(p, body, t=15):
creds = open('/home/openclaw/.bashrc').read()
k=s=pw=None
for line in creds.split('\n'):
if line.startswith('export OKX_API_KEY='): k=...
if line.startswith('export OKX_SECRET='): s=...
if line.startswith('export OKX_PASSPHRASE='): pw=...
body_str = json.dumps(body)
ts = time.strftime('%Y-%m-%dT%H:%M:%S.000Z', time.gmtime())
msg = ts + 'POST' + p + body_str
sig = base64.b64encode(hmac.new(s.encode(), msg.encode(), hashlib.sha256).digest()).decode()
h = {'OK-ACCESS-KEY':k, 'OK-ACCESS-SIGN':sig, 'OK-ACCESS-TIMESTAMP':ts,
'OK-ACCESS-PASSPHRASE':pw, 'Content-Type':'application/json'}
px = {'http':'http://127.0.0.1:7890','https':'http://127.0.0.1:7890'}
return requests.post(f'https://www.okx.com{p}', data=body_str, headers=h, proxies=px, timeout=t).json()
# XAU long 15 张示例
body = {
'instId': 'XAU-USDT-SWAP', 'tdMode': 'cross', 'side': 'buy',
'posSide': 'net', 'ordType': 'market', 'sz': '15'
}
print(okx_post('/api/v5/trade/order', body))
```
### 4. **失败币种 bypass 清单 (写 process_signal.py)**
```python
SILENT_FAIL_SYMBOLS = {'SPCX', '1000PEPE', 'PEPE', 'MU', 'XAU'}
def execute_with_fallback(symbol, side, leverage, contracts):
if symbol in SILENT_FAIL_SYMBOLS:
return manual_raw_rest_order(symbol, side, leverage, contracts)
else:
return ccxt_advisor_execute(symbol, side, leverage)
```
## 与已有 reference 关系
- `references/v4.5.39-xau-silent-execute-and-raw-rest-workaround.md` — 早期 XAU 教训
- `references/spcx-silent-fail-repro.md` — SPCX 静默失败复现
- `references/v4.5.34-2026-07-08-execute-returns-success-no-fill.md` — execute 返回 success 但无 fill
- `references/v4.5.27-2026-07-08-silent-execute-failure.md` — silent execute 通用规则
本文件聚焦: **XAU 新增到失效清单 + 用户对延迟极不耐烦的硬动作规则**
## 实战结果
| 步骤 | 状态 |
|---|---|
| process_signal.py 推送 QQ | ✅ |
| okx_position_advisor --execute | ✅ 返回 JSON (auto_execute=true) |
| 实际下单 | ❌ 静默失败 (无 XAU 持仓) |
| 用户催促 | "快跟单啊" |
| manual raw REST POST | ✅ 下单 15 张成功, order_id: 3748482336059482112 |
| 反查 raw REST 持仓 | ✅ XAU long 15 张 @ 4016.6, 占用 $20.08 保证金 |
## 用户偏好 (已入 memory, 此处重复以便快速召回)
- "对延迟极度敏感": 30s 内必须有动作
- "失败后期待自动重试, 不等我问怎么办"
- 禁止反问, 禁止静默等待, 禁止"等用户拍板"
## 关联代码文件
- `scripts/process_signal.py` — 主流程, 需加 manual fallback 分支
- `scripts/okx_position_advisor.py` — ccxt 路径, XAU/SPCX/PEPE/MU 失效
- `scripts/sanitize_reply.py` — 已存在但未部署到 process_signal.py