对齐币本位期权:现货缓冲开仓、页头 ETH/BTC 余额与默认 coin 模式。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -268,7 +268,7 @@ function toggleListWindowCustom(){
|
||||
|
||||
function applyListWindow(){
|
||||
const qs = listWindowQueryString();
|
||||
const path = window.location.pathname || "/options";
|
||||
const path = window.location.pathname || "/trade";
|
||||
window.location.href = qs ? (path + "?" + qs) : path;
|
||||
}
|
||||
|
||||
@@ -1136,13 +1136,36 @@ function paintRealtimePnlFromSnapshot(data){
|
||||
}
|
||||
}
|
||||
|
||||
function formatOptionsFundingLabel(usdc, usdt) {
|
||||
// 期权侧顶栏仅 USDC;usdt 参数忽略(USDT 在永续资金/交易账户)
|
||||
function formatOptionsFundingLabel(usdc, usdt, eth, marginMode, underly) {
|
||||
if (usdc === null || usdc === undefined || usdc === "") return "—";
|
||||
const n = Number(usdc);
|
||||
if (Number.isNaN(n)) return "—";
|
||||
return `${n.toFixed(2)} USDC`;
|
||||
}
|
||||
function formatTradingAccountLabel(usdt, eth, btc, marginMode) {
|
||||
const mode = String(marginMode || "coin").toLowerCase();
|
||||
if (mode !== "coin") {
|
||||
if (usdt === null || usdt === undefined || usdt === "") return "—";
|
||||
const n = Number(usdt);
|
||||
if (Number.isNaN(n)) return "—";
|
||||
return `${n.toFixed(2)}U`;
|
||||
}
|
||||
const parts = [];
|
||||
if (usdt !== null && usdt !== undefined && usdt !== "") {
|
||||
const n = Number(usdt);
|
||||
if (!Number.isNaN(n)) parts.push(`${n.toFixed(2)} USDT`);
|
||||
}
|
||||
const pushCoin = (v, ccy) => {
|
||||
if (v === null || v === undefined || v === "") return;
|
||||
const n = Number(v);
|
||||
if (Number.isNaN(n) || !(n >= (ccy === "BTC" ? 1e-7 : 1e-6))) return;
|
||||
const txt = String(n.toFixed(6)).replace(/\.?0+$/, "");
|
||||
parts.push(`${txt || "0"} ${ccy}`);
|
||||
};
|
||||
pushCoin(eth, "ETH");
|
||||
pushCoin(btc, "BTC");
|
||||
return parts.length ? parts.join(" / ") : "—";
|
||||
}
|
||||
|
||||
function setFundsFieldText(field, text){
|
||||
if(text == null || text === "") return;
|
||||
@@ -1156,6 +1179,11 @@ function applyPerpFundsVisibility(show){
|
||||
el.style.display = on ? "" : "none";
|
||||
});
|
||||
}
|
||||
function applyOptionsFundsVisibility(show){
|
||||
document.querySelectorAll("[data-options-funds='1']").forEach((el) => {
|
||||
el.style.display = show ? "" : "none";
|
||||
});
|
||||
}
|
||||
function accountSnapshotFundingMissing(data){
|
||||
if(!data || typeof data !== "object") return true;
|
||||
if(data.show_perp_funds === false){
|
||||
@@ -1175,16 +1203,13 @@ function accountSnapshotFundingMissing(data){
|
||||
let accountSnapshotRetryCount = 0;
|
||||
function applyAccountSnapshot(data){
|
||||
if(!data || typeof data !== "object") return;
|
||||
if(data.updated_at){
|
||||
const updatedEl = document.getElementById("price-last-updated");
|
||||
if(updatedEl) updatedEl.innerText = data.updated_at;
|
||||
}
|
||||
const coinMode = String(data.options_margin_mode || "coin").toLowerCase() === "coin";
|
||||
if(typeof data.show_perp_funds !== "undefined"){
|
||||
applyPerpFundsVisibility(data.show_perp_funds);
|
||||
}
|
||||
if(data.exchange_mode_label){
|
||||
setFundsFieldText("exchange-mode-label", data.exchange_mode_label);
|
||||
applyPerpFundsVisibility(data.show_perp_funds !== false || coinMode);
|
||||
} else if (coinMode) {
|
||||
applyPerpFundsVisibility(true);
|
||||
}
|
||||
applyOptionsFundsVisibility(!coinMode);
|
||||
if(data.funding_usdt != null && data.funding_usdt !== ""){
|
||||
setFundsFieldText("total-capital", `${Number(data.funding_usdt).toFixed(2)}U`);
|
||||
}
|
||||
@@ -1192,14 +1217,34 @@ function applyAccountSnapshot(data){
|
||||
setFundsFieldText("total-funds", `${Number(data.total_funds).toFixed(2)}U`);
|
||||
}
|
||||
if(data.current_capital != null && data.current_capital !== "" && !Number.isNaN(Number(data.current_capital))){
|
||||
setFundsFieldText("current-capital", `${Number(data.current_capital).toFixed(2)}U`);
|
||||
setFundsFieldText(
|
||||
"current-capital",
|
||||
formatTradingAccountLabel(
|
||||
data.current_capital,
|
||||
data.options_trading_eth,
|
||||
data.options_trading_btc,
|
||||
data.options_margin_mode
|
||||
)
|
||||
);
|
||||
}
|
||||
if(data.options_funding_usdc != null || data.options_funding_usdt != null){
|
||||
const optFunding = formatOptionsFundingLabel(data.options_funding_usdc, data.options_funding_usdt);
|
||||
if(!coinMode && (data.options_funding_usdc != null || data.options_funding_usdt != null || data.options_funding_eth != null)){
|
||||
const optFunding = formatOptionsFundingLabel(
|
||||
data.options_funding_usdc,
|
||||
data.options_funding_usdt,
|
||||
data.options_funding_eth,
|
||||
data.options_margin_mode,
|
||||
data.options_underly
|
||||
);
|
||||
setFundsFieldText("options-funding-usdc", optFunding);
|
||||
}
|
||||
if(data.options_trading_usdc != null || data.options_trading_usdt != null){
|
||||
const optTrading = formatOptionsFundingLabel(data.options_trading_usdc, data.options_trading_usdt);
|
||||
if(!coinMode && (data.options_trading_usdc != null || data.options_trading_usdt != null || data.options_trading_eth != null)){
|
||||
const optTrading = formatOptionsFundingLabel(
|
||||
data.options_trading_usdc,
|
||||
data.options_trading_usdt,
|
||||
data.options_trading_eth,
|
||||
data.options_margin_mode,
|
||||
data.options_underly
|
||||
);
|
||||
setFundsFieldText("options-trading-usdc", optTrading);
|
||||
}
|
||||
if(typeof data.unrealized_pnl !== "undefined"){
|
||||
@@ -1270,11 +1315,7 @@ function applyAccountSnapshot(data){
|
||||
}
|
||||
function refreshAccountSnapshot(opts){
|
||||
const options = opts || {};
|
||||
const params = new URLSearchParams();
|
||||
if(options.force) params.set("force", "1");
|
||||
const page = (document.body && document.body.getAttribute("data-page")) || "";
|
||||
if(page) params.set("page", page);
|
||||
const qs = params.toString() ? ("?" + params.toString()) : "";
|
||||
const qs = options.force ? "?force=1" : "";
|
||||
fetch("/api/account_snapshot" + qs).then(r=>r.json()).then(data=>{
|
||||
applyAccountSnapshot(data);
|
||||
if(accountSnapshotFundingMissing(data) && !options.force && accountSnapshotRetryCount < 3){
|
||||
|
||||
Reference in New Issue
Block a user