Deduct round-trip taker fees from estimated perp PnL.

Unify hub/instance TP profit, calc_pnl, and push/accounting to net of 0.05% per side; leave exchange floating PnL unchanged.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-17 15:12:52 +08:00
parent d5e6132b13
commit 2269bc51ff
13 changed files with 307 additions and 20 deletions
+48
View File
@@ -4,6 +4,54 @@
---
## 2026-07-17 · 永续估算盈亏统一扣双边 taker 手续费
### 修改原因
中控/实例「盈利金额」、微信推送「本单盈亏」、交易记录 `pnl_amount` 使用价差毛利,未扣开平手续费,与交易所实际净盈亏及盈亏比体感偏差较大。
### 定稿口径
| 项 | 约定 |
|----|------|
| 浮盈亏 | 仍读交易所,不改 |
| 费率 | taker 单边 **0.05%**`PERP_TAKER_FEE_RATE`,默认 `0.0005`),开+平双边 |
| 净盈亏 | 毛利 − 开仓名义×费率 − 平仓名义×费率(不考虑滑点) |
| RR | 净盈利 / 原风险(风险侧加费第二步再做) |
| 历史记录 | 不回算 |
### 修改的地方
| 文件 | 改动摘要 |
|------|----------|
| `lib/trade/trade_fee_lib.py` | 新增公共扣费 / 净盈亏 |
| `lib/strategy/strategy_roll_ui_lib.py` | `reward_at_tp_usdt` → 净盈利 |
| `lib/strategy/strategy_roll_lib.py` | 同上 |
| `lib/strategy/strategy_trend_lib.py` | `calc_tp_profit_usdt` → 净盈利 |
| `lib/hub/hub_calculator_lib.py` | 滚仓预览止盈盈利 / 首仓盈利扣费;RR 跟净盈利 |
| `crypto_monitor_okx/app.py` | `calc_pnl` → 净盈亏(推送/记账) |
| `crypto_monitor_gate/app.py` | 同上 |
| `crypto_monitor_binance/app.py` | `calc_pnl` / 成交回退扣费;income 真费路径优先不改 |
| `tests/test_trade_fee_lib.py` | 新增 |
| `tests/test_strategy_roll_ui_lib.py` | 断言改净额 |
| `tests/test_order_monitor_display_lib.py` | 断言改净额 |
### 达成的目标
1. 中控持仓「盈利金额」、实例「盈利金额」、计算器止盈盈利、趋势/滚仓预览一致为净盈亏。
2. 微信推送与新建交易记录的 `pnl_amount` 与上述估算口径一致。
3. 币安若能拉到 income 净额(已含真实手续费)仍优先用交易所数。
4. 浮盈亏展示仍跟交易所。
### 交付之后的验收
1. 同一笔持仓:中控盈利金额 ≈ 实例盈利金额(均为扣费后)。
2. 平仓推送「本单盈亏」与新写入记录接近,不再明显大于交易所净利。
3. 浮盈亏与交易所 App 一致(本改不动)。
4. 单测:`python -m unittest tests.test_trade_fee_lib tests.test_strategy_roll_ui_lib tests.test_order_monitor_display_lib tests.test_trend_preview_tp -v` 通过。
---
## 2026-07-16 · 计算器左侧 Tab + 三行输入
### 修改原因