背景(来自 PR #113 code review · medium)
回测撮合层 flush_protective_at_close(services/paper/src/inalpha_paper/execution/exchange.py)对 perp BUY 保护单缺少 reduce-only 校验,与 live_runner 不对称。
现状
- live_runner(
live_runner.py reduce-only 豁免路径)对 BUY 保护单有方向校验:(side=="BUY" and cur_qty < 0) 才算平空、享豁免;非平仓降回普通路径。
- backtest
exchange.py 的 flush_protective_at_close:spot SELL 保护单有 can_afford_sell 守门;但 perp BUY 保护单只要满足 is_protective_order(guard- 前缀 + 保护 tag)即在 bar.close 成交,不校验是否真持空头。
问题
移除 is_protective_signature 的 side==SELL 限制后,理论上可构造带 guard- 前缀 + stop_loss tag 的 BUY 单,在回测里以 bar.close 成交(跳过"下一根撮合"约束)且无需对应空头持仓 → backtest / live 行为分叉。
实际影响低:guard 单由框架 PositionGuard 产生(不由策略源码自由构造),正常路径下 BUY 保护单必对应空头。但作为防御性一致性,backtest 侧应镜像 live 的 reduce-only 校验。
期望
flush_protective_at_close 的 BUY 分支加对称 perp reduce-only 检查(portfolio.position(inst).quantity < 0 才放行保护性 BUY),与 live_runner 同口径。
相关:PR #113、跨仓保证金 #114、历史 funding #115
背景(来自 PR #113 code review · medium)
回测撮合层
flush_protective_at_close(services/paper/src/inalpha_paper/execution/exchange.py)对 perp BUY 保护单缺少 reduce-only 校验,与 live_runner 不对称。现状
live_runner.pyreduce-only 豁免路径)对 BUY 保护单有方向校验:(side=="BUY" and cur_qty < 0)才算平空、享豁免;非平仓降回普通路径。exchange.py的flush_protective_at_close:spot SELL 保护单有can_afford_sell守门;但 perp BUY 保护单只要满足is_protective_order(guard-前缀 + 保护 tag)即在 bar.close 成交,不校验是否真持空头。问题
移除
is_protective_signature的side==SELL限制后,理论上可构造带guard-前缀 + stop_loss tag 的 BUY 单,在回测里以 bar.close 成交(跳过"下一根撮合"约束)且无需对应空头持仓 → backtest / live 行为分叉。实际影响低:guard 单由框架 PositionGuard 产生(不由策略源码自由构造),正常路径下 BUY 保护单必对应空头。但作为防御性一致性,backtest 侧应镜像 live 的 reduce-only 校验。
期望
flush_protective_at_close的 BUY 分支加对称 perp reduce-only 检查(portfolio.position(inst).quantity < 0才放行保护性 BUY),与 live_runner 同口径。相关:PR #113、跨仓保证金 #114、历史 funding #115