fix(options): cache instruments and backoff on OKX 50011
期权链拉取遇限频时退避重试并回退短缓存,前端提示更友好。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1216,16 +1216,25 @@
|
||||
try {
|
||||
let d = null;
|
||||
let lastMsg = "";
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
for (let attempt = 0; attempt < 3; attempt++) {
|
||||
if (seq !== chainLoadSeq) return;
|
||||
d = await apiJson("/api/options/chain?underlying=" + encodeURIComponent(uly));
|
||||
if (seq !== chainLoadSeq) return;
|
||||
if (d && d.ok && chainHasExpiries(d)) break;
|
||||
lastMsg = (d && (d.msg || d.chain_error)) || "暂无到期日";
|
||||
const rateLimited =
|
||||
!!(d && d.rate_limited) ||
|
||||
/50011|Too Many Requests|过于频繁/i.test(String(lastMsg || ""));
|
||||
d = null;
|
||||
if (attempt === 0) {
|
||||
if (!soft) setExpirySelectStatus("重试加载到期日…");
|
||||
await new Promise(function (resolve) { setTimeout(resolve, 400); });
|
||||
if (attempt < 2) {
|
||||
if (!soft) {
|
||||
setExpirySelectStatus(
|
||||
rateLimited ? "OKX 限频,稍后重试…" : "重试加载到期日…"
|
||||
);
|
||||
}
|
||||
await new Promise(function (resolve) {
|
||||
setTimeout(resolve, rateLimited ? 1200 * (attempt + 1) : 400);
|
||||
});
|
||||
}
|
||||
}
|
||||
if (seq !== chainLoadSeq) return;
|
||||
@@ -1240,13 +1249,19 @@
|
||||
if (soft) return;
|
||||
setExpirySelectStatus("选择到期日");
|
||||
const tbody = document.getElementById("opt-strike-tbody");
|
||||
const friendly =
|
||||
/50011|Too Many Requests|过于频繁/i.test(String(lastMsg || ""))
|
||||
? "OKX 请求过于频繁,请稍后再点「刷新链」"
|
||||
: lastMsg || "暂无到期日,请点「刷新链」";
|
||||
if (tbody) {
|
||||
tbody.innerHTML =
|
||||
'<tr><td colspan="' + strikeTableColspan() + '" class="muted">' +
|
||||
(lastMsg || "暂无到期日,请点「刷新链」") +
|
||||
'<tr><td colspan="' +
|
||||
strikeTableColspan() +
|
||||
'" class="muted">' +
|
||||
friendly +
|
||||
"</td></tr>";
|
||||
}
|
||||
alert(lastMsg || "加载到期日失败,请点「刷新链」重试");
|
||||
alert(friendly);
|
||||
return;
|
||||
}
|
||||
const keepExp = soft ? (document.getElementById("opt-exp-select") || {}).value : "";
|
||||
|
||||
Reference in New Issue
Block a user