Use trading account and USDC/USDT market price for sim convert.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-14 18:52:38 +08:00
parent 9d1495658c
commit ad992ee262
7 changed files with 181 additions and 45 deletions
+43
View File
@@ -509,6 +509,49 @@ class SimBroker:
"info": {"sim": True, "fee": pr.fee, "fill": pr.to_dict()},
}
def convert_usdt_usdc(
self,
exchange: Any,
*,
direction: str,
amount: float,
fee_rate: float | None = None,
account: str = "trading",
symbol: str = "USDC/USDT",
) -> dict[str, Any]:
"""模拟 USDC-USDT 现货市价兑换, 默认扣交易账户."""
from lib.sim.pricing_lib import spot_usdc_usdt_fill
fr = sim_fee_rate(fee_rate)
bid, ask = _ticker_bid_ask(exchange, symbol)
fill = spot_usdc_usdt_fill(
direction=direction, amount=float(amount), bid=bid, ask=ask, fee_rate=fr
)
result = SimWallets(self.get_db).convert(
from_ccy=fill.from_ccy,
to_ccy=fill.to_ccy,
amount=fill.from_amount,
account=account or "trading",
to_amount=fill.to_amount,
rate=fill.fill_px,
fee=fill.fee,
note=f"USDC/USDT mkt {fill.fill_px:.6f} (bid {bid:.6f}/ask {ask:.6f})",
)
if not result.get("ok"):
return result
result.update(
{
"direction": fill.direction,
"bid": bid,
"ask": ask,
"base_px": fill.base_px,
"fill_px": fill.fill_px,
"fee_rate": fr,
"symbol": symbol,
}
)
return result
def option_positions_okx_rows(self) -> list[dict[str, Any]]:
"""对齐 OKX positions 行字段, 供 format_position_row 使用."""
rows = []