feat: Introduce automated Telegram trade alert push and add target date option to /tradealert command.

This commit is contained in:
2569718930@qq.com
2026-03-06 10:40:39 +08:00
parent bec76e3977
commit ba992f7d80
2 changed files with 35 additions and 7 deletions
+28 -4
View File
@@ -242,16 +242,36 @@ def start_bot():
def tradealert_preview(message):
"""Preview the current trade-alert push payload for one city."""
try:
parts = message.text.split(maxsplit=1)
parts = message.text.split()
if len(parts) < 2:
bot.reply_to(
message,
"用法: <code>/tradealert ankara</code>",
"用法: <code>/tradealert ankara</code> 或 <code>/tradealert ankara 2026-03-06</code>",
parse_mode="HTML",
)
return
target_date = None
city_tokens = parts[1:]
if city_tokens:
last_token = city_tokens[-1].strip()
try:
from datetime import datetime as _dt
_dt.strptime(last_token, "%Y-%m-%d")
target_date = last_token
city_tokens = city_tokens[:-1]
except Exception:
pass
city_input = " ".join(city_tokens).strip().lower()
if not city_input:
bot.reply_to(
message,
"用法: <code>/tradealert ankara</code> 或 <code>/tradealert ankara 2026-03-06</code>",
parse_mode="HTML",
)
return
city_input = parts[1].strip().lower()
city_name = ALIASES.get(city_input)
if not city_name and city_input in CITY_REGISTRY:
@@ -278,20 +298,24 @@ def start_bot():
bot.send_message(
message.chat.id,
f"📡 正在生成 {city_name.title()} 的异动预警预览...",
f"📡 正在生成 {city_name.title()} 的异动预警预览"
f"{f' ({target_date})' if target_date else ''}...",
)
payload = build_trade_alert_for_city(
city_name,
config,
force_refresh=True,
target_date=target_date,
)
preview = ((payload.get("telegram") or {}).get("zh") or "").strip()
trigger_count = int(payload.get("trigger_count") or 0)
severity = str(payload.get("severity") or "none")
resolved_date = payload.get("target_date")
header = (
f"[TEST PREVIEW] city={city_name} "
f"date={resolved_date} "
f"severity={severity} triggers={trigger_count}"
)
+7 -3
View File
@@ -3,6 +3,7 @@ import json
import os
import threading
import time
from datetime import datetime
from typing import Any, Dict, List, Optional
from loguru import logger
@@ -138,13 +139,16 @@ def build_trade_alert_for_city(
city: str,
config: Dict[str, Any],
force_refresh: bool = False,
target_date: Optional[str] = None,
) -> Dict[str, Any]:
from web.app import _analyze
from src.analysis.market_alert_engine import build_trading_alerts
from src.data_collection.polymarket_client import build_city_market_snapshot
city_weather = _analyze(city, force_refresh=force_refresh)
target_date = city_weather.get("local_date")
resolved_target_date = target_date or city_weather.get("local_date")
if resolved_target_date:
datetime.strptime(resolved_target_date, "%Y-%m-%d")
proxy = (
(config.get("polymarket", {}) or {}).get("proxy")
@@ -152,7 +156,7 @@ def build_trade_alert_for_city(
)
market_snapshot = build_city_market_snapshot(
city=city,
target_date=target_date,
target_date=resolved_target_date,
proxy=proxy,
force_refresh=force_refresh,
)
@@ -162,7 +166,7 @@ def build_trade_alert_for_city(
market_snapshot=market_snapshot,
map_url=map_url,
)
alert_payload["target_date"] = target_date
alert_payload["target_date"] = resolved_target_date
return alert_payload