feat(order): show estimated RR before open across four exchanges

Add shared manual_order_rr_preview.js to fetch order_defaults after symbol and TP/SL inputs complete, display estimated profit-loss ratio before submit in price and percentage modes (and fixed RR), unified for risk and full-margin sizing.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-16 16:19:32 +08:00
parent 869728ce10
commit f9257b64e4
7 changed files with 326 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
# 实盘下单 · 预估盈亏比
## 功能
四所(Binance / OKX / Gate / Gate趋势)**实盘下单监控**表单中,在「开仓」按钮前显示 **预估盈亏比**
- **价格模式**:填完币种、方向、止损价、止盈价后,调用 `GET /api/order_defaults` 取标记价,按几何距离计算 RR。
- **百分比模式**:填完币种、方向、止损%、止盈% 后拉快照校验币种,再显示 RR(`止盈% / 止损%`)。
- **固定盈亏比模式**:填完币种、方向、止损价、盈亏比后取价校验几何合法,展示填写的盈亏比。
与计仓方式无关:**以损定仓**`POSITION_SIZING_MODE=risk`)与 **全仓杠杆**`full_margin`)均显示同一预估。
## 前端实现
- 共享脚本:`static/manual_order_rr_preview.js`
- 各所 `templates/index.html` 引入并在 `MANUAL_MIN_PLANNED_RR` 定义后执行:
```js
ManualOrderRrPreview.wire({ minRr: MANUAL_MIN_PLANNED_RR });
```
- 展示元素:`#order-rr-preview`(开仓按钮左侧)
- 颜色:≥ 最低要求为绿色,低于为红色,无效/取价失败为红色或灰色
## 与提交校验
提交时仍走原有 `calcClientRr` / `calcClientRrFromPct` 与 `rejectManualOrderRr`;预估仅用于下单前参考,不替代服务端风控。
## 校验记录
- `node --check static/manual_order_rr_preview.js`
- `tests/test_manual_order_rr_preview.py`RR 公式与四所 `calc_rr_ratio` 口径一致