fix(HEL-164): 撤回盘后刷新改动并恢复原逻辑

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
总管
2026-08-28 09:05:42 +00:00
co-authored by multica-agent
parent 6d7a839202
commit f27471238a
5 changed files with 22 additions and 278 deletions
+13 -3
View File
@@ -26,8 +26,18 @@ class DashboardMixin:
)
daily = self._load_daily(trade_date)
if (
not daily
and requested_date == datetime.now().astimezone().strftime("%Y%m%d")
and trade_date == requested_date
and datetime.now().astimezone().time().replace(tzinfo=None) >= dt_time(9, 15)
):
return self._realtime_dashboard(
requested_date,
trade_date,
previous_trade_date,
)
if not daily:
# 15:05 后只走日线;日线未就绪时不得回退调用无权限的 rt_k。
raise TushareError(f"No daily data returned for {trade_date}")
notices: list[str] = []
@@ -86,13 +96,13 @@ class DashboardMixin:
@staticmethod
def should_use_realtime(requested_date: str, trade_date: str) -> bool:
"""Use rt_k only inside the intraday window; 15:05+ must use daily bars."""
"""Use rt_k for today's open market until end-of-day datasets settle."""
now = datetime.now().astimezone()
today = now.strftime("%Y%m%d")
return (
requested_date == today
and trade_date == today
and dt_time(9, 15) <= now.time().replace(tzinfo=None) < dt_time(15, 5)
and dt_time(9, 15) <= now.time().replace(tzinfo=None) < dt_time(16, 30)
)
def _realtime_dashboard(
+2 -33
View File
@@ -188,30 +188,6 @@ class MarketServiceMixin:
age_seconds = (now - updated_at.astimezone(now.tzinfo)).total_seconds()
return age_seconds >= 8
def _closing_snapshot_due(
self,
normalized_date: str,
snapshot: dict[str, Any],
) -> bool:
"""After 15:05, keep requesting daily bars until today's EOD snapshot exists."""
if not self.configured or normalized_date != date.today().strftime("%Y%m%d"):
return False
now = datetime.now().astimezone()
if now.weekday() >= 5:
return False
local_time = now.time().replace(tzinfo=None)
if local_time < datetime.strptime("15:05", "%H:%M").time():
return False
meta = snapshot.get("meta") or {}
snapshot_trade_date = str(meta.get("trade_date") or "").replace("-", "")
if (
snapshot_trade_date == normalized_date
and not meta.get("realtime")
and not meta.get("carried_forward")
):
return False
return True
def sync_dashboard(self, trade_date: str) -> dict[str, Any]:
normalized_date = normalize_date(trade_date)
source = "tushare"
@@ -256,15 +232,9 @@ class MarketServiceMixin:
fallback, normalized_date, f"最新行情暂不可用,沿用最近收盘快照:{exc}"
)
self.database.finish_sync(
sync_id, "failed", self._record_count(carried), str(exc), "tushare"
sync_id, "fallback", self._record_count(carried), str(exc), "tushare"
)
result = self._apply_reason_overrides(
self._with_storage(carried, cached=True)
)
# 页面仍可读到沿用快照;后台任务通过顶层 status=failed 记失败。
result["status"] = "failed"
result["error"] = str(exc)
return result
return self._apply_reason_overrides(self._with_storage(carried, cached=True))
self.database.finish_sync(sync_id, "failed", message=str(exc))
raise ValueError("暂无可用的真实行情快照,请等待后台完成首次同步。") from exc
except Exception as exc:
@@ -1193,4 +1163,3 @@ class MarketServiceMixin:
len(dashboard.get(key) or [])
for key in ("limits", "broken", "down_limits", "yesterday_limits")
)
-9
View File
@@ -46,13 +46,4 @@ class JobServiceMixin:
lambda: self.sync_dashboard(today),
{"trade_date": today, "trigger": "realtime-poll"},
)
elif self._closing_snapshot_due(today, snapshot):
# 15:05 后改走日线生成当日快照;按分钟去重,避免日线未就绪时刷爆任务。
bucket = int(time.time() // 60)
self.jobs.submit(
"market.refresh",
f"closing:{today}:{bucket}",
lambda: self.sync_dashboard(today),
{"trade_date": today, "trigger": "post-close"},
)
self._schedule_automatic_screeners(today, snapshot)