fix(order): hide estimated RR preview in fixed RR SLTP mode
Only price and percentage modes show estimated profit-loss ratio before open; fixed RR mode keeps the existing estimated take-profit display. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* 实盘下单:币种 + 止盈止损填完后拉 /api/order_defaults 快照,在开仓按钮前显示预估盈亏比。
|
||||
* 价格 / 百分比 / 固定盈亏比模式通用;与以损定仓、全仓杠杆计仓方式无关。
|
||||
* 仅价格 / 百分比模式;固定盈亏比模式沿用「预估止盈」,不显示预估盈亏比。
|
||||
*/
|
||||
(function (global) {
|
||||
"use strict";
|
||||
@@ -47,19 +47,6 @@
|
||||
return tp / sl;
|
||||
}
|
||||
|
||||
function calcTpFromFixedRr(direction, entry, sl, rr) {
|
||||
const e = num(entry);
|
||||
const s = num(sl);
|
||||
const r = num(rr);
|
||||
if (e === null || s === null || r === null || r <= 0) return null;
|
||||
if (direction === "short") {
|
||||
if (s <= e) return null;
|
||||
return e - (s - e) * r;
|
||||
}
|
||||
if (s >= e) return null;
|
||||
return e + (e - s) * r;
|
||||
}
|
||||
|
||||
function currentMode() {
|
||||
return ($("sltp-mode") && $("sltp-mode").value) || "fixed_rr";
|
||||
}
|
||||
@@ -80,21 +67,21 @@
|
||||
const tp = num($("order-tp-pct") && $("order-tp-pct").value);
|
||||
return sl !== null && tp !== null && sl > 0 && tp > 0;
|
||||
}
|
||||
if (m === "fixed_rr") {
|
||||
const sl = num($("order-sl") && $("order-sl").value);
|
||||
const rr = num($("order-fixed-rr") && $("order-fixed-rr").value);
|
||||
return sl !== null && rr !== null && sl > 0 && rr > 0;
|
||||
}
|
||||
const sl = num($("order-sl") && $("order-sl").value);
|
||||
const tp = num($("order-tp") && $("order-tp").value);
|
||||
return sl !== null && tp !== null && sl > 0 && tp > 0;
|
||||
}
|
||||
|
||||
function hidePreview() {
|
||||
const el = $("order-rr-preview");
|
||||
if (el) el.style.display = "none";
|
||||
}
|
||||
|
||||
function paint(rr, state) {
|
||||
const el = $("order-rr-preview");
|
||||
if (!el) return;
|
||||
const m = currentMode();
|
||||
if (m !== "price" && m !== "pct" && m !== "fixed_rr") {
|
||||
if (m === "fixed_rr" || (m !== "price" && m !== "pct")) {
|
||||
el.style.display = "none";
|
||||
return;
|
||||
}
|
||||
@@ -125,6 +112,10 @@
|
||||
|
||||
function refreshNow() {
|
||||
const m = currentMode();
|
||||
if (m === "fixed_rr") {
|
||||
hidePreview();
|
||||
return;
|
||||
}
|
||||
if (!inputsComplete(m)) {
|
||||
paint(null, "empty");
|
||||
return;
|
||||
@@ -163,17 +154,9 @@
|
||||
paint(null, "fetch_fail");
|
||||
return;
|
||||
}
|
||||
let rr = null;
|
||||
if (m === "fixed_rr") {
|
||||
const sl = num($("order-sl") && $("order-sl").value);
|
||||
const fixed = num($("order-fixed-rr") && $("order-fixed-rr").value);
|
||||
const tp = calcTpFromFixedRr(dir, entry, sl, fixed);
|
||||
rr = tp !== null ? fixed : null;
|
||||
} else {
|
||||
const sl = num($("order-sl") && $("order-sl").value);
|
||||
const tp = num($("order-tp") && $("order-tp").value);
|
||||
rr = calcRr(dir, entry, sl, tp);
|
||||
}
|
||||
const sl = num($("order-sl") && $("order-sl").value);
|
||||
const tp = num($("order-tp") && $("order-tp").value);
|
||||
const rr = calcRr(dir, entry, sl, tp);
|
||||
paint(rr, rr === null ? "invalid" : "ok");
|
||||
})
|
||||
.catch(function () {
|
||||
|
||||
Reference in New Issue
Block a user