feat: 品种下拉统一展示推荐列表,与下方品种推荐表一致。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+57
@@ -419,6 +419,63 @@ def search_symbols(query: str) -> list:
|
||||
return results
|
||||
|
||||
|
||||
_THS_TO_PRODUCT = {p["ths"]: p for p in PRODUCTS}
|
||||
for _p in PRODUCTS:
|
||||
_THS_TO_PRODUCT.setdefault(_p["ths"].lower(), _p)
|
||||
|
||||
|
||||
def _product_for_ths(ths: str) -> Optional[dict]:
|
||||
key = (ths or "").strip()
|
||||
if not key:
|
||||
return None
|
||||
return _THS_TO_PRODUCT.get(key) or _THS_TO_PRODUCT.get(key.lower())
|
||||
|
||||
|
||||
def _main_for_product(product: dict) -> Optional[dict]:
|
||||
with _main_index_lock:
|
||||
index = dict(_main_index)
|
||||
main = index.get(product["sina"])
|
||||
if not main:
|
||||
resolved = resolve_main_contract(product)
|
||||
if resolved:
|
||||
main = _enrich_item(resolved)
|
||||
return main
|
||||
|
||||
|
||||
def list_recommended_symbols_grouped(recommend_rows: list[dict]) -> list[dict]:
|
||||
"""按交易所分类返回推荐品种对应的主力合约(品种选择下拉用)。"""
|
||||
if not recommend_rows:
|
||||
return []
|
||||
|
||||
buckets: dict[str, list] = defaultdict(list)
|
||||
seen: set[str] = set()
|
||||
for row in recommend_rows:
|
||||
if row.get("status") not in ("ok", "margin_ok"):
|
||||
continue
|
||||
ths_key = (row.get("ths") or "").strip()
|
||||
if not ths_key or ths_key in seen:
|
||||
continue
|
||||
product = _product_for_ths(ths_key)
|
||||
if not product:
|
||||
continue
|
||||
seen.add(ths_key)
|
||||
main = _main_for_product(product)
|
||||
if not main:
|
||||
continue
|
||||
item = dict(main)
|
||||
max_lots = row.get("max_lots")
|
||||
if max_lots is not None:
|
||||
item["max_lots"] = max_lots
|
||||
buckets[product["exchange"]].append(_enrich_item(item))
|
||||
|
||||
groups: list[dict] = []
|
||||
for cat in EXCHANGE_ORDER:
|
||||
items = buckets.get(cat)
|
||||
if items:
|
||||
groups.append({"category": cat, "items": items})
|
||||
return groups
|
||||
|
||||
|
||||
def list_main_contracts_grouped() -> list[dict]:
|
||||
"""按交易所分类返回全部品种主力合约(行情页下拉用)。"""
|
||||
with _main_index_lock:
|
||||
|
||||
Reference in New Issue
Block a user