fix(okx): cache options balances and stop SSE from hammering exchange API
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+11
-17
@@ -6516,15 +6516,11 @@ def render_main_page(page="trade", embed_mode=None):
|
||||
and embed_mode != "fragment"
|
||||
):
|
||||
try:
|
||||
from lib.exchange.okx_options_lib import (
|
||||
fetch_options_funding_usdc,
|
||||
fetch_options_funding_usdt,
|
||||
fetch_options_trading_usdc,
|
||||
)
|
||||
from lib.exchange.okx_options_lib import options_header_balances
|
||||
|
||||
options_trading_usdc = fetch_options_trading_usdc(exchange_options)
|
||||
options_funding_usdc = fetch_options_funding_usdc(exchange_options)
|
||||
options_funding_usdt = fetch_options_funding_usdt(exchange_options)
|
||||
options_trading_usdc, options_funding_usdc, options_funding_usdt = options_header_balances(
|
||||
exchange_options
|
||||
)
|
||||
except Exception:
|
||||
options_trading_usdc = None
|
||||
options_funding_usdc = None
|
||||
@@ -6838,7 +6834,8 @@ def api_account_snapshot():
|
||||
conn = get_db()
|
||||
session_row = ensure_session(conn, trading_day)
|
||||
local_current_capital = float(session_row["current_capital"])
|
||||
funding_capital, trading_capital = get_exchange_capitals(force=True)
|
||||
force_refresh = (request.args.get("force") or "").strip().lower() in ("1", "true", "yes")
|
||||
funding_capital, trading_capital = get_exchange_capitals(force=force_refresh)
|
||||
funding_usdt = round(funding_capital, FUNDS_DECIMALS) if funding_capital is not None else None
|
||||
current_capital = round(trading_capital, FUNDS_DECIMALS) if trading_capital is not None else round(local_current_capital, FUNDS_DECIMALS)
|
||||
options_trading_usdc = None
|
||||
@@ -6846,15 +6843,12 @@ def api_account_snapshot():
|
||||
options_funding_usdt = None
|
||||
if OKX_OPTIONS_ENABLED and exchange_options.apiKey:
|
||||
try:
|
||||
from lib.exchange.okx_options_lib import (
|
||||
fetch_options_funding_usdc,
|
||||
fetch_options_funding_usdt,
|
||||
fetch_options_trading_usdc,
|
||||
)
|
||||
from lib.exchange.okx_options_lib import options_header_balances
|
||||
|
||||
options_trading_usdc = fetch_options_trading_usdc(exchange_options)
|
||||
options_funding_usdc = fetch_options_funding_usdc(exchange_options)
|
||||
options_funding_usdt = fetch_options_funding_usdt(exchange_options)
|
||||
options_trading_usdc, options_funding_usdc, options_funding_usdt = options_header_balances(
|
||||
exchange_options,
|
||||
force=force_refresh,
|
||||
)
|
||||
except Exception:
|
||||
options_trading_usdc = None
|
||||
options_funding_usdc = None
|
||||
|
||||
Reference in New Issue
Block a user