Show product name, main contract badge, and exchange on position cards.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-26 10:55:37 +08:00
parent 42f2dad52a
commit deb9501cbe
4 changed files with 78 additions and 13 deletions
+33
View File
@@ -458,6 +458,39 @@ def _product_for_ths(ths: str) -> Optional[dict]:
return _THS_TO_PRODUCT.get(key) or _THS_TO_PRODUCT.get(key.lower())
def _product_for_contract_code(ths_code: str) -> Optional[dict]:
sym = (ths_code or "").strip()
if not sym:
return None
m = re.match(r"^([A-Za-z]+)", sym)
if not m:
return None
return _find_product_by_letters(m.group(1))
def position_symbol_meta(ths_code: str) -> dict:
"""持仓/委托展示:品种名、交易所、是否主力合约。"""
sym = (ths_code or "").strip()
if not sym:
return {"name": "", "exchange": "", "is_main": False}
product = _product_for_contract_code(sym)
if not product:
return {"name": sym, "exchange": "", "is_main": False}
codes = ths_to_codes(sym)
norm = (codes["ths_code"] if codes else sym).strip().lower()
is_main = False
with _main_index_lock:
main_item = _main_index.get(product["sina"])
if main_item:
main_ths = (main_item.get("ths_code") or "").strip().lower()
is_main = main_ths == norm or main_ths == sym.lower()
return {
"name": product["name"],
"exchange": product.get("exchange") or "",
"is_main": is_main,
}
def _item_from_recommend_row(row: dict, product: dict) -> Optional[dict]:
"""由可开仓缓存行快速构造下拉项(不在 HTTP 请求中解析主力)。"""
name = row.get("name") or product["name"]