Skip to content

Commit c1e32ec

Browse files
committed
Localize IBKR runtime diagnostics
1 parent 76a6935 commit c1e32ec

2 files changed

Lines changed: 57 additions & 1 deletion

File tree

application/rebalance_service.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,41 @@
2424
("feature_snapshot_config_name_mismatch", "快照配置名不匹配"),
2525
("feature_snapshot_config_path_mismatch", "快照配置路径不匹配"),
2626
("feature_snapshot_contract_version_mismatch", "快照契约版本不匹配"),
27+
("soxl_soxx_trend_income", "SOXL/SOXX 半导体趋势收益"),
28+
("tqqq_growth_income", "TQQQ 增长收益"),
29+
("global_etf_rotation", "全球 ETF 轮动"),
30+
("russell_1000_multi_factor_defensive", "罗素1000多因子"),
31+
("tech_communication_pullback_enhancement", "科技通信回调增强"),
32+
("qqq_tech_enhancement", "科技通信回调增强"),
33+
("mega_cap_leader_rotation_aggressive", "Mega Cap 激进龙头轮动"),
34+
("mega_cap_leader_rotation_dynamic_top20", "Mega Cap 动态 Top20 龙头轮动"),
35+
("mega_cap_leader_rotation_top50_balanced", "Mega Cap Top50 平衡龙头轮动"),
36+
("dynamic_mega_leveraged_pullback", "Mega Cap 2x 回调策略"),
37+
("outside_monthly_execution_window", "当前不在月度执行窗口"),
38+
("no_execution_window_after_snapshot", "快照后没有可用执行窗口"),
39+
("no-op", "不执行"),
40+
("monthly snapshot cadence", "月度快照节奏"),
41+
("waiting inside execution window", "等待进入执行窗口"),
42+
("small_account_warning=true", "小账户提示=是"),
43+
("portfolio_equity=", "净值="),
44+
("min_recommended_equity=", "建议最低净值="),
45+
(
46+
"integer_shares_min_position_value_may_prevent_backtest_replication",
47+
"整数股和最小仓位限制可能导致实盘无法完全复现回测",
48+
),
49+
(
50+
"integer-share minimum position sizing may prevent backtest replication",
51+
"整数股和最小仓位限制可能导致实盘无法完全复现回测",
52+
),
53+
("small account warning: portfolio equity", "小账户提示:净值"),
54+
("small account warning", "小账户提示"),
55+
("is below the recommended", "低于建议"),
56+
("is below recommended", "低于建议"),
57+
("snapshot_as_of=", "快照日期="),
58+
("snapshot=", "快照日期="),
59+
("allowed=", "允许日期="),
60+
("<unknown>", "未知"),
61+
("<none>", "无"),
2762
("RISK-ON", "风险开启"),
2863
("DE-LEVER", "降杠杆"),
2964
("regime=hard_defense", "市场阶段=强防御"),
@@ -191,7 +226,7 @@ def _build_notification_trade_lines(
191226
lines.extend(_build_order_batch_lines(execution_summary, translator=translator))
192227

193228
for raw_line in trade_logs or ():
194-
text = str(raw_line).strip()
229+
text = _localize_notification_text(str(raw_line).strip(), translator=translator)
195230
if not text:
196231
continue
197232
if text.startswith(("目标差异 ", "target_diff ", "DRY_RUN buy ", "DRY_RUN sell ")):

tests/test_rebalance_service.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
from application.rebalance_service import build_dashboard, run_strategy_core
4+
from application.rebalance_service import _build_notification_trade_lines
45
from notifications.telegram import build_translator
56

67

@@ -136,6 +137,26 @@ def test_build_dashboard_localizes_qqq_tech_diagnostics_for_zh():
136137
assert "入选标的数=8 前排标的=CIEN(0.92)" in dashboard
137138

138139

140+
def test_notification_trade_lines_localize_runtime_diagnostic_tail_for_zh():
141+
lines = _build_notification_trade_lines(
142+
[
143+
(
144+
"执行配置=soxl_soxx_trend_income | 市场阶段=<none> | 宽度=0.0% | "
145+
"目标股票仓位=0.0% | 实际股票仓位=0.0% | 快照日期=<none> | 交易日=<none>"
146+
)
147+
],
148+
execution_summary={},
149+
translator=build_translator("zh"),
150+
)
151+
152+
assert lines == [
153+
(
154+
"执行配置=SOXL/SOXX 半导体趋势收益 | 市场阶段=无 | 宽度=0.0% | "
155+
"目标股票仓位=0.0% | 实际股票仓位=0.0% | 快照日期=无 | 交易日=无"
156+
)
157+
]
158+
159+
139160
def test_run_strategy_core_passes_signal_metadata_to_execution():
140161
observed = {"messages": [], "strategy_symbols": None}
141162

0 commit comments

Comments
 (0)