修复持仓监控页长时间空白:品种推荐改为异步加载。
页面先渲染三卡片,推荐表并行拉行情,持仓与推荐分别通过 API 加载。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""按账户资金推荐可交易品种(期货核心筛选)。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import Callable, Optional
|
||||
|
||||
from contract_specs import get_contract_spec
|
||||
@@ -83,14 +84,16 @@ def list_product_recommendations(
|
||||
max_position_pct: float = 50.0,
|
||||
) -> list[dict]:
|
||||
"""扫描全部品种并排序:推荐 > 可开 > 不足。"""
|
||||
rows = []
|
||||
for p in PRODUCTS:
|
||||
ths = p["ths"]
|
||||
|
||||
def _one(product: dict) -> dict:
|
||||
ths = product["ths"]
|
||||
main_code = price_fn(ths)
|
||||
row = assess_product_for_capital(
|
||||
p, capital, main_code, max_position_pct=max_position_pct
|
||||
return assess_product_for_capital(
|
||||
product, capital, main_code, max_position_pct=max_position_pct
|
||||
)
|
||||
rows.append(row)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=10) as pool:
|
||||
rows = list(pool.map(_one, PRODUCTS))
|
||||
order = {"ok": 0, "margin_ok": 1, "blocked": 2, "no_price": 3}
|
||||
rows.sort(key=lambda r: (order.get(r["status"], 9), r.get("min_capital_one_lot") or 1e18))
|
||||
return rows
|
||||
|
||||
Reference in New Issue
Block a user