fix真盈亏只认卖光收回减买币,禁止权利金指数冒充。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -134,31 +134,44 @@ def repair(conn: sqlite3.Connection, *, apply: bool) -> list[dict[str, Any]]:
|
||||
and abs(settled_u - stats_u) / max(abs(stats_u), 1.0) <= 0.15
|
||||
)
|
||||
|
||||
if suspicious and not a_ok_near_b:
|
||||
# 负冻结且无法对上 B:解除错误冻结
|
||||
# 桥真盈亏=卖回累计−买币预算(口径 A 回退;禁止用 B 冒充 A)
|
||||
bridge_true_a = None
|
||||
if bid is not None:
|
||||
try:
|
||||
b2 = conn.execute(
|
||||
"SELECT status, budget_usdt, usdt_recovered FROM options_spot_bridge WHERE id=?",
|
||||
(int(bid),),
|
||||
).fetchone()
|
||||
if b2 and str(b2["status"] or "") == "closed":
|
||||
spent = _safe_float(b2["budget_usdt"])
|
||||
recovered = _safe_float(b2["usdt_recovered"])
|
||||
if spent is not None and recovered is not None:
|
||||
bridge_true_a = round(float(recovered) - float(spent), 4)
|
||||
except Exception:
|
||||
bridge_true_a = None
|
||||
|
||||
if before is not None and after is not None and (not settled or suspicious):
|
||||
action = "settle_from_snapshots"
|
||||
new_settled_u = round(after - before, 4)
|
||||
new_pnl_settled = 1
|
||||
elif bridge_true_a is not None and (not settled or suspicious):
|
||||
action = "settle_from_bridge_cash"
|
||||
new_settled_u = bridge_true_a
|
||||
new_pnl_settled = 1
|
||||
elif suspicious and not a_ok_near_b:
|
||||
# 负冻结且无快照/桥可重建:解除错误冻结
|
||||
action = "unsettle_bad_account_freeze"
|
||||
new_pnl_settled = 0
|
||||
new_settled_u = None
|
||||
elif (
|
||||
(not settled or suspicious)
|
||||
a_ok_near_b
|
||||
and settled_u is not None
|
||||
and settled_u > 0
|
||||
and bridge_hint == "sell_capped_at_premium"
|
||||
and coin_pnl is not None
|
||||
and coin_pnl > 0
|
||||
and stats_u is not None
|
||||
and stats_u > 0
|
||||
and (settled_u is None or settled_u < 0 or a_ok_near_b)
|
||||
):
|
||||
# 桥记录不可信时:优先保留已接近 B 的正 A,否则用口径 B 回填复盘
|
||||
if a_ok_near_b:
|
||||
action = "accept_recovered_account_A"
|
||||
new_settled_u = round(float(settled_u), 4)
|
||||
else:
|
||||
action = "backfill_A_from_stats_B"
|
||||
new_settled_u = round(float(stats_u), 4)
|
||||
new_pnl_settled = 1
|
||||
elif before is not None and after is not None and not settled:
|
||||
action = "settle_from_snapshots"
|
||||
new_settled_u = round(after - before, 4)
|
||||
# 仅当 A 已为正且接近 B 时保留,不再用 B 回填假 A
|
||||
action = "accept_recovered_account_A"
|
||||
new_settled_u = round(float(settled_u), 4)
|
||||
new_pnl_settled = 1
|
||||
|
||||
profit_rate = None
|
||||
@@ -206,8 +219,8 @@ def repair(conn: sqlite3.Connection, *, apply: bool) -> list[dict[str, Any]]:
|
||||
)
|
||||
elif action in (
|
||||
"settle_from_snapshots",
|
||||
"settle_from_bridge_cash",
|
||||
"accept_recovered_account_A",
|
||||
"backfill_A_from_stats_B",
|
||||
) and new_settled_u is not None:
|
||||
conn.execute(
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user