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
18 changes: 15 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)),
)


Expand Down
6 changes: 2 additions & 4 deletions notifications/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"error_title": "🚨 【策略异常】",
"canary_title": "🐤 【金丝雀检查】",
"strategy_label": "🧭 策略: {name}",
"account_ids_detail": "🆔 账户: {account_ids}",
"equity": "净值",
"buying_power": "购买力",
"reserved_cash": "预留现金",
Expand Down Expand Up @@ -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": "持续观察",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions tests/test_request_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down