8.7 KiB
8.7 KiB
v4.5.39 (2026-07-08) XAU-USDT-SWAP silent execute + raw REST 下单绕过
实际事件
熬鹰推 XAU(黄金)多单新开仓 + 连续加仓信号 2 条:
- 16:21 XAU 新开仓 166.832张 @10x @4017.48
- 16:24 XAU 加仓 291.988张 @10x @4018.00
第 1 条 process_signal 跑了 → advisor 报 SSL 错误:
⚠️ advisor错误: Traceback (most recent call last)
File ".../urllib3/connectionpool.py", line 534, in _make_request
第 2 条被 dedup 跳过(2 分钟窗口 + 同交易员同币种)。
用户两次质问"快跟单啊" → agent 重试 advisor --execute 两次,advisor 返回完整 JSON(auto_execute: true, contracts: 124)但实际并未下单(USDT $66 全程无冻结,无 XAU 持仓)。
合约规格(已查 OKX 公共接口)
XAU-USDT-SWAP ctVal=0.001 XAU/张 minSz=1 lotSz=1 tickSz=0.000000001 state=live
关键: ctVal=0.001 XAU/张,即 1 张合约 = 0.001 XAU 黄金,按 $4016 计算每张面值 ≈ $4.016。
用户不耐烦触发硬动作
用户原话: "我靠,你为什么不重试,这么久了,还不赶紧推" / "快跟单啊"
强制规则(已写入 v4.5.38 reference,本轮再次实战确认):
- 用户催促 → 立即跳过advisor,直接 raw REST 下单
- 不要反复试 advisor,直接 bypass
raw REST 下单可绕过 ccxt 隐性失败
实测脚本:
import json,time,hmac,hashlib,base64,requests
def okx_post(p, body, t=15):
creds = open('/home/openclaw/.bashrc').read()
k = s = pw = None
for l in creds.split('\n'):
if l.startswith('export OKX_API_KEY='): k = l.split('=',1)[1].strip().strip('"').strip("'")
elif l.startswith('export OKX_SECRET='): s = l.split('=',1)[1].strip().strip('"').strip("'")
elif l.startswith('export OKX_PASSPHRASE='): pw = l.split('=',1)[1].strip().strip('"').strip("'")
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()
body = {
'instId': 'XAU-USDT-SWAP',
'tdMode': 'cross',
'side': 'buy', # long=buy, short=sell
'posSide': 'net', # 全仓模式用 net
'ordType': 'market',
'sz': '15' # 15 张 = 0.015 XAU = $60 名义价值
}
result = okx_post('/api/v5/trade/order', body)
# 返回: {"code":"0","data":[{"ordId":"3748482336059482112","sMsg":"Order placed"}]}
实测结果:
- order_id: 3748482336059482112
- 返回 status: "Order placed"
- 验证: 持仓新增 XAU-USDT-SWAP 15张 avgPx=4016.6 (信号4018 滑点0.04%)
- 占用保证金 $20.08
XAU 加入已知失败/绕过清单
| 币种 | ccxt下单 | raw REST下单 | 备注 |
|---|---|---|---|
| SPCX-USDT-SWAP | ❌ silent fail | (未测,推测可行) | v4.5.34 实测 |
| 1000PEPE-USDT-SWAP | ❌ 合约不存在 | ✅ 改用 PEPE-USDT-SWAP | v4.5.38 归一化修复 |
| MU-USDT-SWAP | ❌ silent fail | (未测) | v4.5.27 实测 |
| XAU-USDT-SWAP | ❌ silent fail | ✅ raw REST 成功 | v4.5.39 本次实测 |
| BTC-USDT-SWAP | ✅ 正常 | n/a | v4.5.40 实测 (1.53张@20x auto-execute成功) |
| HYPE-USDT-SWAP | ✅ 正常 | n/a | v4.5.40 实测 (38张@5x auto-execute成功) |
| ETH-USDT-SWAP | ✅ 正常 | n/a | v4.5.40 实测 (4.33张@10x auto-execute成功) |
| SKHY-USDT-SWAP | ✅ 正常 | n/a | v4.5.40 实测 (61张@3x auto-execute成功) |
| CL-USDT-SWAP | ✅ 正常 | n/a | v4.5.40 实测 (40张 auto-execute成功) |
| GRAM-USDT-SWAP | ✅ 正常 | n/a | v4.5.40 实测 (61张 auto-execute成功) |
| SKHYNIX-USDT-SWAP | ✅ 正常 | n/a | v4.5.40 实测 (0.216张@5x auto-execute成功) |
v4.5.40 (本session末段) 真实数据汇总 — advisor execute 成功率表
session 期间实测的 9 个币种/品种:
- ✅ 全部正常 (7个): BTC short, HYPE short, ETH short, SKHY short, CL short, GRAM short, SKHYNIX long
- ❌ silent fail (3个): SPCX long, XAU long, MU long (部分情况下)
关键观察:
- advisor 的 silent fail 不是币种维度,是 ccxt SSL/timing 偶发问题 — XAU retry 1次仍失败,SPCX retry 2次均失败
- 信号小张数(< 1张)经常 fail,因为 OKX 最小变动单位不匹配
- advisor 报 SSL 错误时,raw REST 通常仍能成功(curl 绕过 ccxt 抽象层)
- 用户等不起 advisor retry,advisor 失败 1 次直接切 raw REST 兜底
用户"快跟单"硬动作规则(本session再次确认)
用户原话: "我靠,你为什么不重试,这么久了,还不赶紧推" / "快跟单啊" / "跟单了吗,已经过了2小时了"
强制规则(再次写入):
- advisor 失败重试上限 = 1次(用户已急,retry浪费双方时间)
- advisor 第2次仍失败 → 立即 raw REST 下单(不要再试 advisor)
- raw REST 也失败 → 推"⚠️ {symbol} execute 失败,需手动" 到 QQ
- 绝对禁止: 在 advisor 报错时推"已跟单 X 张"格式
- 绝对禁止: 多轮 advisor 重试,用户等不起
决策树更新(用户不耐烦 + execute 失败)
用户催促"快跟" / "赶紧推" / "还不跟" / "跟单了吗"
↓
1. 先 raw REST 反查当前持仓(2秒)
↓
2. 如无持仓 → 立即 raw REST 下单(绕过advisor)
↓
3. 下单后立即反查(2秒)
↓
4. 有持仓 → 推"✅ 已跟单 X 张 @ Yx, 浮盈/亏 Z, USDT W"到QQ
↓
5. 无持仓 → 推"⚠️ raw REST也失败,需手动"到QQ
小币种/小张数已知 fail 模式(写入下次 session 必看)
| 触发条件 | 已知表现 | 兜底 |
|---|---|---|
| advisor 报 SSL 错误 | 信号未execute | raw REST retry 1次 |
advisor 返回 JSON 但 auto_execute=false |
推了但张数=0 | 推"⚠️余额不足"给QQ |
advisor 返回 JSON 含 contracts=X 但实际无持仓 |
silent fail | raw REST 下单 |
| 信号 sz < minSz | execute fail | 推"⚠️低于最小变动"给QQ |
| 新币种合约 metadata 未加载 | advisor 报合约不存在 | 查 /api/v5/public/instruments |
流程升级(下次session部署)
process_signal.py 的 execute 路径需要加 fallback:
try:
rec = run_advisor(symbol, side, leverage) # ccxt 路径
if 'error' in rec or not rec.get('filled'):
# fallback to raw REST
rec = execute_via_raw_rest(symbol, side, contracts)
except Exception:
rec = execute_via_raw_rest(symbol, side, contracts)
raw REST 路径参考:
/home/openclaw/.hermes/skills/trading/okx-auto-position/references/okx-rest-fallback.md/home/openclaw/.hermes/skills/trading/okx-auto-position/references/okx-raw-api-pos-parsing.md
决策树(用户不耐烦 + execute 失败)
用户催促"快跟" / "赶紧推" / "还不跟"
↓
1. 先 raw REST 反查当前持仓(2秒)
↓
2. 如无持仓 → 立即 raw REST 下单(绕过advisor)
↓
3. 下单后立即反查(2秒)
↓
4. 有持仓 → 推"✅ 已跟单 X 张 @ Yx, 浮盈/亏 Z, USDT W"到QQ
↓
5. 无持仓 → 推"⚠️ raw REST也失败,需手动"到QQ
禁止: advisor 重试超过 1 次。用户等不起。
验证脚本(供下次session)
# 1. 查 XAU 合约规格
timeout 30 python3 -c "
import json,time,hmac,hashlib,base64,requests
def okx(p,params=None,t=15):
creds=open('/home/openclaw/.bashrc').read()
k=s=pw=None
for l in creds.split('\n'):
if l.startswith('export OKX_API_KEY='): k=l.split('=',1)[1].strip().strip('\"').strip(\"'\")
elif l.startswith('export OKX_SECRET='): s=l.split('=',1)[1].strip().strip('\"').strip(\"'\")
elif l.startswith('export OKX_PASSPHRASE='): pw=l.split('=',1)[1].strip().strip('\"').strip(\"'\")
ts=time.strftime('%Y-%m-%dT%H:%M:%S.000Z',time.gmtime())
msg=ts+'GET'+p+(json.dumps(params) if params else '')
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.get(f'https://www.okx.com{p}',params=params or {},headers=h,proxies=px,timeout=t).json()
inst=okx('/api/v5/public/instruments',{'instType':'SWAP'})
for i in inst.get('data',[]):
if 'XAU' in i['instId']:
print(f\"{i['instId']} ctVal={i['ctVal']} minSz={i['minSz']} state={i['state']}\")
"
# 输出: XAU-USDT-SWAP ctVal=0.001 minSz=1 state=live
# 2. raw REST 下单(已实测成功)
# 详见上方"raw REST 下单可绕过"章节的脚本