Expand default strike rows and add hedge fund transfer / sell-coin.

Show the default five chain rows without a scroll box, add funding transfer under manual pick, and wire sell-back-coin above positions via hedge APIs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 19:11:44 +08:00
parent d40a0d25be
commit fc83905cf6
6 changed files with 287 additions and 34 deletions
+78
View File
@@ -1244,6 +1244,80 @@ def register_hedge_plan_routes(app: Flask, cfg: dict[str, Any]) -> None:
conn.close()
return jsonify(out)
@app.route("/api/hedge-plan/transfer", methods=["POST"])
@lr
def api_hedge_transfer():
"""账户内划转(资金↔交易);USDT/ETH/BTC.本仓不依赖单独期权 UI."""
if not _hedge_enabled():
return jsonify({"ok": False, "msg": "对冲模块未启用"}), 400
ex = cfg.get("exchange_options") or cfg.get("exchange")
if ex is None:
return jsonify({"ok": False, "msg": "交易所未配置"}), 400
data = request.get_json(silent=True) or {}
ccy = str(data.get("ccy") or "USDT").strip().upper()
if ccy not in ("USDT", "ETH", "BTC"):
return jsonify({"ok": False, "msg": "币种仅支持 USDT/ETH/BTC"}), 400
from_acct = str(data.get("from") or "funding").strip().lower()
to_acct = str(data.get("to") or "trading").strip().lower()
if from_acct not in ("funding", "trading") or to_acct not in ("funding", "trading"):
return jsonify({"ok": False, "msg": "账户仅支持 funding/trading"}), 400
if from_acct == to_acct:
return jsonify({"ok": False, "msg": "划出与划入账户不能相同"}), 400
try:
amount = float(data.get("amount"))
except (TypeError, ValueError):
return jsonify({"ok": False, "msg": "数量无效"}), 400
if amount <= 0:
return jsonify({"ok": False, "msg": "数量须大于 0"}), 400
from lib.exchange.okx_options_lib import transfer_ccy
result = transfer_ccy(ex, ccy, amount, from_acct, to_acct)
if result.get("ok"):
try:
from lib.exchange.okx_options_lib import invalidate_options_balance_cache
invalidate_options_balance_cache()
except Exception:
pass
return jsonify(result)
@app.route("/api/hedge-plan/sell-coin", methods=["POST"])
@lr
def api_hedge_sell_coin():
"""手动卖回币:市价卖出交易账户全部可用标的币换 USDT."""
if not _hedge_enabled():
return jsonify({"ok": False, "msg": "对冲模块未启用"}), 400
ex = cfg.get("exchange_options") or cfg.get("exchange")
if ex is None:
return jsonify({"ok": False, "msg": "交易所未配置"}), 400
data = request.get_json(silent=True) or {}
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
conn = cfg["get_db"]()
try:
from lib.options.options_db import init_options_tables
from lib.options.options_spot_bridge_lib import sell_residual_after_option_flat
init_options_tables(conn)
out = sell_residual_after_option_flat(
conn,
ex,
underlying=underlying,
inst_id=(str(data.get("inst_id") or "").strip() or None),
)
if out.get("ok"):
conn.commit()
try:
from lib.exchange.okx_options_lib import invalidate_options_balance_cache
invalidate_options_balance_cache()
except Exception:
pass
return jsonify(out)
finally:
conn.close()
@app.route("/api/hedge-plan/monitor-tick", methods=["POST"])
@lr
def api_hedge_monitor_tick():
@@ -1479,6 +1553,10 @@ def _options_account_snapshot(cfg: dict[str, Any]) -> dict[str, Any]:
"funding_usdt": pack.get("funding_usdt"),
"trading_usdt_avail": pack.get("trading_usdt_avail", pack.get("trading_usdt")),
"perp_margin_usdt": pack.get("perp_margin_usdt"),
"funding_eth": pack.get("funding_eth"),
"trading_eth": pack.get("trading_eth"),
"funding_btc": pack.get("funding_btc"),
"trading_btc": pack.get("trading_btc"),
}
)
except Exception: