-
Notifications
You must be signed in to change notification settings - Fork 0
Add SMS channel for crisis alerts #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,10 @@ | |
| build_strategy_plugin_alert_context_label as build_email_alert_context_label, | ||
| publish_strategy_plugin_email_alerts, | ||
| ) | ||
| from quant_platform_kit.notifications.strategy_plugin_sms import ( | ||
| StrategyPluginSmsAlertMarkerStore, | ||
| publish_strategy_plugin_sms_alerts, | ||
| ) | ||
| from quant_platform_kit.strategy_contracts import build_strategy_evaluation_inputs | ||
| from runtime_config_support import PlatformRuntimeSettings, load_platform_runtime_settings | ||
| from strategy_runtime import load_strategy_runtime | ||
|
|
@@ -238,6 +242,35 @@ def build_strategy_plugin_alert_store( | |
| ) | ||
|
|
||
|
|
||
| def build_strategy_plugin_sms_alert_store( | ||
| settings: PlatformRuntimeSettings, | ||
| *, | ||
| env_reader: Callable[[str, str | None], str | None] = os.getenv, | ||
| ): | ||
| explicit_gcs_uri = env_reader("STRATEGY_PLUGIN_ALERT_STATE_GCS_URI", None) | ||
| report_gcs_uri = env_reader("EXECUTION_REPORT_GCS_URI", None) | ||
| state_bucket = env_reader("FIRSTRADE_GCS_STATE_BUCKET", None) | ||
| state_prefix = env_reader("FIRSTRADE_STATE_PREFIX", "firstrade-platform") or "firstrade-platform" | ||
| state_gcs_uri = f"gs://{state_bucket}/{state_prefix}" if state_bucket else None | ||
| return StrategyPluginSmsAlertMarkerStore( | ||
| local_dir=env_reader("STRATEGY_PLUGIN_ALERT_STATE_DIR", None) or "/tmp/quant_strategy_plugin_alerts", | ||
| gcs_prefix_uri=explicit_gcs_uri or report_gcs_uri or state_gcs_uri, | ||
| gcp_project_id=settings.project_id, | ||
| ) | ||
|
|
||
|
|
||
| class StrategyPluginAlertPublishResults: | ||
| def __init__(self, *, email_result, sms_result): | ||
| self.email_result = email_result | ||
| self.sms_result = sms_result | ||
|
|
||
| def to_report_fields(self) -> dict[str, Any]: | ||
| fields: dict[str, Any] = {} | ||
| fields.update(self.email_result.to_report_fields()) | ||
| fields.update(self.sms_result.to_report_fields()) | ||
| return fields | ||
|
|
||
|
|
||
| def publish_strategy_plugin_alerts( | ||
| signals, | ||
| *, | ||
|
|
@@ -246,7 +279,7 @@ def publish_strategy_plugin_alerts( | |
| log_message: Callable[..., Any] = print, | ||
| env_reader: Callable[[str, str | None], str | None] = os.getenv, | ||
| ): | ||
| return publish_strategy_plugin_email_alerts( | ||
| email_result = publish_strategy_plugin_email_alerts( | ||
| signals, | ||
| email_settings=settings, | ||
| translator=translator, | ||
|
|
@@ -255,6 +288,16 @@ def publish_strategy_plugin_alerts( | |
| alert_store=build_strategy_plugin_alert_store(settings, env_reader=env_reader), | ||
| log_message=log_message, | ||
| ) | ||
| sms_result = publish_strategy_plugin_sms_alerts( | ||
| signals, | ||
| sms_settings=settings, | ||
| translator=translator, | ||
| strategy_label=settings.strategy_profile, | ||
| context_label=build_strategy_plugin_alert_context_label(settings), | ||
| alert_store=build_strategy_plugin_sms_alert_store(settings, env_reader=env_reader), | ||
| log_message=log_message, | ||
| ) | ||
|
Comment on lines
+291
to
+299
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Call failures from Useful? React with 👍 / 👎. |
||
| return StrategyPluginAlertPublishResults(email_result=email_result, sms_result=sms_result) | ||
|
|
||
|
|
||
| def _runtime_metadata_with_execution_policy( | ||
|
|
@@ -385,6 +428,11 @@ def run_strategy_cycle( | |
| "strategy_plugin_alert_email_skipped_count": 0, | ||
| "strategy_plugin_alert_email_failed_count": 0, | ||
| "strategy_plugin_alert_email_deliveries": [], | ||
| "strategy_plugin_alert_sms_attempted_count": 0, | ||
| "strategy_plugin_alert_sms_sent_count": 0, | ||
| "strategy_plugin_alert_sms_skipped_count": 0, | ||
| "strategy_plugin_alert_sms_failed_count": 0, | ||
| "strategy_plugin_alert_sms_deliveries": [], | ||
| } | ||
| return attach_strategy_plugin_result( | ||
| result, | ||
|
|
@@ -489,6 +537,11 @@ def run_strategy_cycle( | |
| "strategy_plugin_alert_email_skipped_count": 0, | ||
| "strategy_plugin_alert_email_failed_count": 0, | ||
| "strategy_plugin_alert_email_deliveries": [], | ||
| "strategy_plugin_alert_sms_attempted_count": 0, | ||
| "strategy_plugin_alert_sms_sent_count": 0, | ||
| "strategy_plugin_alert_sms_skipped_count": 0, | ||
| "strategy_plugin_alert_sms_failed_count": 0, | ||
| "strategy_plugin_alert_sms_deliveries": [], | ||
| } | ||
| ) | ||
| if strategy_plugin_alert_email_error: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| flask | ||
| gunicorn | ||
| firstrade==0.0.38 | ||
| quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@3c8f52b16a8ebf98b9fdfa4af5e96be43e6144fe | ||
| us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@b84bebb784248bd2bb3d2c589db9ea0ab35ee95d | ||
| quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@d43800180aae1c7fe7051496a6af5d76f2c65879 | ||
| us-equity-strategies @ git+https://github.com/QuantStrategyLab/UsEquityStrategies.git@9661d8bb74e33466fa0ec1efef168b1d1bae8875 | ||
| google-cloud-storage | ||
| requests | ||
| pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Publishing email and SMS alerts in a single call path means an exception from
publish_strategy_plugin_sms_alertsabortspublish_strategy_plugin_alertsafter email may already have been sent, andrun_strategy_cyclethen falls back to zero counts withstrategy_plugin_alert_email_error. In environments where SMS credentials are missing or the SMS provider errors, this produces incorrect email telemetry and mislabels the failure channel, which can hide real deliveries and mislead incident response.Useful? React with 👍 / 👎.