From b5e20be66b9c1e06b95ae9aaf4dad54f4893afb8 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Tue, 12 May 2026 05:51:11 +0800 Subject: [PATCH 1/3] Remove crisis plugin TACO copy --- application/runtime_strategy_adapters.py | 4 ++++ notifications/telegram.py | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/application/runtime_strategy_adapters.py b/application/runtime_strategy_adapters.py index 09b74e6..14fa5d4 100644 --- a/application/runtime_strategy_adapters.py +++ b/application/runtime_strategy_adapters.py @@ -47,6 +47,10 @@ def attach_strategy_plugin_report(self, report, *, signals, error: str | None = def translate_strategy_plugin_value(self, category: str, raw_value: str | None) -> str: value = str(raw_value or "").strip() or "unknown" + if category == "route" and value == "taco_fake_crisis": + value = "unknown_route" + elif category == "action" and value == "small_taco": + value = "unknown_action" key = f"strategy_plugin_{category}_{value}" translated = self.translator(key) return translated if translated != key else value diff --git a/notifications/telegram.py b/notifications/telegram.py index 5d11945..16d3ace 100644 --- a/notifications/telegram.py +++ b/notifications/telegram.py @@ -76,11 +76,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": "持续观察", @@ -183,11 +181,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", From f078907bf974d2421c9658a1dc20e2f0ad92c535 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Tue, 12 May 2026 05:52:02 +0800 Subject: [PATCH 2/3] Remove TACO from crisis plugin --- application/runtime_strategy_adapters.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/application/runtime_strategy_adapters.py b/application/runtime_strategy_adapters.py index 14fa5d4..09b74e6 100644 --- a/application/runtime_strategy_adapters.py +++ b/application/runtime_strategy_adapters.py @@ -47,10 +47,6 @@ def attach_strategy_plugin_report(self, report, *, signals, error: str | None = def translate_strategy_plugin_value(self, category: str, raw_value: str | None) -> str: value = str(raw_value or "").strip() or "unknown" - if category == "route" and value == "taco_fake_crisis": - value = "unknown_route" - elif category == "action" and value == "small_taco": - value = "unknown_action" key = f"strategy_plugin_{category}_{value}" translated = self.translator(key) return translated if translated != key else value From 4670a11b9a90c81356e507ebb937c7925d63683f Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Tue, 12 May 2026 06:07:53 +0800 Subject: [PATCH 3/3] Show IBKR account id in notifications --- main.py | 18 +++++++++++++++--- notifications/telegram.py | 2 ++ tests/conftest.py | 2 +- tests/test_notifications.py | 1 + tests/test_request_handling.py | 5 +++++ 5 files changed, 24 insertions(+), 4 deletions(-) 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 16d3ace..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": "预留现金", @@ -115,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", 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 = {}