diff --git a/main.py b/main.py index 742b98d..346773b 100644 --- a/main.py +++ b/main.py @@ -464,6 +464,20 @@ def build_strategy_plugin_notification_lines(signals) -> tuple[str, ...]: return build_strategy_adapters().build_strategy_plugin_notification_lines(signals) +def build_account_notification_lines() -> tuple[str, ...]: + account_ids = tuple(str(account_id).strip() for account_id in ACCOUNT_IDS if str(account_id).strip()) + if not account_ids: + return () + return (t("account_ids_detail", account_ids=", ".join(account_ids)),) + + +def build_extra_notification_lines(strategy_plugin_signals=()) -> tuple[str, ...]: + return ( + *build_account_notification_lines(), + *build_strategy_plugin_notification_lines(strategy_plugin_signals), + ) + + def get_current_portfolio(ib): return build_broker_adapters().get_current_portfolio(ib) @@ -522,9 +536,7 @@ def run_strategy_core(*, strategy_plugin_signals=()): composer = build_composer() return run_rebalance_cycle( runtime=composer.build_rebalance_runtime(), - config=composer.build_rebalance_config( - extra_notification_lines=build_strategy_plugin_notification_lines(strategy_plugin_signals) - ), + config=composer.build_rebalance_config(extra_notification_lines=build_extra_notification_lines(strategy_plugin_signals)), ) diff --git a/notifications/telegram.py b/notifications/telegram.py index 5d11945..022fe38 100644 --- a/notifications/telegram.py +++ b/notifications/telegram.py @@ -10,6 +10,7 @@ "error_title": "🚨 【策略异常】", "canary_title": "🐤 【金丝雀检查】", "strategy_label": "🧭 策略: {name}", + "account_ids_detail": "🆔 账户: {account_ids}", "equity": "净值", "buying_power": "购买力", "reserved_cash": "预留现金", @@ -76,11 +77,9 @@ "strategy_plugin_mode_shadow": "影子观察", "strategy_plugin_route_no_action": "未触发危机", "strategy_plugin_route_true_crisis": "真危机", - "strategy_plugin_route_taco_fake_crisis": "TACO 假危机", "strategy_plugin_route_unknown_route": "未知状态", "strategy_plugin_action_no_action": "不操作", "strategy_plugin_action_watch_only": "仅通知", - "strategy_plugin_action_small_taco": "小仓 TACO", "strategy_plugin_action_defend": "防守", "strategy_plugin_action_blocked": "已阻断", "strategy_plugin_action_monitor": "持续观察", @@ -117,6 +116,7 @@ "error_title": "🚨 【Strategy Error】", "canary_title": "🐤 【Canary Check】", "strategy_label": "🧭 Strategy: {name}", + "account_ids_detail": "🆔 Account: {account_ids}", "equity": "Equity", "buying_power": "Buying Power", "reserved_cash": "Reserved Cash", @@ -183,11 +183,9 @@ "strategy_plugin_mode_shadow": "shadow", "strategy_plugin_route_no_action": "no crisis detected", "strategy_plugin_route_true_crisis": "true crisis", - "strategy_plugin_route_taco_fake_crisis": "TACO fake crisis", "strategy_plugin_route_unknown_route": "unknown status", "strategy_plugin_action_no_action": "no action", "strategy_plugin_action_watch_only": "notify only", - "strategy_plugin_action_small_taco": "small TACO", "strategy_plugin_action_defend": "defend", "strategy_plugin_action_blocked": "blocked", "strategy_plugin_action_monitor": "watch", diff --git a/tests/conftest.py b/tests/conftest.py index fba3933..2e1e48b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,7 +26,7 @@ def load_strategy_module(**env_overrides): "IBKR_RECONCILIATION_OUTPUT_PATH": None, "IB_ACCOUNT_GROUP_CONFIG_JSON": ( '{"groups":{"default":{"ib_gateway_instance_name":"127.0.0.1",' - '"ib_gateway_mode":"live","ib_client_id":1}}}' + '"ib_gateway_mode":"live","ib_client_id":1,"account_ids":["U18308207"]}}}' ), "IB_ACCOUNT_GROUP_CONFIG_SECRET_NAME": None, "GLOBAL_TELEGRAM_CHAT_ID": None, diff --git a/tests/test_notifications.py b/tests/test_notifications.py index 5c043ec..dfcf447 100644 --- a/tests/test_notifications.py +++ b/tests/test_notifications.py @@ -46,6 +46,7 @@ def test_build_translator_supports_chinese(): ) == "🧩 插件:危机观察通知 | 状态:未触发危机 | 提醒:仅通知" ) + assert translate("account_ids_detail", account_ids="U18308207") == "🆔 账户: U18308207" assert ( translate( "small_account_warning_note", diff --git a/tests/test_request_handling.py b/tests/test_request_handling.py index e92cbc1..fe909d1 100644 --- a/tests/test_request_handling.py +++ b/tests/test_request_handling.py @@ -32,6 +32,11 @@ def fake_run_strategy_core(**_kwargs): assert observed["called"] is True +def test_build_extra_notification_lines_includes_account_id(strategy_module): + lines = strategy_module.build_extra_notification_lines(()) + assert any("U18308207" in line for line in lines) + + def test_handle_request_skips_overlapping_post(strategy_module, monkeypatch): observed = {}