From abac54b226aa3c733706a71eea81e5143f74ef39 Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Sat, 18 Apr 2026 01:46:03 +0800 Subject: [PATCH] Localize LongBridge runtime diagnostics --- application/rebalance_service.py | 35 ++++++++++++++++++++++++++++++++ tests/test_rebalance_service.py | 30 +++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/application/rebalance_service.py b/application/rebalance_service.py index 64472a8..960f15f 100644 --- a/application/rebalance_service.py +++ b/application/rebalance_service.py @@ -20,6 +20,41 @@ ("feature_snapshot_config_name_mismatch", "快照配置名不匹配"), ("feature_snapshot_config_path_mismatch", "快照配置路径不匹配"), ("feature_snapshot_contract_version_mismatch", "快照契约版本不匹配"), + ("soxl_soxx_trend_income", "SOXL/SOXX 半导体趋势收益"), + ("tqqq_growth_income", "TQQQ 增长收益"), + ("global_etf_rotation", "全球 ETF 轮动"), + ("russell_1000_multi_factor_defensive", "罗素1000多因子"), + ("tech_communication_pullback_enhancement", "科技通信回调增强"), + ("qqq_tech_enhancement", "科技通信回调增强"), + ("mega_cap_leader_rotation_aggressive", "Mega Cap 激进龙头轮动"), + ("mega_cap_leader_rotation_dynamic_top20", "Mega Cap 动态 Top20 龙头轮动"), + ("mega_cap_leader_rotation_top50_balanced", "Mega Cap Top50 平衡龙头轮动"), + ("dynamic_mega_leveraged_pullback", "Mega Cap 2x 回调策略"), + ("outside_monthly_execution_window", "当前不在月度执行窗口"), + ("no_execution_window_after_snapshot", "快照后没有可用执行窗口"), + ("no-op", "不执行"), + ("monthly snapshot cadence", "月度快照节奏"), + ("waiting inside execution window", "等待进入执行窗口"), + ("small_account_warning=true", "小账户提示=是"), + ("portfolio_equity=", "净值="), + ("min_recommended_equity=", "建议最低净值="), + ( + "integer_shares_min_position_value_may_prevent_backtest_replication", + "整数股和最小仓位限制可能导致实盘无法完全复现回测", + ), + ( + "integer-share minimum position sizing may prevent backtest replication", + "整数股和最小仓位限制可能导致实盘无法完全复现回测", + ), + ("small account warning: portfolio equity", "小账户提示:净值"), + ("small account warning", "小账户提示"), + ("is below the recommended", "低于建议"), + ("is below recommended", "低于建议"), + ("snapshot_as_of=", "快照日期="), + ("snapshot=", "快照日期="), + ("allowed=", "允许日期="), + ("", "未知"), + ("", "无"), ("RISK-ON", "风险开启"), ("DE-LEVER", "降杠杆"), ("regime=hard_defense", "市场阶段=强防御"), diff --git a/tests/test_rebalance_service.py b/tests/test_rebalance_service.py index dad9b25..04afed9 100644 --- a/tests/test_rebalance_service.py +++ b/tests/test_rebalance_service.py @@ -131,6 +131,36 @@ def test_append_status_lines_localizes_qqq_tech_diagnostics_for_zh(self): lines, ) + def test_append_status_lines_localizes_runtime_diagnostic_tail_for_zh(self): + lines = [] + rebalance_service._append_status_lines( + lines, + execution={ + "status_display": ( + "no-op | reason=outside_monthly_execution_window " + "snapshot=2026-04-10 allowed=2026-04-13" + ), + "signal_display": ( + "monthly snapshot cadence | waiting inside execution window | " + "small_account_warning=true portfolio_equity=$0 " + "min_recommended_equity=$1,000 " + "reason=integer_shares_min_position_value_may_prevent_backtest_replication" + ), + }, + translator=build_translator("zh"), + signal_key="heartbeat_signal", + ) + + self.assertIn( + "📊 市场状态: 不执行 | 原因=当前不在月度执行窗口 快照日期=2026-04-10 允许日期=2026-04-13", + lines, + ) + self.assertIn( + "🎯 信号: 月度快照节奏 | 等待进入执行窗口 | 小账户提示=是 净值=$0 " + "建议最低净值=$1,000 原因=整数股和最小仓位限制可能导致实盘无法完全复现回测", + lines, + ) + def _run_strategy( self, plan,