Use trading account and USDC/USDT market price for sim convert.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+15
-6
@@ -140,12 +140,21 @@ def install_sim_trading(app: Flask, repo_root: str, app_module: Any = None) -> N
|
||||
amount = float(body.get("amount") or 0)
|
||||
except (TypeError, ValueError):
|
||||
return jsonify({"ok": False, "msg": "amount 无效"}), 400
|
||||
result = SimWallets(get_db).convert(
|
||||
from_ccy=str(body.get("from_ccy") or ""),
|
||||
to_ccy=str(body.get("to_ccy") or ""),
|
||||
amount=amount,
|
||||
account=str(body.get("account") or "funding"),
|
||||
)
|
||||
from_ccy = str(body.get("from_ccy") or "USDT").strip().upper()
|
||||
to_ccy = str(body.get("to_ccy") or "USDC").strip().upper()
|
||||
if {from_ccy, to_ccy} != {"USDT", "USDC"}:
|
||||
return jsonify({"ok": False, "msg": "仅支持 USDT↔USDC"}), 400
|
||||
direction = "usdt_to_usdc" if from_ccy == "USDT" else "usdc_to_usdt"
|
||||
account = str(body.get("account") or "trading")
|
||||
ex = getattr(app_module, "exchange", None) or getattr(app_module, "exchange_options", None)
|
||||
if ex is None:
|
||||
return jsonify({"ok": False, "msg": "无公开行情 exchange"}), 500
|
||||
try:
|
||||
result = SimBroker(get_db).convert_usdt_usdc(
|
||||
ex, direction=direction, amount=amount, account=account
|
||||
)
|
||||
except Exception as e:
|
||||
return jsonify({"ok": False, "msg": str(e)}), 400
|
||||
if not result.get("ok"):
|
||||
return jsonify(result), 400
|
||||
return jsonify({**result, **_status_payload()})
|
||||
|
||||
Reference in New Issue
Block a user