diff --git a/main.py b/main.py index 2fdcf10..8b6008d 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ """ -LongPort semiconductor rotation + income layer. -Trading: SOXL/SOXX by 150d MA, remainder in BOXX. Income: QQQI/SPYI above equity threshold. +LongPort Cloud Run strategy executor. +Runs the configured shared UsEquityStrategies profile for the deployed LongBridge account. Runs on Cloud Run; token from Secret Manager, orders via LongPort OpenAPI, alerts via Telegram. """ import os diff --git a/notifications/telegram.py b/notifications/telegram.py index 1d75da2..3bb894b 100644 --- a/notifications/telegram.py +++ b/notifications/telegram.py @@ -75,10 +75,6 @@ "status_rejected": "拒绝", "status_canceled": "取消", "status_expired": "过期", - "market_status_risk_on": "🚀 风险开启({asset})", - "market_status_delever": "🛡️ 降杠杆({asset})", - "signal_risk_on": "SOXL 站上 {window} 日均线,持有 SOXL,交易层风险仓位 {ratio}", - "signal_delever": "SOXL 跌破 {window} 日均线,切换至 SOXX,交易层风险仓位 {ratio}", "market_status_blend_gate_risk_on": "🚀 风险开启({asset})", "market_status_blend_gate_defensive": "🛡️ 降杠杆({asset})", "signal_blend_gate_risk_on": "{trend_symbol} 站上 {window} 日门槛线,持有 SOXL {soxl_ratio} + SOXX {soxx_ratio}", @@ -161,10 +157,6 @@ "status_rejected": "Rejected", "status_canceled": "Canceled", "status_expired": "Expired", - "market_status_risk_on": "🚀 RISK-ON ({asset})", - "market_status_delever": "🛡️ DE-LEVER ({asset})", - "signal_risk_on": "SOXL above {window}d MA, hold SOXL, risk {ratio}", - "signal_delever": "SOXL below {window}d MA, switch to SOXX, risk {ratio}", "market_status_blend_gate_risk_on": "🚀 RISK-ON ({asset})", "market_status_blend_gate_defensive": "🛡️ DE-LEVER ({asset})", "signal_blend_gate_risk_on": "{trend_symbol} above {window}d gated entry, hold SOXL {soxl_ratio} + SOXX {soxx_ratio}", diff --git a/tests/test_decision_mapper.py b/tests/test_decision_mapper.py index ff56706..fd4d274 100644 --- a/tests/test_decision_mapper.py +++ b/tests/test_decision_mapper.py @@ -18,12 +18,12 @@ def test_maps_semiconductor_strategy_decision_to_execution_plan(self): PositionTarget(symbol="SPYI", target_value=1500.0, role="income"), ), diagnostics={ - "market_status": "🚀 RISK-ON (SOXL)", + "market_status": "🚀 RISK-ON (SOXX+SOXL)", "signal_message": "signal", "deploy_ratio_text": "60.0%", "income_ratio_text": "10.0%", "income_locked_ratio_text": "10.0%", - "active_risk_asset": "SOXL", + "active_risk_asset": "SOXX+SOXL", "investable_cash": 9000.0, "threshold_value": 500.0, "current_min_trade": 100.0, diff --git a/tests/test_order_alerts.py b/tests/test_order_alerts.py index fd89494..66be3bc 100644 --- a/tests/test_order_alerts.py +++ b/tests/test_order_alerts.py @@ -24,12 +24,6 @@ def test_render_order_lifecycle_message_localizes_order_fill_for_zh(): assert message == "✅ 订单成交 | BOXX 买入 49股 均价 $116.31(订单号: 1227343614540054528)" -def test_build_translator_localizes_semiconductor_trend_status_for_zh(): - translate = build_translator("zh") - assert translate("market_status_delever", asset="SOXX") == "🛡️ 降杠杆(SOXX)" - assert translate("signal_delever", window=150, ratio="40.2%") == "SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 40.2%" - - def test_publish_order_lifecycle_event_routes_rendering_through_publisher(): messages = [] diff --git a/tests/test_rebalance_service.py b/tests/test_rebalance_service.py index 7d95e12..baa9acf 100644 --- a/tests/test_rebalance_service.py +++ b/tests/test_rebalance_service.py @@ -181,7 +181,7 @@ def test_run_strategy_prefers_portfolio_port_runtime_path(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=101.95, total_strategy_equity=60000.0, portfolio_rows=(("SOXX",),), @@ -255,7 +255,7 @@ def test_run_strategy_supports_execution_port_runtime_path(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=50000.0, total_strategy_equity=60000.0, portfolio_rows=(("SOXX",),), @@ -492,7 +492,7 @@ def test_sell_then_buy_skip_is_sent_in_single_summary_message(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=101.95, total_strategy_equity=60000.0, portfolio_rows=(("SOXL", "SOXX"),), @@ -525,7 +525,7 @@ def test_buy_skip_without_orders_is_sent_in_single_heartbeat_message(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=101.95, total_strategy_equity=60000.0, portfolio_rows=(("SOXX",),), @@ -554,11 +554,11 @@ def test_zero_investable_cash_reports_buying_power_without_trade_note(self): current_min_trade=100.0, trade_threshold_value=100.0, investable_cash=0.0, - market_status="🚀 RISK-ON (SOXL)", + market_status="🚀 风险开启(SOXX+SOXL)", deploy_ratio_text="57.7%", income_ratio_text="0.0%", income_locked_ratio_text="37.6%", - signal_message="SOXL 站上 150 日均线,持有 SOXL,交易层风险仓位 57.7%", + signal_message="SOXX 站上 140 日门槛线,持有 SOXL 57.7% + SOXX 0.0%", available_cash=3065.61, total_strategy_equity=103350.09, portfolio_rows=(("BOXX",),), @@ -593,7 +593,7 @@ def test_cash_limit_zero_mentions_possible_order_hold(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=40000.0, total_strategy_equity=60000.0, portfolio_rows=(("SOXX",),), @@ -660,7 +660,7 @@ def test_refreshes_account_state_after_sell_and_can_place_followup_buy(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=101.95, total_strategy_equity=60000.0, portfolio_rows=(("SOXL", "SOXX"),), @@ -679,7 +679,7 @@ def test_refreshes_account_state_after_sell_and_can_place_followup_buy(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=40000.0, total_strategy_equity=60000.0, portfolio_rows=(("SOXL", "SOXX"),), @@ -810,7 +810,7 @@ def test_dry_run_replaces_real_order_submission_with_summary_lines(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=101.95, total_strategy_equity=60000.0, portfolio_rows=(("SOXL", "SOXX"),), @@ -829,7 +829,7 @@ def test_dry_run_replaces_real_order_submission_with_summary_lines(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=40000.0, total_strategy_equity=60000.0, portfolio_rows=(("SOXL", "SOXX"),), @@ -866,7 +866,7 @@ def test_heartbeat_accepts_normalized_portfolio_and_execution_sections(self): deploy_ratio_text="57.9%", income_ratio_text="0.0%", income_locked_ratio_text="38.3%", - signal_message="SOXL 跌破 150 日均线,切换至 SOXX,交易层风险仓位 57.9%", + signal_message="SOXX 跌破门槛线,防守持有 SOXX 57.9%", available_cash=101.95, total_strategy_equity=60000.0, portfolio_rows=(("SOXX",),),