fix真盈亏只认历史币盈亏不再另扣费,刷新按固定量价重算;修模拟到期币盈亏。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-13 11:30:07 +08:00
parent aa8b16ce27
commit dd979d9dd0
7 changed files with 278 additions and 128 deletions
+4 -3
View File
@@ -6,8 +6,8 @@ import unittest
class ReviewLocalSyncFreezeTests(unittest.TestCase):
def test_settled_true_pnl_not_rewritten_on_resync(self):
"""已冻结真盈亏只读;同步不得因桥/指数再改写."""
def test_refresh_recomputes_u_keeps_frozen_qty_px(self):
"""刷新按公式重算U;权利金币/币盈亏/开仓卖回价不变."""
from lib.options.options_db import init_options_tables
from lib.options.options_review_lib import sync_options_from_local_trades
from lib.sim.mode_lib import MODE_SIM, TRADING_MODE_KEY
@@ -29,7 +29,7 @@ class ReviewLocalSyncFreezeTests(unittest.TestCase):
) VALUES (
'BTC-USD-261008-86500-P', 'BTC', 'P', 1, 0.01,
0.01, 0.02, 0.01, 'BTC',
0, 0, 'closed', 700.0,
0, 0, 'closed', -51.0,
90000.0, 80000.0, 1,
'2026-10-05 05:11:30', '2026-10-07 10:03:53'
)
@@ -41,6 +41,7 @@ class ReviewLocalSyncFreezeTests(unittest.TestCase):
trade = conn.execute(
"SELECT realized_pnl_usdt, open_index_px, close_index_px, pnl_settled, realized_pnl, premium_paid FROM options_trades WHERE id=1"
).fetchone()
# 0.01*80000 - 0.01*(90000-80000)=700;旧错账 -51 被刷新纠正
self.assertAlmostEqual(float(trade["realized_pnl_usdt"]), 700.0, places=2)
self.assertAlmostEqual(float(trade["open_index_px"]), 90000.0, places=2)
self.assertAlmostEqual(float(trade["close_index_px"]), 80000.0, places=2)