fix期权复盘与数据统计双口径盈亏,并修复卖回封顶导致盈利单冻成亏损。

平仓卖光可卖币后再按账户差分结算复盘;数据统计改为历史币盈亏×卖回价;复盘展示初始权利金与盈利率,并附历史修复脚本。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-13 09:10:13 +08:00
parent d4de6a23ae
commit 9d77a430e5
16 changed files with 2858 additions and 2242 deletions
+10
View File
@@ -28,12 +28,22 @@ class TestSpotDust(unittest.TestCase):
class TestSellCapLogic(unittest.TestCase):
def test_excess_cap_math(self):
"""开仓清过量仍按 coin_bought 封顶;平仓卖回不再用权利金封顶."""
bought, keep = 0.01, 0.004
excess = max(0.0, bought - keep)
self.assertAlmostEqual(excess, 0.006)
sell_amt = min(0.02, excess)
self.assertAlmostEqual(sell_amt, 0.006)
def test_flat_sell_does_not_use_premium_cap(self):
import inspect
from lib.options import options_spot_bridge_lib as m
src = inspect.getsource(m.sell_residual_after_option_flat)
self.assertIn("coin_amount=None", src)
self.assertNotIn("sell_cap if", src)
class TestMaybeSellAfterCloseGuard(unittest.TestCase):
"""平仓后卖回:持仓查询失败/空响应绝不卖币."""