模拟盘统计改为现货买币/卖回的真实 USDT 净盈亏,对齐钱包。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-08 23:24:18 +08:00
parent 7943cd2167
commit bb9d14dd73
4 changed files with 312 additions and 2 deletions
+29 -2
View File
@@ -59,9 +59,21 @@ def _sell_excess_bridge_coin(
sell_amt = min(float(avail), excess_cap)
if not _spot_bridge.is_sellable_spot_coin(ex, underlying, sell_amt):
return None
return _spot_bridge.spot_market_sell_coin_to_usdt(
sell = _spot_bridge.spot_market_sell_coin_to_usdt(
ex, underlying=underlying, coin_amount=sell_amt
)
if sell and sell.get("ok"):
try:
recovered = float(sell.get("usdt_recovered") or 0)
except (TypeError, ValueError):
recovered = 0.0
if recovered > 0:
try:
_spot_bridge.add_bridge_usdt_recovered(conn, int(bridge_id), recovered)
conn.commit()
except Exception:
pass
return sell
def coin_budget_preview(cfg: dict[str, Any], ex: Any) -> dict[str, Any]:
@@ -650,12 +662,27 @@ def maybe_sell_spot_after_close(
pass
parts = inst_id.split("-")
underlying = (parts[0] if parts else "ETH").upper()
return _spot_bridge.sell_residual_after_option_flat(
result = _spot_bridge.sell_residual_after_option_flat(
cfg["get_db"],
ex,
underlying=underlying,
inst_id=inst_id,
)
# 模拟盘:卖回后按桥上真实 USDT 净额回写已实现盈亏
try:
from lib.sim.mode_lib import is_sim_mode
from lib.options.options_stats_lib import sync_sim_cash_realized_pnl_usdt
if is_sim_mode(cfg["get_db"]):
conn = cfg["get_db"]()
try:
sync_sim_cash_realized_pnl_usdt(conn, ex)
conn.commit()
finally:
conn.close()
except Exception:
pass
return result
def sweep_spot_after_options_flat(