fix卖回未完成禁止用指数提前结算,并纠正买卖VWAP回退。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -184,12 +184,16 @@ def add_bridge_close_sell_fill(
|
||||
|
||||
|
||||
def bridge_buy_vwap(conn: sqlite3.Connection, bridge_id: int | None) -> float | None:
|
||||
"""开仓买币 VWAP(USDT/币);多笔加权.忽略后续把 coin_bought 改成权利金量."""
|
||||
"""开仓买币 VWAP(USDT/币);多笔加权.
|
||||
|
||||
只用 buy_usdt_spent/buy_coin_accum.禁止 budget/coin_bought:
|
||||
开仓成功后 coin_bought 会被改成权利金量,用 budget/缩水量会把开仓价抬飞.
|
||||
"""
|
||||
if bridge_id is None:
|
||||
return None
|
||||
ensure_bridge_table(conn)
|
||||
row = conn.execute(
|
||||
"SELECT buy_usdt_spent, buy_coin_accum, budget_usdt, coin_bought FROM options_spot_bridge WHERE id=?",
|
||||
"SELECT buy_usdt_spent, buy_coin_accum FROM options_spot_bridge WHERE id=?",
|
||||
(int(bridge_id),),
|
||||
).fetchone()
|
||||
if not row:
|
||||
@@ -198,21 +202,19 @@ def bridge_buy_vwap(conn: sqlite3.Connection, bridge_id: int | None) -> float |
|
||||
coins = _safe_float(row["buy_coin_accum"] if hasattr(row, "keys") else row[1])
|
||||
if spent is not None and coins is not None and spent > 0 and coins > 0:
|
||||
return round(float(spent) / float(coins), 8)
|
||||
# 旧桥无累加字段:用预算/买入量近似单笔
|
||||
budget = _safe_float(row["budget_usdt"] if hasattr(row, "keys") else row[2])
|
||||
bought = _safe_float(row["coin_bought"] if hasattr(row, "keys") else row[3])
|
||||
if budget is not None and bought is not None and budget > 0 and bought > 0:
|
||||
return round(float(budget) / float(bought), 8)
|
||||
return None
|
||||
|
||||
|
||||
def bridge_sell_vwap(conn: sqlite3.Connection, bridge_id: int | None) -> float | None:
|
||||
"""平仓后卖回 VWAP(USDT/币);仅 close_sell_* 多笔加权,不含开仓多余卖回."""
|
||||
"""平仓后卖回 VWAP(USDT/币);仅 close_sell_* 多笔加权.
|
||||
|
||||
禁止回退 usdt_recovered/coin_sold:后者常混有开仓多余卖回,会污染卖回均价.
|
||||
"""
|
||||
if bridge_id is None:
|
||||
return None
|
||||
ensure_bridge_table(conn)
|
||||
row = conn.execute(
|
||||
"SELECT close_sell_usdt, close_sell_coin, usdt_recovered, coin_sold, status FROM options_spot_bridge WHERE id=?",
|
||||
"SELECT close_sell_usdt, close_sell_coin FROM options_spot_bridge WHERE id=?",
|
||||
(int(bridge_id),),
|
||||
).fetchone()
|
||||
if not row:
|
||||
@@ -221,13 +223,6 @@ def bridge_sell_vwap(conn: sqlite3.Connection, bridge_id: int | None) -> float |
|
||||
c = _safe_float(row["close_sell_coin"] if hasattr(row, "keys") else row[1])
|
||||
if u is not None and c is not None and u > 0 and c > 0:
|
||||
return round(float(u) / float(c), 8)
|
||||
# 旧桥无分拆字段且已关桥:用总收回/总卖出近似(可能含开仓多余卖回)
|
||||
st = str(row["status"] if hasattr(row, "keys") else row[4] or "")
|
||||
if st == BRIDGE_CLOSED:
|
||||
ru = _safe_float(row["usdt_recovered"] if hasattr(row, "keys") else row[2])
|
||||
sc = _safe_float(row["coin_sold"] if hasattr(row, "keys") else row[3])
|
||||
if ru is not None and sc is not None and ru > 0 and sc > 0:
|
||||
return round(float(ru) / float(sc), 8)
|
||||
return None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user