Fix post-close auto sell: restore missing spot min-size helpers used by sim sell.
Sell was silently failing on ImportError; surface sell result in close alert notes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -177,6 +177,50 @@ def fetch_trading_coin_available(ex: Any, ccy: str) -> float | None:
|
||||
return None
|
||||
|
||||
|
||||
def spot_min_sell_sz(ex: Any, ccy: str) -> float:
|
||||
"""OKX 现货最小卖出量(base ccy);读不到则用保守默认."""
|
||||
ccy_u = (ccy or "").strip().upper()
|
||||
defaults = {"BTC": 1e-5, "ETH": 1e-4}
|
||||
default = float(defaults.get(ccy_u, 1e-4))
|
||||
inst_id = spot_quote_inst_id(ccy_u)
|
||||
if not inst_id:
|
||||
return default
|
||||
try:
|
||||
if ex is not None and hasattr(ex, "public_get_public_instruments"):
|
||||
resp = ex.public_get_public_instruments({"instType": "SPOT", "instId": inst_id})
|
||||
data = (resp or {}).get("data") or []
|
||||
if data:
|
||||
raw = data[0].get("minSz")
|
||||
if raw is not None and str(raw).strip() != "":
|
||||
return float(raw)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if ex is not None and hasattr(ex, "market"):
|
||||
m = ex.market(inst_id.replace("-", "/"))
|
||||
lim = (m or {}).get("limits") or {}
|
||||
amt = (lim.get("amount") or {}).get("min")
|
||||
if amt is not None:
|
||||
return float(amt)
|
||||
except Exception:
|
||||
pass
|
||||
return default
|
||||
|
||||
|
||||
def is_sellable_spot_coin(ex: Any, ccy: str, amount: float) -> bool:
|
||||
"""数量是否达到现货最小卖出门槛."""
|
||||
try:
|
||||
amt = float(amount or 0)
|
||||
except (TypeError, ValueError):
|
||||
return False
|
||||
if amt <= 0:
|
||||
return False
|
||||
try:
|
||||
return amt + 1e-15 >= float(spot_min_sell_sz(ex, ccy))
|
||||
except Exception:
|
||||
return amt > 0
|
||||
|
||||
|
||||
def spot_market_buy_coin_with_usdt(
|
||||
ex: Any,
|
||||
*,
|
||||
|
||||
Reference in New Issue
Block a user