fix(hub): restore pre-WS quote path and relieve Gate/account contention
Two audit rounds after WS rollback: lighten hub options snapshot, cache hub balances without extra fetch_balance, soft-poll single-flight, and document fixes in R1/R2 reports. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -2028,7 +2028,8 @@ async def _fetch_flask_json(
|
||||
return parsed
|
||||
return _parse_http_json_body(r)
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": str(e)}
|
||||
err = str(e)
|
||||
return {"ok": False, "error": err, "msg": err}
|
||||
|
||||
|
||||
async def _notify_instance_user_close(
|
||||
@@ -2567,8 +2568,8 @@ def _merge_flask_exchange_tpsl(agent_row: dict, snap: dict | None, hub_mon: dict
|
||||
|
||||
async def _fetch_exchange_flask_bundle(
|
||||
client: httpx.AsyncClient, ex: dict, *, trading_day: str | None = None
|
||||
) -> tuple[dict | None, dict | None, list | None, dict | None, dict | None, dict | None]:
|
||||
"""单所 Flask:monitor / meta / price_snapshot / account / trades/today(有 flask_url 时)并行拉取."""
|
||||
) -> tuple:
|
||||
"""单所 Flask:monitor / meta / price_snapshot / account / trades/today / options 并行拉取."""
|
||||
caps = ex.get("capabilities") or []
|
||||
tasks = [
|
||||
_fetch_flask_json(client, ex, "/api/hub/monitor"),
|
||||
@@ -2576,6 +2577,7 @@ async def _fetch_exchange_flask_bundle(
|
||||
]
|
||||
has_flask = bool((ex.get("flask_url") or "").strip())
|
||||
day = (trading_day or "").strip()
|
||||
want_options = has_flask and "options" in caps
|
||||
if has_flask:
|
||||
tasks.extend(
|
||||
[
|
||||
@@ -2592,15 +2594,26 @@ async def _fetch_exchange_flask_bundle(
|
||||
params={"trading_day": day},
|
||||
)
|
||||
)
|
||||
if want_options:
|
||||
tasks.append(_fetch_flask_json(client, ex, "/api/hub/options/snapshot"))
|
||||
results = await asyncio.gather(*tasks)
|
||||
hub_mon = results[0]
|
||||
meta = results[1]
|
||||
snap = results[2] if has_flask and len(results) > 2 else None
|
||||
account = results[3] if has_flask and len(results) > 3 else None
|
||||
trades_today = results[4] if has_flask and day and len(results) > 4 else None
|
||||
idx = 2
|
||||
snap = None
|
||||
account = None
|
||||
trades_today = None
|
||||
options_snap = None
|
||||
if has_flask and "options" in caps:
|
||||
options_snap = await _fetch_flask_json(client, ex, "/api/hub/options/snapshot")
|
||||
if has_flask:
|
||||
snap = results[idx]
|
||||
idx += 1
|
||||
account = results[idx]
|
||||
idx += 1
|
||||
if day:
|
||||
trades_today = results[idx]
|
||||
idx += 1
|
||||
if want_options:
|
||||
options_snap = results[idx]
|
||||
key_prices = None
|
||||
want_prices = HUB_BOARD_KEY_PRICES and "key" in caps
|
||||
if want_prices and isinstance(snap, dict):
|
||||
|
||||
Reference in New Issue
Block a user