Fold chain/account/PnL hints into rules; hide dust sell-coin.
Move the three noisy help lines into 规则说明, and show 手动卖回币 only when trading-coin balance meets the exchange min size. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1281,10 +1281,47 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
pass
|
||||
return jsonify(result)
|
||||
|
||||
@app.route("/api/hedge-plan/sell-coin-status")
|
||||
@lr
|
||||
def api_hedge_sell_coin_status():
|
||||
"""是否显示「手动卖回币」:交易户有币且 ≥ 现货最小卖出量(粉尘隐藏)."""
|
||||
if not _hedge_enabled():
|
||||
return jsonify({"ok": False, "sellable": False, "msg": "对冲模块未启用"})
|
||||
ex = cfg.get("exchange_options") or cfg.get("exchange")
|
||||
if ex is None:
|
||||
return jsonify({"ok": False, "sellable": False, "msg": "交易所未配置"})
|
||||
underlying = str(
|
||||
request.args.get("underlying") or cfg.get("default_underly") or "ETH"
|
||||
).strip().upper()
|
||||
if underlying not in ("ETH", "BTC"):
|
||||
return jsonify({"ok": False, "sellable": False, "msg": "标的仅支持 ETH/BTC"})
|
||||
from lib.options.options_spot_bridge_lib import (
|
||||
fetch_trading_coin_available,
|
||||
is_sellable_spot_coin,
|
||||
spot_min_sell_sz,
|
||||
)
|
||||
|
||||
avail = fetch_trading_coin_available(ex, underlying)
|
||||
try:
|
||||
avail_f = float(avail) if avail is not None else 0.0
|
||||
except (TypeError, ValueError):
|
||||
avail_f = 0.0
|
||||
min_sz = float(spot_min_sell_sz(ex, underlying))
|
||||
sellable = is_sellable_spot_coin(ex, underlying, avail_f)
|
||||
return jsonify(
|
||||
{
|
||||
"ok": True,
|
||||
"underlying": underlying,
|
||||
"available": avail_f,
|
||||
"min_sz": min_sz,
|
||||
"sellable": bool(sellable),
|
||||
}
|
||||
)
|
||||
|
||||
@app.route("/api/hedge-plan/sell-coin", methods=["POST"])
|
||||
@lr
|
||||
def api_hedge_sell_coin():
|
||||
"""手动卖回币:市价卖出交易账户全部可用标的币换 USDT."""
|
||||
"""手动卖回币:市价卖出交易账户全部可用标的币换 USDT(粉尘拒绝)."""
|
||||
if not _hedge_enabled():
|
||||
return jsonify({"ok": False, "msg": "对冲模块未启用"}), 400
|
||||
ex = cfg.get("exchange_options") or cfg.get("exchange")
|
||||
@@ -1294,6 +1331,27 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
underlying = str(data.get("underlying") or cfg.get("default_underly") or "ETH").strip().upper()
|
||||
if underlying not in ("ETH", "BTC"):
|
||||
return jsonify({"ok": False, "msg": "标的仅支持 ETH/BTC"}), 400
|
||||
from lib.options.options_spot_bridge_lib import (
|
||||
fetch_trading_coin_available,
|
||||
is_sellable_spot_coin,
|
||||
spot_min_sell_sz,
|
||||
)
|
||||
|
||||
avail = fetch_trading_coin_available(ex, underlying)
|
||||
try:
|
||||
avail_f = float(avail) if avail is not None else 0.0
|
||||
except (TypeError, ValueError):
|
||||
avail_f = 0.0
|
||||
if not is_sellable_spot_coin(ex, underlying, avail_f):
|
||||
min_sz = spot_min_sell_sz(ex, underlying)
|
||||
return jsonify(
|
||||
{
|
||||
"ok": False,
|
||||
"msg": f"无足够 {underlying} 可卖(可用 {avail_f:g} · 最小 {min_sz:g})",
|
||||
"available": avail_f,
|
||||
"min_sz": min_sz,
|
||||
}
|
||||
), 400
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
from lib.options.options_db import init_options_tables
|
||||
|
||||
Reference in New Issue
Block a user