npm run diagnose:delta
这会输出:
每个交易周期都应该有:
📊 Delta Assessment {
symbol: 'BTC',
totalPositionBTC: '0.00150', # 当前净敞口
positionValueUSDC: '150.00',
weightedDelta: '0.0075%', # 加权 Delta
currentTolerance: '0.5000%', # 当前容忍度
exceedsTolerance: '✅ NO', # 是否超限
recommendation: 'hold' # 建议操作
}
当 Delta 超限时应该看到:
⚖️ Delta exceeds tolerance, generating rebalance signal {
totalPositionBTC: 0.00150,
deltaAssessment: 'adjust',
balanceAmount: 0.00075,
balanceSide: 'ask'
}
对冲执行:
Executing signal {
type: 'balance',
accountId: 'account1',
symbol: 'BTC',
side: 'ask',
amount: 0.00075
}
Signal executed successfully {
orderId: '12345',
clientOrderId: 'uuid-...'
}
窗口1 - 运行策略:
npm run trade
窗口2 - 监控 Delta:
tail -f logs/strategy.log | grep "Delta Assessment"
窗口3 - 监控对冲:
tail -f logs/strategy.log | grep -E "exceeds tolerance|Hedging signal|Executing signal"
窗口4 - 监控错误:
tail -f logs/strategy.log | grep -E "error|failed|ERROR"
{
"deltaRebalancing": {
"enabled": true, # ← 必须启用
"checkInterval": 60,
"rebalanceThreshold": 0.05, # ← 当前 5%,建议降到 0.01
"maxDeltaDeviation": 0.001
}
}
{
"deltaControl": {
"baseDeltaTolerance": 0.005, # ← 当前 0.5%,建议降到 0.001
"stableDeltaTolerance": 0.005,
"volatileDeltaTolerance": 0.02
}
}
修复1:降低阈值(使用绝对值)
编辑 src/strategies/SimpleStrategyEngine.ts:326-362
:
// 当前逻辑(基于百分比)
if (deltaAssessment.exceedsTolerance) {
// ...
}
// 改为绝对值阈值(推荐)
const ABSOLUTE_THRESHOLD_BTC = 0.0001; // 0.0001 BTC ≈ $10
if (Math.abs(totalPositionBTC) > ABSOLUTE_THRESHOLD_BTC) {
const balanceAmount = Math.abs(totalPositionBTC); // 全部对冲
// ... 生成对冲信号
}
修复2:更新配置
# 编辑 config/trading-strategy.json
{
"deltaRebalancing": {
"rebalanceThreshold": 0.01, # 从 5% 改为 1%
"maxDeltaDeviation": 0.0005 # 从 0.1% 改为 0.05%
}
}
检查步骤:
exceedsTolerance: YES
出现在日志中rebalanceThreshold
这是正常的! 表示账户无持仓可减。
SignalExecutor 已自动处理,跳过重试:
⚠️ Reduce-only order failed: position not found (skip retry)
修复:提高波动容忍度
{
"deltaControl": {
"volatileDeltaTolerance": 0.03, # 从 2% 提高到 3%
"volatilityThreshold": 0.015 # 从 1% 提高到 1.5%
}
}
运行策略并观察:
初始状态:
totalPositionBTC: 0.00150 # 有敞口
exceedsTolerance: ⚠️ YES
触发对冲:
⚖️ Delta exceeds tolerance, generating rebalance signal
Executing signal { type: 'balance', side: 'ask', amount: 0.00075 }
Signal executed successfully { orderId: '12345' }
对冲后:
totalPositionBTC: 0.00075 # 敞口减少
exceedsTolerance: ✅ NO
最终:
totalPositionBTC: <0.0001 # 接近零
编辑 src/strategies/SimpleStrategyEngine.ts:326
:
// 在 checkDeltaRebalance 方法中
// 替换原有的百分比检查
const ABSOLUTE_THRESHOLD_BTC = 0.0001; // 约 $10 USDC
if (Math.abs(totalPositionBTC) > ABSOLUTE_THRESHOLD_BTC) {
const balanceAmount = Math.abs(totalPositionBTC);
// ... 生成 100% 对冲信号
}
config/trading-strategy.json:
{
"deltaRebalancing": {
"enabled": true,
"checkInterval": 30,
"rebalanceThreshold": 0.01, # 1%(作为后备)
"maxDeltaDeviation": 0.0005 # 0.05%
},
"intervals": {
"volumeTrading": 3,
"deltaMonitoring": 30
}
}
config/delta-strategy-config.json:
{
"deltaControl": {
"baseDeltaTolerance": 0.001, # 0.1%(严格)
"stableDeltaTolerance": 0.001,
"volatileDeltaTolerance": 0.02,
"predictiveDelta": true
}
}
npm run build
npm run trade
✅ 已完成的优化:
npm run diagnose:delta
📋 下一步行动:
npm run diagnose:delta
检查当前状态🔍 关键指标:
totalPositionBTC
应该 < 0.0001 BTCexceedsTolerance
超限时应生成对冲信号