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
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"strategy_plugin_situation_delever_delever": "De-lever: a de-lever signal is active and risk exposure should be reduced under strategy rules.",
"strategy_plugin_situation_notify_manual_review": "Manual review: the plugin found a market state that needs human judgment.",
"strategy_plugin_situation_default": "State notice: the plugin found a market state that needs attention.",
"strategy_plugin_recommendation_default": "Review manually first, then decide whether the action belongs to strategy rules or a manual process; do not treat the plugin notice as a trade instruction.",
"strategy_plugin_recommendation_market_regime_control_watch_watch_only": "Check the trigger, recent volatility, and current leverage; this watch notice does not change allocations automatically, and any position change should come from the strategy run or an explicit manual decision.",
"strategy_plugin_recommendation_market_regime_control_risk_reduced_delever": "Check the strategy run, account constraints, and de-lever thresholds; if the strategy-side automatic rule fired, execution belongs to the strategy notification and position adapter.",
"strategy_plugin_recommendation_market_regime_control_risk_off_defend": "Pause opportunity adds and confirm whether defensive exposure matches strategy rules; wait for the risk-off state to clear before resuming offensive signals.",
Expand Down Expand Up @@ -243,7 +244,7 @@
("global_etf_rotation", "全球 ETF 轮动"),
("russell_1000_multi_factor_defensive", "罗素1000多因子"),
("tech_communication_pullback_enhancement", "科技通信回调增强"),
("qqq_tech_enhancement", "科技通信回调增强"),
("qqq_tech_enhancement", "QQQ 科技增强"),
("mega_cap_leader_rotation_top50_balanced", "美股超大盘50强平衡龙头轮动"),
("outside_monthly_execution_window", "当前不在月度执行窗口"),
("no_execution_window_after_snapshot", "快照后没有可用执行窗口"),
Expand Down
32 changes: 22 additions & 10 deletions src/quant_platform_kit/common/strategy_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@

from quant_platform_kit.common.strategy_plugin_artifacts import (
cache_path_for_remote_artifact,
download_gcs_object,
materialize_local_or_gcs_artifact,
parse_gcs_uri,
download_remote_object,
materialize_local_or_remote_artifact,
parse_cloud_uri,
)

PLUGIN_CRISIS_RESPONSE_SHADOW = "crisis_response_shadow"
PLUGIN_MARKET_REGIME_CONTROL = "market_regime_control"
PLUGIN_MACRO_RISK_GOVERNOR = "macro_risk_governor"
PLUGIN_TACO_REBOUND_SHADOW = "taco_rebound_shadow"
PLUGIN_PANIC_REVERSAL_SHADOW = "panic_reversal_shadow"
GENERAL_MARKET_REGIME_NOTIFICATION_TARGET = "market_regime_notification"
PLUGIN_MODE_SHADOW = "shadow"
STRATEGY_PLUGIN_ALERT_CHANNEL_EMAIL = "email"
Expand Down Expand Up @@ -1310,7 +1311,10 @@ def _translate_first_formatted(
if translator is None:
return None
for key in keys:
translated = translator(key, **kwargs)
try:
translated = translator(key, **kwargs)
except TypeError:
translated = translator(key)
if translated != key:
text = str(translated).strip()
if text:
Expand Down Expand Up @@ -1695,19 +1699,24 @@ def _sanitize_key_part(value: Any) -> str:


def _materialize_artifact_path(reference: str, *, client_factory: Any = None) -> tuple[Path, dict[str, str | None]]:
return materialize_local_or_gcs_artifact(
return materialize_local_or_remote_artifact(
reference,
cache_dir=DEFAULT_PLUGIN_ARTIFACT_CACHE_DIR,
client_factory=client_factory,
)


def _download_gcs_object(uri: str, destination: Path, *, client_factory: Any = None) -> None:
download_gcs_object(uri, destination, client_factory=client_factory)
def _download_remote_object(uri: str, destination: Path, *, client_factory: Any = None) -> None:
download_remote_object(uri, destination, client_factory=client_factory)


def _parse_cloud_uri(uri: str) -> tuple[str, str]:
return parse_cloud_uri(uri)


def _parse_gcs_uri(uri: str) -> tuple[str, str]:
return parse_gcs_uri(uri)
# Backward-compatible aliases (used internally by notification modules)
_download_gcs_object = _download_remote_object
_parse_gcs_uri = _parse_cloud_uri


def _cache_path_for_remote_artifact(reference: str) -> Path:
Expand Down Expand Up @@ -1742,7 +1751,10 @@ def _translate(
) -> str:
if translator is None:
return fallback.format(**kwargs)
translated = translator(key, **kwargs)
try:
translated = translator(key, **kwargs)
except TypeError:
translated = translator(key)
return translated if translated != key else fallback.format(**kwargs)


Expand Down
Loading