fix卖回未完成禁止用指数提前结算,并纠正买卖VWAP回退。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -76,6 +76,7 @@ class SpotVwapBridgeTests(unittest.TestCase):
|
||||
def test_pending_sell_blocks_true_pnl(self):
|
||||
from lib.options.options_pnl_settle_lib import resolve_true_pnl_usdt_from_trade
|
||||
from lib.options.options_spot_bridge_lib import (
|
||||
BRIDGE_HOLDING,
|
||||
BRIDGE_PENDING_SELL,
|
||||
add_bridge_buy_fill,
|
||||
add_bridge_close_sell_fill,
|
||||
@@ -103,6 +104,39 @@ class SpotVwapBridgeTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(src, "pending_sell")
|
||||
self.assertIsNone(pnl)
|
||||
# holding 未关桥同样不得用指数提前结算
|
||||
update_bridge(conn, bid, status=BRIDGE_HOLDING)
|
||||
pnl2, src2 = resolve_true_pnl_usdt_from_trade(
|
||||
premium_paid=0.01,
|
||||
premium_received=0.02,
|
||||
realized_pnl=0.01,
|
||||
open_index_px=3000.0,
|
||||
close_index_px=3000.0,
|
||||
premium_ccy="ETH",
|
||||
conn=conn,
|
||||
bridge_id=bid,
|
||||
)
|
||||
self.assertEqual(src2, "pending_sell")
|
||||
self.assertIsNone(pnl2)
|
||||
conn.close()
|
||||
|
||||
def test_buy_vwap_ignores_shrunk_coin_bought(self):
|
||||
"""开仓后 coin_bought 被改成权利金量时,不得用 budget/缩水量当买价."""
|
||||
from lib.options.options_spot_bridge_lib import (
|
||||
add_bridge_buy_fill,
|
||||
bridge_buy_vwap,
|
||||
ensure_bridge_table,
|
||||
insert_bridge,
|
||||
update_bridge,
|
||||
)
|
||||
|
||||
conn = sqlite3.connect(":memory:")
|
||||
conn.row_factory = sqlite3.Row
|
||||
ensure_bridge_table(conn)
|
||||
bid = insert_bridge(conn, underlying="BTC", status="holding", budget_usdt=2200)
|
||||
add_bridge_buy_fill(conn, bid, usdt_spent=2200.0, coin_bought=1.1)
|
||||
update_bridge(conn, bid, coin_bought=0.01) # 缩成权利金
|
||||
self.assertAlmostEqual(float(bridge_buy_vwap(conn, bid)), 2000.0, places=4)
|
||||
conn.close()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user