|
17 | 17 | except ImportError: # pragma: no cover - compatibility with older pinned shared wheels |
18 | 18 | _merge_strategy_plugin_i18n = None |
19 | 19 |
|
| 20 | +_TELEGRAM_MARKET_SYMBOL_LINK_RE = re.compile(r"(?<![A-Za-z0-9_])([A-Z0-9]{1,12})\.([A-Z]{2,4})(?![A-Za-z0-9_])") |
| 21 | +_TELEGRAM_MARKET_SYMBOL_LINK_JOINER = "\u2060" |
| 22 | + |
| 23 | + |
| 24 | +def _break_telegram_market_symbol_auto_links(value: object) -> str: |
| 25 | + text = str(value or "") |
| 26 | + return _TELEGRAM_MARKET_SYMBOL_LINK_RE.sub( |
| 27 | + lambda match: f"{match.group(1)}.{_TELEGRAM_MARKET_SYMBOL_LINK_JOINER}{match.group(2)}", |
| 28 | + text, |
| 29 | + ) |
| 30 | + |
| 31 | + |
20 | 32 | _PRICE_SOURCE_LABELS = { |
21 | 33 | "longbridge_candlesticks": ("LongBridge 日线K线", "LongBridge daily candlesticks"), |
22 | 34 | "schwab_daily_history_with_live_quote_overlay": ("Schwab 日线历史", "Schwab daily history"), |
@@ -185,12 +197,13 @@ def format_small_account_whole_share_bootstrap_notes( |
185 | 197 | "strategy_plugin_line": "🧩 插件:{plugin} | 启用:{enabled} | 状态:{route} | 提醒:{action}", |
186 | 198 | "strategy_plugin_enabled_true": "是", |
187 | 199 | "strategy_plugin_enabled_false": "否", |
188 | | - "strategy_plugin_consumption_auto": "🧩 插件消费:已按策略规则参与本轮仓位计算", |
189 | | - "strategy_plugin_consumption_auto_defend": "🧩 插件消费:已按策略规则参与本轮仓位计算;风险仓位按防守规则处理", |
190 | | - "strategy_plugin_consumption_auto_delever": "🧩 插件消费:已按策略规则参与本轮仓位计算;杠杆仓位按降档规则缩放", |
191 | | - "strategy_plugin_consumption_loaded_not_applied": "🧩 插件消费:已加载但未改写仓位;当前策略未启用该状态的自动消费", |
192 | | - "strategy_plugin_consumption_review_only": "🧩 插件消费:仅通知复核,未参与自动仓位计算", |
193 | | - "strategy_plugin_consumption_unavailable": "🧩 插件消费:未消费插件信号", |
| 200 | + "strategy_plugin_consumption_auto": "🧩 插件本次影响:已按策略规则参与本轮仓位计算", |
| 201 | + "strategy_plugin_consumption_auto_defend": "🧩 插件本次影响:已触发防守规则并参与本轮仓位计算", |
| 202 | + "strategy_plugin_consumption_auto_delever": "🧩 插件本次影响:已触发降杠杆规则并参与本轮仓位计算", |
| 203 | + "strategy_plugin_consumption_loaded_not_applied": "🧩 插件本次影响:已加载;该状态未启用自动仓位改写", |
| 204 | + "strategy_plugin_consumption_review_only": "🧩 插件本次影响:仅通知复核;当前状态未触发自动仓位改写", |
| 205 | + "strategy_plugin_consumption_unavailable": "🧩 插件本次影响:未加载可用插件信号", |
| 206 | + |
194 | 207 | "strategy_plugin_alert_subject": "🚨 策略插件告警:{plugin} | {route}", |
195 | 208 | "strategy_plugin_alert_title": "🚨 【策略插件告警】", |
196 | 209 | "strategy_plugin_alert_context": "运行环境:{context}", |
@@ -346,12 +359,13 @@ def format_small_account_whole_share_bootstrap_notes( |
346 | 359 | "strategy_plugin_line": "🧩 Plugin: {plugin} | enabled: {enabled} | status: {route} | notice: {action}", |
347 | 360 | "strategy_plugin_enabled_true": "yes", |
348 | 361 | "strategy_plugin_enabled_false": "no", |
349 | | - "strategy_plugin_consumption_auto": "🧩 Plugin consumption: included in this cycle's position calculation under strategy rules", |
350 | | - "strategy_plugin_consumption_auto_defend": "🧩 Plugin consumption: included in this cycle's position calculation; risk exposure follows defensive rules", |
351 | | - "strategy_plugin_consumption_auto_delever": "🧩 Plugin consumption: included in this cycle's position calculation; leveraged exposure follows de-risking rules", |
352 | | - "strategy_plugin_consumption_loaded_not_applied": "🧩 Plugin consumption: loaded but did not rewrite positions; this strategy does not enable automatic consumption for this state", |
353 | | - "strategy_plugin_consumption_review_only": "🧩 Plugin consumption: review-only notice, not used for automatic position calculation", |
354 | | - "strategy_plugin_consumption_unavailable": "🧩 Plugin consumption: no plugin signal consumed", |
| 362 | + "strategy_plugin_consumption_auto": "🧩 Plugin impact this run: included in this cycle's position calculation under strategy rules", |
| 363 | + "strategy_plugin_consumption_auto_defend": "🧩 Plugin impact this run: triggered defensive rules and joined this cycle's position calculation", |
| 364 | + "strategy_plugin_consumption_auto_delever": "🧩 Plugin impact this run: triggered de-levering rules and joined this cycle's position calculation", |
| 365 | + "strategy_plugin_consumption_loaded_not_applied": "🧩 Plugin impact this run: loaded; this state did not enable automatic position rewrites", |
| 366 | + "strategy_plugin_consumption_review_only": "🧩 Plugin impact this run: review-only notice; current state did not trigger automatic position rewrites", |
| 367 | + "strategy_plugin_consumption_unavailable": "🧩 Plugin impact this run: no usable plugin signal loaded", |
| 368 | + |
355 | 369 | "strategy_plugin_alert_subject": "🚨 Strategy plugin alert: {plugin} | {route}", |
356 | 370 | "strategy_plugin_alert_title": "🚨 【Strategy Plugin Alert】", |
357 | 371 | "strategy_plugin_alert_context": "Context: {context}", |
@@ -522,7 +536,11 @@ def send_tg_message(message: str) -> None: |
522 | 536 | return |
523 | 537 | url = f"https://api.telegram.org/bot{token}/sendMessage" |
524 | 538 | try: |
525 | | - requests_module.post(url, json={"chat_id": chat_id, "text": message}, timeout=15) |
| 539 | + requests_module.post( |
| 540 | + url, |
| 541 | + json={"chat_id": chat_id, "text": _break_telegram_market_symbol_auto_links(message)}, |
| 542 | + timeout=15, |
| 543 | + ) |
526 | 544 | except Exception as exc: |
527 | 545 | print(f"Telegram send failed: {type(exc).__name__}", flush=True) |
528 | 546 |
|
|
0 commit comments