From 125cc60a3d4c30278e46996a1c8a6838b3b4bb35 Mon Sep 17 00:00:00 2001 From: dekun Date: Fri, 3 Jul 2026 06:34:12 +0800 Subject: [PATCH] Fix positions 500 when recommend row lacks turnover field. Use Jinja defined check in trade template and always set turnover key (or null) when enriching recommend rows. Co-authored-by: Cursor --- modules/trading/product_recommend.py | 3 +++ modules/web/templates/trade.html | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/trading/product_recommend.py b/modules/trading/product_recommend.py index 480c70b..4623925 100644 --- a/modules/trading/product_recommend.py +++ b/modules/trading/product_recommend.py @@ -141,9 +141,12 @@ def _attach_turnover(row: dict) -> None: price = float(row.get("prev_close") or row.get("price") or 0) mult = float(row.get("mult") or 0) except (TypeError, ValueError): + row["turnover"] = None return if vol > 0 and price > 0 and mult > 0: row["turnover"] = round(vol * price * mult, 2) + else: + row["turnover"] = None def _letters_from_ths(ths_code: str) -> str: diff --git a/modules/web/templates/trade.html b/modules/web/templates/trade.html index e56c6e5..ba68e54 100644 --- a/modules/web/templates/trade.html +++ b/modules/web/templates/trade.html @@ -251,7 +251,7 @@ {% if r.yesterday_amplitude_pct is not none %}{{ '%.2f'|format(r.yesterday_amplitude_pct) }}%{% else %}—{% endif %} {% if r.volume is not none %}{{ r.volume }}{% else %}—{% endif %} - {% if r.turnover is not none %}{{ '%.0f'|format(r.turnover) }}{% else %}—{% endif %} + {% if r.turnover is defined and r.turnover is not none %}{{ '%.0f'|format(r.turnover) }}{% else %}—{% endif %} {% if r.mult is not none %}{{ '%g'|format(r.mult) }}{% if r.spec_source == 'ctp' %} (柜台){% endif %}{% else %}—{% endif %} {% if r.tick_size is not none %}{{ '%g'|format(r.tick_size) }}{% if r.spec_source == 'ctp' %} (柜台){% endif %}{% else %}—{% endif %} {% if r.margin_one_lot %}{{ r.margin_one_lot }}{% if r.margin_source == 'ctp' %} (柜台){% endif %}{% else %}—{% endif %}