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
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 0 additions & 8 deletions notifications/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down Expand Up @@ -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}",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_decision_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions tests/test_order_alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
24 changes: 12 additions & 12 deletions tests/test_rebalance_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",),),
Expand Down Expand Up @@ -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",),),
Expand Down Expand Up @@ -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"),),
Expand Down Expand Up @@ -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",),),
Expand Down Expand Up @@ -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",),),
Expand Down Expand Up @@ -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",),),
Expand Down Expand Up @@ -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"),),
Expand All @@ -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"),),
Expand Down Expand Up @@ -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"),),
Expand All @@ -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"),),
Expand Down Expand Up @@ -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",),),
Expand Down