feat中控条件单可指令实例账户内划转,Bridge 暴露划转接口。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1261,52 +1261,21 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
ex, err = _require_options_ex(cfg)
|
||||
if ex is None:
|
||||
return jsonify({"ok": False, "msg": err})
|
||||
# 持仓/待卖回禁止划转(规格)
|
||||
conn_blk = cfg["get_db"]()
|
||||
try:
|
||||
from lib.options.options_account_pnl_lib import transfer_blocked_by_position_msg
|
||||
|
||||
block = transfer_blocked_by_position_msg(conn_blk, ex)
|
||||
if block:
|
||||
return jsonify({"ok": False, "msg": block, "transfer_blocked": True})
|
||||
finally:
|
||||
conn_blk.close()
|
||||
del ex # 执行层自行取 exchange_options
|
||||
data = request.get_json(silent=True) or {}
|
||||
ccy = (data.get("ccy") or "USDC").upper()
|
||||
from_acct = (data.get("from") or "funding").strip()
|
||||
to_acct = (data.get("to") or "trading").strip()
|
||||
try:
|
||||
amount = float(data.get("amount"))
|
||||
except (TypeError, ValueError):
|
||||
return jsonify({"ok": False, "msg": "数量无效"})
|
||||
try:
|
||||
import lib.exchange.okx_options_lib as _opt_lib
|
||||
from lib.options.options_transfer_exec_lib import execute_options_internal_transfer
|
||||
|
||||
xfer = getattr(_opt_lib, "transfer_ccy", None)
|
||||
except Exception:
|
||||
xfer = None
|
||||
if not callable(xfer):
|
||||
xfer = cfg.get("transfer_ccy")
|
||||
result = xfer(ex, ccy, amount, from_acct, to_acct) if callable(xfer) else {
|
||||
"ok": False,
|
||||
"msg": "划转不可用",
|
||||
}
|
||||
if result.get("ok"):
|
||||
conn = cfg["get_db"]()
|
||||
try:
|
||||
init_options_tables(conn)
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO options_transfer_log (ccy, amount, from_account, to_account, status, message)
|
||||
VALUES (?, ?, ?, ?, 'ok', '')
|
||||
""",
|
||||
(ccy, amount, from_acct, to_acct),
|
||||
)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
_mark_balances_stale(cfg)
|
||||
return jsonify(result)
|
||||
# 前端传 ccy;缺省 USDT(币本位)
|
||||
ccy = (data.get("ccy") or "USDT").upper()
|
||||
return jsonify(
|
||||
execute_options_internal_transfer(
|
||||
cfg,
|
||||
amount=data.get("amount"),
|
||||
from_acct=(data.get("from") or "funding"),
|
||||
to_acct=(data.get("to") or "trading"),
|
||||
ccy=ccy,
|
||||
)
|
||||
)
|
||||
|
||||
@app.route("/api/options/spot/swap", methods=["POST"])
|
||||
@lr
|
||||
|
||||
Reference in New Issue
Block a user