账户快照缺失后改为 10 秒补打一次,避免短间隔 force 撞频。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-04 21:50:50 +08:00
parent 4cad929886
commit 7b432bc964
2 changed files with 54 additions and 22 deletions
+27 -11
View File
@@ -1200,7 +1200,23 @@ function accountSnapshotFundingMissing(data){
const hasTrading = data.current_capital != null && data.current_capital !== "";
return !hasFunding && !hasTotal && !hasTrading;
}
let accountSnapshotRetryCount = 0;
let accountSnapshotMissRetryTimer = null;
let accountSnapshotMissRetryDone = false;
function clearAccountSnapshotMissRetry(){
accountSnapshotMissRetryDone = false;
if(accountSnapshotMissRetryTimer){
clearTimeout(accountSnapshotMissRetryTimer);
accountSnapshotMissRetryTimer = null;
}
}
function scheduleAccountSnapshotMissRetry(){
if(accountSnapshotMissRetryDone || accountSnapshotMissRetryTimer) return;
accountSnapshotMissRetryTimer = setTimeout(function(){
accountSnapshotMissRetryTimer = null;
accountSnapshotMissRetryDone = true;
refreshAccountSnapshot({ silent: true, force: true, missRetry: true });
}, 10000);
}
function applyAccountSnapshot(data){
if(!data || typeof data !== "object") return;
const coinMode = String(data.options_margin_mode || "coin").toLowerCase() === "coin";
@@ -1329,20 +1345,20 @@ function applyAccountSnapshot(data){
}
function refreshAccountSnapshot(opts){
const options = opts || {};
const qs = options.force ? "?force=1" : "";
let useForce = !!options.force;
if(useForce && !options.missRetry && (accountSnapshotMissRetryTimer || accountSnapshotMissRetryDone)){
useForce = false;
}
const qs = useForce ? "?force=1" : "";
fetch("/api/account_snapshot" + qs).then(r=>r.json()).then(data=>{
applyAccountSnapshot(data);
if(accountSnapshotFundingMissing(data) && !options.force && accountSnapshotRetryCount < 3){
accountSnapshotRetryCount += 1;
setTimeout(() => refreshAccountSnapshot({ silent: true, force: accountSnapshotRetryCount >= 2 }), 1200 * accountSnapshotRetryCount);
}else if(!accountSnapshotFundingMissing(data)){
accountSnapshotRetryCount = 0;
if(!accountSnapshotFundingMissing(data)){
clearAccountSnapshotMissRetry();
return;
}
scheduleAccountSnapshotMissRetry();
}).catch(()=>{
if(!options.silent && accountSnapshotRetryCount < 3){
accountSnapshotRetryCount += 1;
setTimeout(() => refreshAccountSnapshot({ silent: true }), 1200 * accountSnapshotRetryCount);
}
scheduleAccountSnapshotMissRetry();
});
}