Rebrand product and enhance tradable symbols table with spec columns and K-line links.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-26 03:18:42 +08:00
parent ab9987e4c7
commit 4eb5709d71
30 changed files with 178 additions and 57 deletions
+33 -4
View File
@@ -12,6 +12,7 @@ import math
from datetime import datetime
from typing import Callable, Optional
from contract_specs import get_contract_spec
from fee_specs import ensure_fee_rates_schema
from product_recommend import _attach_turnover, list_product_recommendations
from recommend_trend import sort_recommend_by_trend
@@ -71,6 +72,12 @@ def rows_missing_turnover(rows: list[dict]) -> bool:
return any("turnover" not in r for r in rows)
def rows_missing_contract_spec(rows: list[dict]) -> bool:
if not rows:
return False
return any("mult" not in r or "tick_size" not in r for r in rows)
def recommend_cache_needs_refresh(
cached: dict,
*,
@@ -90,6 +97,8 @@ def recommend_cache_needs_refresh(
return True
if rows_missing_turnover(rows):
return True
if rows_missing_contract_spec(rows):
return True
if float(capital or 0) > 0 and not rows:
return True
return False
@@ -107,23 +116,43 @@ def enrich_recommend_rows(
pct = max(1.0, min(100.0, float(max_margin_pct or 30.0)))
budget = cap * pct / 100.0 if cap > 0 else 0.0
ctp_connected = False
ctp_lookup_spec = None
ctp_estimate_margin_one_lot_fn = None
try:
from vnpy_bridge import ctp_estimate_margin_one_lot, ctp_status
from vnpy_bridge import ctp_estimate_margin_one_lot, ctp_lookup_contract_spec, ctp_status
ctp_connected = bool(ctp_status(trading_mode).get("connected"))
ctp_lookup_spec = ctp_lookup_contract_spec
ctp_estimate_margin_one_lot_fn = ctp_estimate_margin_one_lot
except Exception:
pass
enriched: list[dict] = []
for raw in rows:
row = dict(raw)
ths = (row.get("ths") or "").strip()
main_code = (row.get("main_code") or "").strip()
spec_code = main_code or (ths + "8888" if ths else "")
if spec_code:
spec = get_contract_spec(spec_code)
if row.get("mult") in (None, ""):
row["mult"] = spec["mult"]
if row.get("tick_size") in (None, ""):
row["tick_size"] = float(spec.get("tick_size") or 1.0)
if ctp_connected and main_code and ctp_lookup_spec:
ctp_spec = ctp_lookup_spec(trading_mode, main_code)
if ctp_spec:
if ctp_spec.get("mult"):
row["mult"] = ctp_spec["mult"]
if ctp_spec.get("tick_size"):
row["tick_size"] = ctp_spec["tick_size"]
row["spec_source"] = "ctp"
margin_one = 0.0
try:
margin_one = float(row.get("margin_one_lot") or 0)
except (TypeError, ValueError):
margin_one = 0.0
price = float(row.get("price") or 0)
main_code = (row.get("main_code") or "").strip()
if ctp_connected and main_code and price > 0:
ctp_margin = ctp_estimate_margin_one_lot(trading_mode, main_code, price)
if ctp_connected and main_code and price > 0 and ctp_estimate_margin_one_lot_fn:
ctp_margin = ctp_estimate_margin_one_lot_fn(trading_mode, main_code, price)
if ctp_margin and ctp_margin > 0:
margin_one = ctp_margin
row["margin_one_lot"] = ctp_margin