Use trading account and USDC/USDT market price for sim convert.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+16
-20
@@ -264,26 +264,20 @@ def _patch_okx_options_lib(app_module: Any) -> None:
|
||||
def spot_market_swap_usdt_usdc(ex, *, direction: str = "usdt_to_usdc", amount: float = 0):
|
||||
try:
|
||||
if _GET_DB is not None and is_sim_mode(_GET_DB):
|
||||
from lib.sim.wallets_lib import SimWallets
|
||||
|
||||
d = (direction or "usdt_to_usdc").strip().lower()
|
||||
if d == "usdc_to_usdt":
|
||||
from_ccy, to_ccy = "USDC", "USDT"
|
||||
else:
|
||||
from_ccy, to_ccy = "USDT", "USDC"
|
||||
result = SimWallets(_GET_DB).convert(
|
||||
from_ccy=from_ccy,
|
||||
to_ccy=to_ccy,
|
||||
amount=float(amount),
|
||||
account="funding",
|
||||
)
|
||||
if not result.get("ok"):
|
||||
result = SimWallets(_GET_DB).convert(
|
||||
from_ccy=from_ccy,
|
||||
to_ccy=to_ccy,
|
||||
amount=float(amount),
|
||||
account="trading",
|
||||
# 对齐实盘: 交易账户 + USDC/USDT 公开买卖一(含手续费滑点)
|
||||
pub = ex
|
||||
if pub is None and _APP_MODULE is not None:
|
||||
pub = getattr(_APP_MODULE, "exchange", None) or getattr(
|
||||
_APP_MODULE, "exchange_options", None
|
||||
)
|
||||
if pub is None:
|
||||
return {"ok": False, "msg": "sim: 无公开行情 exchange"}
|
||||
result = broker().convert_usdt_usdc(
|
||||
pub,
|
||||
direction=direction,
|
||||
amount=float(amount),
|
||||
account="trading",
|
||||
)
|
||||
if not result.get("ok"):
|
||||
return {
|
||||
"ok": False,
|
||||
@@ -295,7 +289,9 @@ def _patch_okx_options_lib(app_module: Any) -> None:
|
||||
notify_instance_balance_changed()
|
||||
except Exception:
|
||||
pass
|
||||
return {"ok": True, "msg": "sim 兑换成功(1:1)", "sim": True, **result}
|
||||
px = result.get("fill_px")
|
||||
msg = f"sim 兑换成功 @ {px:.6f}" if px else "sim 兑换成功"
|
||||
return {"ok": True, "msg": msg, "sim": True, **result}
|
||||
except Exception as e:
|
||||
return {"ok": False, "msg": str(e)}
|
||||
return _orig_swap(ex, direction=direction, amount=amount)
|
||||
|
||||
Reference in New Issue
Block a user