Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions notifications/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
localize_notification_text as _base_localize_notification_text,
)

try:
from quant_platform_kit.common.notification_localization import (
merge_strategy_plugin_i18n as _merge_strategy_plugin_i18n,
)
except ImportError: # pragma: no cover - compatibility with older pinned shared wheels
_merge_strategy_plugin_i18n = None

_PRICE_SOURCE_LABELS = {
"longbridge_candlesticks": ("LongBridge 日线K线", "LongBridge daily candlesticks"),
"schwab_daily_history_with_live_quote_overlay": ("Schwab 日线历史", "Schwab daily history"),
Expand Down Expand Up @@ -148,7 +155,7 @@ def format_small_account_cash_substitution_notes(
"strategy_plugin_name_macro_risk_governor": "宏观风险控制通知",
"strategy_plugin_name_market_regime_control": "市场状态控制通知",
"strategy_plugin_name_panic_reversal_shadow": "恐慌反转观察通知",
"strategy_plugin_name_taco_rebound_shadow": "TACO 抄底观察通知",
"strategy_plugin_name_taco_rebound_shadow": "TACO 反弹观察通知",
"strategy_plugin_mode_shadow": "影子观察",
"strategy_plugin_route_blocked": "已阻断",
"strategy_plugin_route_crisis": "危机",
Expand Down Expand Up @@ -396,6 +403,9 @@ def format_small_account_cash_substitution_notes(
},
}

if _merge_strategy_plugin_i18n is not None:
I18N = _merge_strategy_plugin_i18n(I18N)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve local strategy-plugin labels when merging

When the new QuantPlatformKit pin is installed, _merge_strategy_plugin_i18n is present and its default merge policy lets the shared strings overwrite existing entries. Calling it without shared_wins=False means this module’s local strategy-plugin labels are no longer authoritative in production, so local formatting/wording such as the existing Telegram strategy_plugin_line output is replaced instead of only filling missing keys. If the local labels are intended to remain the fallback/override set, merge with local values winning.

Useful? React with 👍 / 👎.



def build_translator(lang: str | None) -> Callable[..., str]:
normalized = str(lang or "").lower()
Expand Down Expand Up @@ -424,7 +434,7 @@ def send_tg_message(message: str) -> None:
try:
requests_module.post(url, json={"chat_id": chat_id, "text": message}, timeout=15)
except Exception as exc:
print(f"Telegram send failed: {exc}", flush=True)
print(f"Telegram send failed: {type(exc).__name__}", flush=True)

return send_tg_message

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ authors = [
]
dependencies = [
"firstrade==0.0.39",
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@c6e221f71d7be4d8b1c8c94ce05452c3116e0c10",
"us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@2b02dc947d99a593d2bbae4833f0eeeffc2eecd2",
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@d26e8019a0d7d9f1947a0e11bf8829520db60c98",
"us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@ad3b3f72bab07d786f399709b4301ab32a70142b",
"google-cloud-storage",
"requests",
]
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
flask
gunicorn
firstrade==0.0.39
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@c6e221f71d7be4d8b1c8c94ce05452c3116e0c10
us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@2b02dc947d99a593d2bbae4833f0eeeffc2eecd2
quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@d26e8019a0d7d9f1947a0e11bf8829520db60c98
us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@ad3b3f72bab07d786f399709b4301ab32a70142b
google-cloud-storage
requests
pytest
2 changes: 1 addition & 1 deletion scripts/cloud_run_runtime_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _send_telegram(message: str) -> bool:
print(f"Telegram returned HTTP {response.status}", file=sys.stderr)
except Exception as exc: # noqa: BLE001
ok = False
print(f"Telegram send failed: {exc}", file=sys.stderr)
print(f"Telegram send failed: {type(exc).__name__}", file=sys.stderr)
return ok


Expand Down
2 changes: 1 addition & 1 deletion scripts/execution_report_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _send_telegram(message: str) -> bool:
ok = ok and response.status < 400
except Exception as exc: # noqa: BLE001
ok = False
print(f"Telegram send failed: {exc}", file=sys.stderr)
print(f"Telegram send failed: {type(exc).__name__}", file=sys.stderr)
return ok


Expand Down