c021c38e2d
Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
4.4 KiB
Markdown
80 lines
4.4 KiB
Markdown
# 永续删除 / 关键位保留 — 审计报告(2026-10-07)
|
||
|
||
## 目标
|
||
|
||
- **保留**:关键位监控(`key_monitor` 页面、`/key_*` 与 `/api/key_*` 路由、`check_key_monitors()`、`lib/key_monitor/*`、相关 DB 表)。
|
||
- **删除**:永续下单/平仓、下单监控 CRUD、自动划转/强平、仅服务于永续的 lib 与模板;期权与 hub bridge 路径不受影响。
|
||
|
||
## 已删除或下线的能力
|
||
|
||
### app.py
|
||
|
||
- 移除:`check_order_monitors`、`force_close_before_reset`、`auto_transfer_once_per_day`、`reconcile_external_close(s)`、OKX 永续开平仓与 TP/SL 同步大段逻辑。
|
||
- `place_exchange_order` / `close_exchange_order` **已物理删除**(调用方与 sim 包装一并移除)。
|
||
- `background_task()` 仅调用 `check_key_monitors()`;`if __name__` 下恢复 `threading.Thread(..., daemon=True).start()`。
|
||
- `/api/price_snapshot`:`order_prices` 恒为 `[]`,不再查询 `order_monitors`。
|
||
- `render_main_page`:`order_list` 恒为 `[]`;开仓门禁改为本地 stub(`can_trade=False`)。
|
||
- 永续相关路由改为 `redirect('/options')` 或 410 JSON:`/add_order`、`/del_order`、`/order_focus`、`/api/order_*`、`/sync_positions`、`/manual_transfer` 等。
|
||
|
||
### 删除的文件(lib / templates)
|
||
|
||
| 路径 | 说明 |
|
||
|------|------|
|
||
| `lib/trade/force_close_lib.py` | 强平 UI/逻辑 |
|
||
| `lib/trade/open_trade_gate_lib.py` | 永续开仓门禁 |
|
||
| `lib/trade/daily_open_limit_lib.py` | 日开仓上限 |
|
||
| `lib/trade/order_monitor_display_lib.py` | 下单监控展示 |
|
||
| `lib/trade/manual_sltp_lib.py` | 手动 TP/SL |
|
||
| `lib/trade/position_sizing_lib.py` | 仓位 sizing |
|
||
| `lib/trade/trade_fee_lib.py` | 手续费净盈亏 |
|
||
| `lib/trade/trade_exchange_stats_lib.py` | 成交统计回填 |
|
||
| `lib/trade/trade_stats_calendar_lib.py` | 日历统计 |
|
||
| `lib/trade/compensating_close_lib.py` | 补偿平仓 |
|
||
| `lib/common/auto_transfer_daily_lib.py` | 日自动划转 |
|
||
| `lib/exchange/gate_transfer_lib.py` | Gate 划转 |
|
||
| `lib/exchange/okx_orders_lib.py` | OKX 永续挂单查询 |
|
||
| `lib/market/reconcile_flat_lib.py` | 外部平仓对账 |
|
||
| `order_monitor_*`、`force_close_*`、`instance_transfer_panel.html`、`gate_transfer_block.html` | 永续 UI 模板 |
|
||
| `order_focus_v2.html`、`order_plan_preview_bar.html`、`order_leverage_fields.html`、`order_entry_model_fields.html`、`templates/order_focus.html` | 永续下单/聚焦页残留模板 |
|
||
|
||
### 保留的 trade 模块
|
||
|
||
- `trade_policy_lib.py`、`trade_policy_app_lib.py`、`time_close_lib.py`
|
||
- `trade_labels_lib.py`、`trade_result_lib.py`(新增 `snapshot_stop_loss`)、`entry_model_lib.py`、`account_risk_lib.py`(日记/风控仍用)
|
||
|
||
## Sim / Options
|
||
|
||
- `lib/sim/hooks.py`:移除对 `place_exchange_order` / `close_exchange_order` 的包装;保留期权/现货桥/钱包 sim 路径。
|
||
- `lib/sim/register.py`:不再向 options cfg 注入永续下单函数。
|
||
|
||
## 测试
|
||
|
||
在项目根目录执行:
|
||
|
||
```text
|
||
python -m unittest tests.test_spot_dust_and_sell_cap tests.test_options_partial_close_accum tests.test_options_profit_exit_recycle tests.test_options_btc_pnl_usdt tests.test_hub_bridge_auth -v
|
||
```
|
||
|
||
**结果**:
|
||
|
||
| 批次 | 用例数 | 结果 |
|
||
|------|--------|------|
|
||
| 期权粉尘/卖回封顶、部分平仓、翻倍出场、BTC 盈亏、hub auth、去对冲冒烟 | 22 | **OK**(2026-10-07) |
|
||
|
||
`python -c "import app"` 可导入(`APP_AUTH_DISABLED=true`)。
|
||
|
||
## 残留风险与后续可选清理
|
||
|
||
1. **DB schema**:`order_monitors` 等表仍在 `init_db()` 中创建,历史数据未迁移;仅不再读写业务逻辑。
|
||
2. **模板/静态**:`index.html` 等仍可能含永续 UI 片段(无后端路由时多为死链);可按 display_prefs 再收一层 UI。
|
||
3. **统计口径**:`compute_stats_bundle` 仍可能统计历史 `order_monitors` 开仓次数;与「零 active 监控」展示一致,但不等于删表。
|
||
4. **设置页**:「transfer」子页改为说明文案;期权/模拟划转仍在各自模块。
|
||
5. **account_risk / entry_model / trade_labels**:日记与设置仍引用,未整包删除。
|
||
|
||
## 关键位验证建议(手工)
|
||
|
||
1. 添加 BTC/ETH 关键支撑阻力 → `/key_monitor` 列表可见。
|
||
2. 观察后台线程日志无 `[key_monitor_loop]` 以外永续轮询错误。
|
||
3. `/api/price_snapshot` 返回 `key_prices` 非空(有关键位时)、`order_prices: []`。
|
||
4. 微信提醒依赖环境变量与行情;需在实盘/模拟各测一次 RS 突破通知(若已配置 webhook)。
|