Refine market alert wording and focus digest scheduling

This commit is contained in:
2569718930@qq.com
2026-04-01 18:56:39 +08:00
parent 5fa69556eb
commit 4f017d501b
3 changed files with 8 additions and 38 deletions
+4 -4
View File
@@ -808,7 +808,7 @@ def _build_advice_cn(
parts.append("实测已击穿主流模型上沿") parts.append("实测已击穿主流模型上沿")
if not parts: if not parts:
return "当前未触发高优先级天气异动,继续观察实测与模型联动。" return "当前未触发高优先级关键信号,继续观察实测与模型联动。"
return "".join(parts) + "" return "".join(parts) + ""
@@ -934,8 +934,8 @@ def _build_telegram_messages(
advice = _build_advice_cn(rules, temp_symbol, suppression=suppression) advice = _build_advice_cn(rules, temp_symbol, suppression=suppression)
final_map = map_url or "https://polyweather-pro.vercel.app/" final_map = map_url or "https://polyweather-pro.vercel.app/"
title_zh = "🚨 PolyWeather 异动预警" if has_active_trigger else "📍 PolyWeather 状态快照" title_zh = "🚨 PolyWeather 市场提醒" if has_active_trigger else "📍 PolyWeather 状态快照"
title_en = "🚨 PolyWeather Alert" if has_active_trigger else "📍 PolyWeather Status" title_en = "🚨 PolyWeather Market Alert" if has_active_trigger else "📍 PolyWeather Status"
lines_zh = [ lines_zh = [
f"{title_zh} [{city_name}]", f"{title_zh} [{city_name}]",
@@ -1139,7 +1139,7 @@ def _build_telegram_messages_mispricing(
elif snapshot.get("available"): elif snapshot.get("available"):
title_zh = "📍 PolyWeather 市场观察" title_zh = "📍 PolyWeather 市场观察"
else: else:
title_zh = "🚨 PolyWeather 异动预警" if (has_active_trigger or suppressed) else "📍 PolyWeather 状态快照" title_zh = "🚨 PolyWeather 市场提醒" if (has_active_trigger or suppressed) else "📍 PolyWeather 状态快照"
lines_zh = [f"{title_zh} [{city_name}]"] lines_zh = [f"{title_zh} [{city_name}]"]
lines_zh.append("") lines_zh.append("")
+2 -7
View File
@@ -153,15 +153,10 @@ class StartupCoordinator:
def _start_trade_alert_loop(self) -> LoopStatus: def _start_trade_alert_loop(self) -> LoopStatus:
enabled = _env_bool("TELEGRAM_ALERT_PUSH_ENABLED", True) enabled = _env_bool("TELEGRAM_ALERT_PUSH_ENABLED", True)
chat_ids = get_telegram_chat_ids_from_env() chat_ids = get_telegram_chat_ids_from_env()
mispricing_only = _env_bool("TELEGRAM_ALERT_MISPRICING_ONLY", True) interval = max(60, _env_int("TELEGRAM_ALERT_PUSH_INTERVAL_SEC", 300))
interval = (
max(300, _env_int("TELEGRAM_ALERT_MISPRICING_INTERVAL_SEC", 7200))
if mispricing_only
else max(60, _env_int("TELEGRAM_ALERT_PUSH_INTERVAL_SEC", 300))
)
cities_count = _parse_csv_count(os.getenv("TELEGRAM_ALERT_CITIES")) cities_count = _parse_csv_count(os.getenv("TELEGRAM_ALERT_CITIES"))
details = { details = {
"mode": "mispricing-only" if mispricing_only else "full", "mode": "focus-digest-only",
"interval_sec": interval, "interval_sec": interval,
"cities_count": cities_count, "cities_count": cities_count,
"chat_targets": len(chat_ids), "chat_targets": len(chat_ids),
+2 -27
View File
@@ -961,16 +961,7 @@ def start_trade_alert_push_loop(bot: Any, config: Dict[str, Any]) -> Optional[th
logger.warning("telegram market monitor loop skipped: TELEGRAM_CHAT_IDS is not set") logger.warning("telegram market monitor loop skipped: TELEGRAM_CHAT_IDS is not set")
return None return None
mispricing_only = _env_bool("TELEGRAM_ALERT_MISPRICING_ONLY", True) interval_sec = max(60, _env_int("TELEGRAM_ALERT_PUSH_INTERVAL_SEC", 300))
if mispricing_only:
interval_sec = max(
300, _env_int("TELEGRAM_ALERT_MISPRICING_INTERVAL_SEC", 7200)
)
else:
interval_sec = max(60, _env_int("TELEGRAM_ALERT_PUSH_INTERVAL_SEC", 300))
cooldown_sec = max(interval_sec, _env_int("TELEGRAM_ALERT_PUSH_COOLDOWN_SEC", 1800))
min_trigger_count = max(1, _env_int("TELEGRAM_ALERT_MIN_TRIGGER_COUNT", 2))
min_severity = os.getenv("TELEGRAM_ALERT_MIN_SEVERITY", "medium").strip().lower()
cities = _parse_city_list(os.getenv("TELEGRAM_ALERT_CITIES")) cities = _parse_city_list(os.getenv("TELEGRAM_ALERT_CITIES"))
state_path = _state_file() state_path = _state_file()
focus_digest_enabled = _env_bool("TELEGRAM_MARKET_FOCUS_DIGEST_ENABLED", True) focus_digest_enabled = _env_bool("TELEGRAM_MARKET_FOCUS_DIGEST_ENABLED", True)
@@ -989,9 +980,8 @@ def start_trade_alert_push_loop(bot: Any, config: Dict[str, Any]) -> Optional[th
except Exception: except Exception:
logger.exception(f"failed to initialize market monitor state path={state_path}") logger.exception(f"failed to initialize market monitor state path={state_path}")
logger.info( logger.info(
f"telegram market monitor loop started mode={'mispricing-only' if mispricing_only else 'full'} " f"telegram market monitor loop started mode=focus-digest-only "
f"cities={len(cities)} interval={interval_sec}s chat_targets={len(chat_ids)} " f"cities={len(cities)} interval={interval_sec}s chat_targets={len(chat_ids)} "
f"cooldown={cooldown_sec}s min_triggers={min_trigger_count} min_severity={min_severity} "
f"focus_digest_enabled={focus_digest_enabled} focus_hours={focus_digest_hours} " f"focus_digest_enabled={focus_digest_enabled} focus_hours={focus_digest_hours} "
f"state_path={state_path}" f"state_path={state_path}"
) )
@@ -1005,21 +995,6 @@ def start_trade_alert_push_loop(bot: Any, config: Dict[str, Any]) -> Optional[th
try: try:
alert_payload = build_trade_alert_for_city(city, config) alert_payload = build_trade_alert_for_city(city, config)
cycle_payloads.append(alert_payload) cycle_payloads.append(alert_payload)
if _maybe_send_alert(
bot=bot,
chat_ids=chat_ids,
city=city,
alert_payload=alert_payload,
state=state,
cooldown_sec=cooldown_sec,
min_severity=min_severity,
min_trigger_count=min_trigger_count,
mispricing_only=mispricing_only,
):
try:
_save_state(state_path, state)
except Exception:
logger.exception(f"failed to save market monitor state city={city}")
except Exception: except Exception:
logger.exception(f"telegram market monitor loop failed for city={city}") logger.exception(f"telegram market monitor loop failed for city={city}")
time.sleep(1) time.sleep(1)