Show residual bid as price/size and recovery percent from bid premium.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -909,7 +909,7 @@ class Matcher:
|
||||
return (None, close_bid, oq)
|
||||
|
||||
def list_residual_options_enriched(self) -> list[dict[str, Any]]:
|
||||
"""pending 残留 + 买一权利金/回收占比/流动性是否可手动平。"""
|
||||
"""pending 残留 + 买一价/量、买一权利金、回收占比、流动性是否可手动平。"""
|
||||
out: list[dict[str, Any]] = []
|
||||
for row in self.list_residual_options(pending_only=True):
|
||||
d = dict(row)
|
||||
@@ -918,6 +918,17 @@ class Matcher:
|
||||
init = float(d.get("initial_premium") or 0)
|
||||
oq = self._quote_held_option(option_inst_id) if option_inst_id else None
|
||||
bid = float(oq.bid) if oq is not None and oq.bid is not None else None
|
||||
bid_sz = None
|
||||
bid_sz_eth = None
|
||||
if oq is not None and getattr(oq, "bid_sz", None) is not None:
|
||||
try:
|
||||
bid_sz = float(oq.bid_sz)
|
||||
except (TypeError, ValueError):
|
||||
bid_sz = None
|
||||
if bid_sz is not None and bid_sz >= 0:
|
||||
ct = self._ct_mult(option_inst_id) if option_inst_id else 0.01
|
||||
bid_sz_eth = eth_from_contracts(bid_sz, ct)
|
||||
# 权利金 = 最新买一价 × 持仓数量;占比 = 买一权利金 / 开仓权利金
|
||||
cur = float(bid) * opt_qty if bid is not None else None
|
||||
ratio = (cur / init * 100.0) if cur is not None and init > 1e-12 else None
|
||||
liq_detail: str | None
|
||||
@@ -930,6 +941,8 @@ class Matcher:
|
||||
d.update(
|
||||
{
|
||||
"bid_px": bid,
|
||||
"bid_sz": bid_sz,
|
||||
"bid_sz_eth": bid_sz_eth,
|
||||
"current_premium": cur,
|
||||
"recovery_pct": ratio,
|
||||
"liquidity_ok": liq_detail is None,
|
||||
|
||||
@@ -206,7 +206,11 @@ def test_manual_close_skips_premium_ratio(tmp_path, monkeypatch) -> None:
|
||||
enriched = m.list_residual_options_enriched()
|
||||
assert len(enriched) == 1
|
||||
assert enriched[0]["liquidity_ok"] is True
|
||||
assert enriched[0]["recovery_pct"] is not None
|
||||
assert enriched[0]["bid_px"] == 5.0
|
||||
assert enriched[0]["bid_sz"] == 10_000.0
|
||||
assert abs(float(enriched[0]["bid_sz_eth"]) - 100.0) < 1e-9 # 10000*0.01
|
||||
assert abs(float(enriched[0]["current_premium"]) - 10.0) < 1e-9 # 5*2
|
||||
assert abs(float(enriched[0]["recovery_pct"]) - 10.0) < 1e-9 # 10/100*100
|
||||
assert float(enriched[0]["recovery_pct"]) < 20.0
|
||||
|
||||
r = m.close_residual_manual("G-res")
|
||||
|
||||
Reference in New Issue
Block a user