chore: follow-ups for PR #231/#233 reviews

- monitor_rules: raise from None in remind_date validation (B904)
- lots: log warning on asset-type fallback to stock (fail-open traceability)
- matrix: demote turnover NaN-column notice to debug
This commit is contained in:
shy3130
2026-09-03 12:45:24 +08:00
parent 8b12fc7a65
commit 41205b197c
3 changed files with 7 additions and 2 deletions
+5
View File
@@ -4,6 +4,7 @@
"""
from __future__ import annotations
import logging
import secrets
import threading
import time
@@ -31,6 +32,10 @@ def _resolve_asset_type(request: Request, symbol: str) -> str:
try:
return repo.resolve_asset_type(symbol) if repo is not None else "stock"
except Exception:
# 回退为 stock 会让 etf 批次的止盈止损规则落入错误的监控轮, 必须留痕排查
logging.getLogger(__name__).warning(
"resolve_asset_type failed for %s, falling back to stock", symbol, exc_info=True
)
return "stock"
+1 -1
View File
@@ -1435,7 +1435,7 @@ def _populate_matrix_derived_arrays(
# 异常, 由 _resolve_matrix_storage_fields 的 vector 装载路径显式失败。
if "float_shares" in vector_fields:
raise ValueError("matrix turnover_rate requires float_shares")
logger.info(
logger.debug(
"turnover_rate unavailable (asset has no float_shares); keeping NaN column"
)
else:
+1 -1
View File
@@ -261,7 +261,7 @@ def validate(rule: dict) -> None:
try:
date.fromisoformat(remind.strip())
except ValueError:
raise ValueError(f"remind_date 必须是 YYYY-MM-DD 日期: {remind!r}")
raise ValueError(f"remind_date 必须是 YYYY-MM-DD 日期: {remind!r}") from None
lead = rule.get("lead_days", 0)
if isinstance(lead, bool) or not isinstance(lead, int) or lead < 0:
raise ValueError("lead_days 必须是非负整数 (提前提醒天数)")