修复 BTC 币本位期权净盈亏被 round4 抹成 0 的精度问题。

币本位权利金/回收/盈亏改用 8 位小数,避免小额 BTC 报价显示为 0。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-02 14:45:54 +08:00
parent c1f783df9b
commit 34322d1731
5 changed files with 59 additions and 15 deletions
+21 -7
View File
@@ -11,9 +11,11 @@ from lib.options.options_close_gate_lib import (
update_close_gate,
)
from lib.options.options_pricing_lib import (
PREMIUM_DECIMALS_COIN,
estimate_close_by_bids,
fetch_option_mark_px,
is_stub_bid_px,
round_premium_amount,
total_premium,
)
@@ -307,7 +309,9 @@ def close_option_by_bid1(
px = float(order.get("px", locked_bid_px))
oid = str((order.get("data") or {}).get("ordId") or "")
# 本批预估收回(按挂单张数);成交后按实际减仓张数重算并入累计
prem_recv_submit = round(total_premium(px, level_sheets * ct_mult), 4)
prem_recv_submit = round_premium_amount(
total_premium(px, level_sheets * ct_mult), decimals=PREMIUM_DECIMALS_COIN
)
time.sleep(0.6)
invalidate_option_positions_cache()
raw2 = cfg["fetch_option_positions"](ex)
@@ -331,7 +335,9 @@ def close_option_by_bid1(
if fully_closed and filled_sheets < 1:
filled_sheets = level_sheets
batch_recv = (
round(total_premium(px, filled_sheets * ct_mult), 4) if filled_sheets > 0 else 0.0
round_premium_amount(total_premium(px, filled_sheets * ct_mult), decimals=PREMIUM_DECIMALS_COIN)
if filled_sheets > 0
else 0.0
)
total_recv = batch_recv
@@ -360,7 +366,9 @@ def close_option_by_bid1(
ord_id=oid or None,
)
accum = get_open_close_accum(conn, inst_id)
total_recv = round(float(accum.get("recv") or 0), 4)
total_recv = round_premium_amount(
float(accum.get("recv") or 0), decimals=PREMIUM_DECIMALS_COIN
) or 0.0
accum_sheets = int(accum.get("sheets") or 0)
accum_notional = float(accum.get("notional") or 0)
if accum_sheets > 0 and accum_notional > 0:
@@ -380,14 +388,20 @@ def close_option_by_bid1(
for i, row in enumerate(open_rows):
paid = float(row["premium_paid"] or 0)
if i == len(open_rows) - 1:
recv = round(total_recv - allocated, 4)
recv = round_premium_amount(
total_recv - allocated, decimals=PREMIUM_DECIMALS_COIN
) or 0.0
elif total_paid > 0:
recv = round(total_recv * (paid / total_paid), 4)
recv = round_premium_amount(
total_recv * (paid / total_paid), decimals=PREMIUM_DECIMALS_COIN
) or 0.0
allocated += recv
else:
recv = round(total_recv / len(open_rows), 4)
recv = round_premium_amount(
total_recv / len(open_rows), decimals=PREMIUM_DECIMALS_COIN
) or 0.0
allocated += recv
pnl = round(recv - paid, 4)
pnl = round_premium_amount(recv - paid, decimals=PREMIUM_DECIMALS_COIN) or 0.0
note_sql = ""
from lib.options.options_time_lib import options_app_now_str