修复实例页长时间后不自动刷新:回前台强制拉数、SSE假连接兜底、快照请求超时防卡死。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1173,6 +1173,17 @@ function accountSnapshotFundingMissing(data){
|
||||
return !hasFunding && !hasTotal && !hasTrading;
|
||||
}
|
||||
let accountSnapshotRetryCount = 0;
|
||||
let accountSnapshotInflight = false;
|
||||
let priceSnapshotInflight = false;
|
||||
|
||||
function fetchJsonWithTimeout(url, timeoutMs) {
|
||||
const ms = timeoutMs != null ? timeoutMs : 25000;
|
||||
const ac = new AbortController();
|
||||
const timer = setTimeout(function () { ac.abort(); }, ms);
|
||||
return fetch(url, { signal: ac.signal, credentials: "same-origin" })
|
||||
.then(function (r) { return r.json(); })
|
||||
.finally(function () { clearTimeout(timer); });
|
||||
}
|
||||
function applyAccountSnapshot(data){
|
||||
if(!data || typeof data !== "object") return;
|
||||
if(typeof data.show_perp_funds !== "undefined"){
|
||||
@@ -1263,8 +1274,10 @@ function applyAccountSnapshot(data){
|
||||
}
|
||||
function refreshAccountSnapshot(opts){
|
||||
const options = opts || {};
|
||||
if(accountSnapshotInflight && !options.force) return;
|
||||
accountSnapshotInflight = true;
|
||||
const qs = options.force ? "?force=1" : "";
|
||||
fetch("/api/account_snapshot" + qs).then(r=>r.json()).then(data=>{
|
||||
fetchJsonWithTimeout("/api/account_snapshot" + qs, 25000).then(data=>{
|
||||
applyAccountSnapshot(data);
|
||||
if(accountSnapshotFundingMissing(data) && !options.force && accountSnapshotRetryCount < 3){
|
||||
accountSnapshotRetryCount += 1;
|
||||
@@ -1277,7 +1290,7 @@ function refreshAccountSnapshot(opts){
|
||||
accountSnapshotRetryCount += 1;
|
||||
setTimeout(() => refreshAccountSnapshot({ silent: true }), 1200 * accountSnapshotRetryCount);
|
||||
}
|
||||
});
|
||||
}).finally(()=>{ accountSnapshotInflight = false; });
|
||||
}
|
||||
|
||||
const orderSymbolEl = document.getElementById("order-symbol");
|
||||
@@ -1419,8 +1432,10 @@ refreshOrderDefaults();
|
||||
if(typeof initOrderEntryModelSelect === "function") initOrderEntryModelSelect();
|
||||
refreshPriceSnapshotConditional();
|
||||
function refreshPriceSnapshotConditional(){
|
||||
if(priceSnapshotInflight) return;
|
||||
priceSnapshotInflight = true;
|
||||
const page = document.body.getAttribute("data-page") || "";
|
||||
fetch("/api/price_snapshot").then(r=>r.json()).then(data=>{
|
||||
fetchJsonWithTimeout("/api/price_snapshot", 25000).then(data=>{
|
||||
const updatedEl = document.getElementById("price-last-updated");
|
||||
if(data.updated_at && updatedEl) updatedEl.innerText = data.updated_at;
|
||||
if(data.force_close && window.TimeCloseUI && TimeCloseUI.paintForceCloseHeader){
|
||||
@@ -1474,7 +1489,7 @@ function refreshPriceSnapshotConditional(){
|
||||
} else if (typeof data.options_unrealized_pnl !== "undefined") {
|
||||
paintRealtimePnlFromSnapshot(data);
|
||||
}
|
||||
}).catch(()=>{});
|
||||
}).catch(()=>{}).finally(()=>{ priceSnapshotInflight = false; });
|
||||
}
|
||||
function formatLiveHoldDurationFromMs(openedMs, nowMs){
|
||||
if(openedMs == null || openedMs === "" || !Number.isFinite(Number(openedMs))) return "—";
|
||||
|
||||
Reference in New Issue
Block a user