账户快照缺失后改为 10 秒补打一次,避免短间隔 force 撞频。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1686,7 +1686,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";
|
||||
@@ -1824,20 +1840,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();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user