feat: complete strategy and market data improvements

This commit is contained in:
leefer
2026-07-29 16:50:40 +08:00
parent c30d2107b3
commit 0030bb8cc1
18 changed files with 1622 additions and 162 deletions
+19 -10
View File
@@ -668,8 +668,8 @@ class MarketInsightsService:
start_stamp = f"{display_date} 09:15:00"
snapshot_rows: list[dict[str, Any]] = []
ordered_codes = sorted(selected_codes)
try:
for index in range(0, len(ordered_codes), 80):
for index in range(0, len(ordered_codes), 80):
try:
snapshot_rows.extend(
self.ifind.snapshots(
ordered_codes[index:index + 80],
@@ -682,13 +682,18 @@ class MarketInsightsService:
cache_ttl=8,
)
)
except IfindError:
return []
except IfindError:
continue
latest: dict[str, dict[str, Any]] = {}
for row in snapshot_rows:
ts_code = str(row.get("thscode") or "")
if ts_code and _number(row.get("latest")) > 0:
previous = latest.get(ts_code) or {}
if (
ts_code
and _number(row.get("latest")) > 0
and str(row.get("time") or "") >= str(previous.get("time") or "")
):
latest[ts_code] = row
prior_factors = {
str(item.get("ts_code") or ""): item
@@ -735,11 +740,13 @@ class MarketInsightsService:
trade_date, previous_date = self._trade_context(requested_date)
session = self._auction_session(requested_date, trade_date)
phase = str(session["phase"])
dynamic = phase == "observing" and bool(self.ifind and self.ifind.configured)
data_date = previous_date if phase == "pending" or (phase == "observing" and not dynamic) else trade_date
ifind_ready = bool(self.ifind and self.ifind.configured)
live_dynamic = phase == "observing" and ifind_ready
use_ifind_snapshot = phase in {"observing", "selection", "finalized"} and ifind_ready
data_date = previous_date if phase == "pending" or (phase == "observing" and not live_dynamic) else trade_date
carried_forward = data_date != trade_date
cache_key = data_date
if not force and not dynamic:
if not force and not live_dynamic:
cached = self.database.get_data_snapshot("auction_center_v6", cache_key)
if cached:
result = copy.deepcopy(cached)
@@ -754,9 +761,11 @@ class MarketInsightsService:
}
return self._with_auction_watchlist(result, data_date, user_id)
if dynamic:
if use_ifind_snapshot:
rows = self._dynamic_auction_rows(data_date, previous_date, user_id)
else:
rows = []
if not rows and not live_dynamic:
try:
rows = self.client.query("stk_auction", {"trade_date": data_date})
except TushareError:
@@ -927,7 +936,7 @@ class MarketInsightsService:
"one_price_rows": one_price_rows,
"rows": candidates,
}
if not dynamic:
if not live_dynamic:
self.database.save_data_snapshot("auction_center_v6", cache_key, "market", result)
return self._with_auction_watchlist(result, data_date, user_id)