fix卖回VWAP必须落库并覆盖指数占位价,禁止预算反推开仓价。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+13
-2
@@ -421,7 +421,11 @@ def _patch_spot_bridge_lib() -> None:
|
||||
if not is_sellable_spot_coin(ex, coin, amt):
|
||||
min_sz = spot_min_sell_sz(ex, coin)
|
||||
return {"ok": False, "msg": f"{coin} 可卖数量过小(低于现货最小 {min_sz:g})"}
|
||||
sell_sz = max(0.0, float(amt) * 0.999)
|
||||
# 平仓卖回(coin_amount=None)一次卖光;限量卖才留粉尘余量
|
||||
if coin_amount is None:
|
||||
sell_sz = float(amt)
|
||||
else:
|
||||
sell_sz = max(0.0, float(amt) * 0.999)
|
||||
if sell_sz <= 0 or not is_sellable_spot_coin(ex, coin, sell_sz):
|
||||
return {"ok": False, "msg": f"{coin} 可卖数量过小"}
|
||||
pub = _sim_public_exchange(ex)
|
||||
@@ -445,13 +449,20 @@ def _patch_spot_bridge_lib() -> None:
|
||||
notify_instance_balance_changed()
|
||||
except Exception:
|
||||
pass
|
||||
recovered = result.get("usdt_recovered")
|
||||
if recovered is None and result.get("fill_px") is not None:
|
||||
try:
|
||||
recovered = round(float(sell_sz) * float(result.get("fill_px")), 8)
|
||||
except (TypeError, ValueError):
|
||||
recovered = None
|
||||
return {
|
||||
"ok": True,
|
||||
"inst_id": result.get("inst_id") or "",
|
||||
"ord_id": f"sim-spot-sell-{result.get('fill_px') or 0}",
|
||||
"coin_sold": float(sell_sz),
|
||||
"fill_px": result.get("fill_px"),
|
||||
"sim": True,
|
||||
"usdt_recovered": result.get("usdt_recovered"),
|
||||
"usdt_recovered": recovered,
|
||||
"data": {"sCode": "0", "sMsg": "sim filled"},
|
||||
}
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user