Force-refresh header balances after transfers and balance SSE events.
Invalidate balance caches on mutation, push SSE balance tick, and bypass 60s cache when refreshing funds. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -123,9 +123,24 @@ def _build_cfg(app_module: Any) -> dict[str, Any]:
|
||||
"spot_market_swap_usdt_usdc": spot_market_swap_usdt_usdc,
|
||||
"transfer_main_sub_account": transfer_main_sub_account,
|
||||
"options_api_ready": options_api_ready,
|
||||
"app_module": app_module,
|
||||
}
|
||||
|
||||
|
||||
def _mark_balances_stale(cfg: dict[str, Any]) -> None:
|
||||
from lib.exchange.okx_options_lib import invalidate_options_balance_cache
|
||||
from lib.instance.instance_live_push_lib import notify_instance_balance_changed
|
||||
|
||||
invalidate_options_balance_cache()
|
||||
app_mod = cfg.get("app_module")
|
||||
if app_mod is not None and hasattr(app_mod, "invalidate_account_balance_cache"):
|
||||
app_mod.invalidate_account_balance_cache()
|
||||
try:
|
||||
notify_instance_balance_changed()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _require_options_ex(cfg: dict[str, Any]):
|
||||
if not cfg.get("enabled"):
|
||||
return None, "期权模块未启用,请在 .env 设置 OKX_OPTIONS_ENABLED=true 并重启 PM2"
|
||||
@@ -791,6 +806,7 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
_mark_balances_stale(cfg)
|
||||
return jsonify(result)
|
||||
|
||||
@app.route("/api/options/spot/swap", methods=["POST"])
|
||||
@@ -805,7 +821,10 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
amount = float(data.get("amount"))
|
||||
except (TypeError, ValueError):
|
||||
return jsonify({"ok": False, "msg": "数量无效"})
|
||||
return jsonify(cfg["spot_market_swap_usdt_usdc"](ex, direction=direction, amount=amount))
|
||||
result = cfg["spot_market_swap_usdt_usdc"](ex, direction=direction, amount=amount)
|
||||
if result.get("ok"):
|
||||
_mark_balances_stale(cfg)
|
||||
return jsonify(result)
|
||||
|
||||
@app.route("/api/options/cross-transfer", methods=["POST"])
|
||||
@lr
|
||||
@@ -852,6 +871,7 @@ def register_options_routes(app: Flask, cfg: dict[str, Any]) -> None:
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
_mark_balances_stale(cfg)
|
||||
return jsonify(result)
|
||||
|
||||
@app.route("/api/options/history")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{# 期权设置脚本挂载点(卡片在 settings_panel 中拆分) #}
|
||||
<div id="options-settings-root" hidden
|
||||
data-sub-account="{{ instance_settings.options_sub_account | default('', true) }}"></div>
|
||||
<script src="/static/options_settings.js?v=6"></script>
|
||||
<script src="/static/options_settings.js?v=7"></script>
|
||||
|
||||
Reference in New Issue
Block a user