feat: 持仓委托改止盈止损,保证金改读CTP柜台UseMargin
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+12
-2
@@ -488,6 +488,15 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
direction, entry, sl if sl is not None else entry,
|
||||
tp if tp is not None else entry, lots, mark, capital, sym,
|
||||
)
|
||||
ctp_margin = float(ctp.get("margin") or 0) if ctp else 0.0
|
||||
est_margin = pos_metrics.get("margin")
|
||||
margin = ctp_margin if ctp_margin > 0 else est_margin
|
||||
margin_source = "ctp" if ctp_margin > 0 else "estimate"
|
||||
position_pct = (
|
||||
round(float(margin) / capital * 100, 2)
|
||||
if capital > 0 and margin
|
||||
else pos_metrics.get("position_pct")
|
||||
)
|
||||
order_st = monitor_order_status(
|
||||
mon or {}, mode=mode, ths_code=sym, direction=direction,
|
||||
)
|
||||
@@ -529,8 +538,9 @@ def install_trading(app, *, login_required, require_nav, get_db, get_setting, se
|
||||
"holding_duration": holding or None,
|
||||
"mark_price": mark,
|
||||
"current_price": mark,
|
||||
"margin": pos_metrics.get("margin"),
|
||||
"position_pct": pos_metrics.get("position_pct"),
|
||||
"margin": margin,
|
||||
"margin_source": margin_source,
|
||||
"position_pct": position_pct,
|
||||
"risk_amount": pos_metrics.get("risk_amount") if sl is not None else None,
|
||||
"risk_pct": pos_metrics.get("risk_pct") if sl is not None else None,
|
||||
"rr_ratio": pos_metrics.get("rr_ratio") if sl is not None and tp is not None else None,
|
||||
|
||||
Reference in New Issue
Block a user