feat: 修改委托后展示最新风险,四所持仓卡增加张数

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-02 22:08:27 +08:00
parent 9d9d0af31e
commit 687a34474d
14 changed files with 505 additions and 5 deletions
+34
View File
@@ -7387,6 +7387,13 @@ def api_price_snapshot():
exchange_tpsl=exchange_tpsl,
format_price_fn=format_price_for_symbol,
symbol=r["symbol"],
margin_capital=margin,
leverage=leverage,
exchange_notional=ex_metrics.get("notional") if ex_metrics else None,
contracts=abs(_position_row_effective_contracts(prow)) if prow else None,
contract_size=float(get_contract_size(r["symbol"])) if r["symbol"] else 1.0,
mark_price=ex_metrics.get("mark_price") if ex_metrics else price,
funds_decimals=FUNDS_DECIMALS,
)
apply_time_close_to_payload(payload, r)
payload["opened_at"] = r["opened_at"] if "opened_at" in r.keys() else None
@@ -7508,6 +7515,32 @@ def api_order_place_tpsl(order_id):
conn.commit()
ex_sym = resolve_monitor_exchange_symbol(row)
slots = fetch_exchange_tpsl_slots(ex_sym, direction, plan_sl=stop_loss, plan_tp=take_profit)
prow = None
ex_metrics = None
if exchange_private_api_configured():
try:
rows = exchange.fetch_positions([ex_sym]) or exchange.fetch_positions() or []
prow = _select_live_position_row(rows, ex_sym, direction)
if prow:
ex_metrics = parse_ccxt_position_metrics(prow, order_leverage=row["leverage"])
except Exception:
pass
from lib.trade.order_monitor_display_lib import enrich_active_monitor_tpsl_json
display_extra = enrich_active_monitor_tpsl_json(
row,
stop_loss,
take_profit,
slots,
position_row=prow,
exchange_notional=ex_metrics.get("notional") if ex_metrics else None,
contract_size=float(get_contract_size(symbol)) if symbol else 1.0,
mark_price=live_price,
calc_rr_ratio_fn=calc_rr_ratio,
format_price_fn=format_price_for_symbol,
symbol=symbol,
funds_decimals=FUNDS_DECIMALS,
)
conn.close()
return jsonify(
{
@@ -7517,6 +7550,7 @@ def api_order_place_tpsl(order_id):
"take_profit": take_profit,
"planned_rr": planned_rr,
"exchange_tpsl": slots,
**display_extra,
}
)
+35 -1
View File
@@ -429,6 +429,7 @@
<span class="pos-meta-item">来源: {{ o.monitor_type|default('下单监控', true) }}{% if o.key_signal_type %} · {{ o.key_signal_type }}{% endif %}</span>
<span class="pos-meta-item">风格: {{ o.trade_style or 'trend' }}</span>
<span class="pos-meta-item">风险: {% if position_sizing_mode == 'full_margin' %}{{ funds_fmt(o.risk_amount) if o.risk_amount is not none else '-' }}U{% else %}{{ o.risk_percent or '-' }}%≈{{ funds_fmt(o.risk_amount) if o.risk_amount is not none else '-' }}U{% endif %}</span>
<span class="pos-meta-item" id="order-latest-risk-wrap-{{ o.id }}" style="display:none">最新风险: —</span>
<span class="pos-meta-item {% if o.breakeven_enabled %}pos-meta-on{% else %}pos-meta-off{% endif %}">
{% if o.breakeven_enabled %}移动保本:开 {{ o.breakeven_rr_trigger or '-' }}R→{{ price_fmt(o.symbol, o.breakeven_price) }}{% else %}移动保本:关{% endif %}
</span>
@@ -451,6 +452,10 @@
<span class="pos-label">盈亏比</span>
<span class="pos-value" id="order-rr-{{ o.id }}">{% if o.rr_ratio is not none %}{{ '%g'|format(o.rr_ratio) }}:1{% else %}-:1{% endif %}</span>
</div>
<div class="pos-cell">
<span class="pos-label">张数</span>
<span class="pos-value" id="order-contracts-{{ o.id }}">{% if o.order_amount is not none %}{{ '%g'|format(o.order_amount) }}{% else %}—{% endif %}</span>
</div>
<div class="pos-cell">
<span class="pos-label">标记价</span>
<span class="pos-value" id="order-price-{{ o.id }}">-</span>
@@ -1663,6 +1668,13 @@ function submitTpslEntrust(){
alert(data.msg || '已提交');
closeTpslEntrustModal();
if(data.exchange_tpsl) paintExchangeTpslRow(orderId, data.exchange_tpsl);
paintPlanTpslDisplay(orderId, data);
paintLatestRiskDisplay(orderId, data);
const rrEl = document.getElementById(`order-rr-${orderId}`);
if(rrEl){
const rr = data.display_rr_ratio != null && data.display_rr_ratio !== "" ? data.display_rr_ratio : data.planned_rr;
rrEl.innerText = formatRrRatio(rr);
}
refreshPriceSnapshotConditional();
}).catch(()=>alert('委托请求失败'));
}
@@ -1730,6 +1742,25 @@ function paintPlanTpslDisplay(orderId, snap){
else if(tpDisp) card.setAttribute("data-plan-tp", tpDisp);
}
}
function paintLatestRiskDisplay(orderId, snap){
const wrap = document.getElementById(`order-latest-risk-wrap-${orderId}`);
if(!wrap) return;
const v = snap && snap.latest_risk_amount;
const n = v != null && v !== "" ? Number(v) : NaN;
if(Number.isFinite(n)){
wrap.style.display = "inline-flex";
wrap.textContent = `最新风险: ${n.toFixed(2)}U`;
} else {
wrap.style.display = "none";
}
}
function paintContractsDisplay(orderId, snap){
const el = document.getElementById(`order-contracts-${orderId}`);
if(!el || !snap) return;
const v = snap.contracts != null && snap.contracts !== "" ? snap.contracts : snap.order_amount;
const n = v != null && v !== "" ? Number(v) : NaN;
el.innerText = Number.isFinite(n) ? String(parseFloat(n.toFixed(4))) : "—";
}
function paintPriceTrend(el, key, value){
if(!el) return;
@@ -1813,8 +1844,11 @@ function refreshPriceSnapshot(){
}
const rrEl = document.getElementById(`order-rr-${o.id}`);
if(rrEl){
rrEl.innerText = formatRrRatio(o.rr_ratio);
const rr = o.display_rr_ratio != null && o.display_rr_ratio !== "" ? o.display_rr_ratio : o.rr_ratio;
rrEl.innerText = formatRrRatio(rr);
}
paintLatestRiskDisplay(o.id, o);
paintContractsDisplay(o.id, o);
paintBreakevenBadge(o.id, o.sl_breakeven_secured);
if(o.exchange_tpsl) paintExchangeTpslRow(o.id, o.exchange_tpsl);
paintPlanTpslDisplay(o.id, o);