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
6 changes: 5 additions & 1 deletion application/runtime_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ def build_reporting_adapters(self):
service_name=self.service_name,
strategy_profile=self.strategy_profile,
runtime_target=self.runtime_target,
account_scope=self.account_group,
account_scope=(
self.runtime_target.account_scope
if self.runtime_target and self.runtime_target.account_scope
else self.account_group
),
account_group=self.account_group,
project_id=self.project_id,
instance_name=self.instance_name,
Expand Down
6 changes: 5 additions & 1 deletion runtime_config_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,11 @@ def load_platform_runtime_settings(
)
),
account_group=account_group,
service_name=group_config.service_name,
service_name=first_non_empty(
os.getenv("K_SERVICE"),
runtime_target.service_name,
group_config.service_name,
),
account_ids=group_config.account_ids,
tg_token=os.getenv("TELEGRAM_TOKEN"),
tg_chat_id=os.getenv("QSL_GLOBAL_TELEGRAM_CHAT_ID") or os.getenv("GLOBAL_TELEGRAM_CHAT_ID"),
Expand Down
7 changes: 4 additions & 3 deletions tests/test_runtime_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def fake_reporting_builder(**kwargs):
service_name="interactive-brokers-platform",
strategy_profile="global_etf_rotation",
strategy_domain="us_equity",
account_group="default",
account_group="shared-live",
project_id="project-1",
instance_name="ib-gateway",
account_ids=("U123456",),
Expand All @@ -44,7 +44,7 @@ def fake_reporting_builder(**kwargs):
platform_id="interactive_brokers",
strategy_profile="global_etf_rotation",
dry_run_only=True,
account_scope="default",
account_scope="us-combo-shadow",
service_name="interactive-brokers-platform",
),
strategy_config_source="env",
Expand Down Expand Up @@ -87,7 +87,8 @@ def fake_reporting_builder(**kwargs):

assert notification_adapters.notification_port == "notification-port"
assert observed["notification_builder"]["send_message"]
assert observed["reporting_builder"]["runtime_assembly"].account_scope == "default"
assert observed["reporting_builder"]["runtime_assembly"].account_scope == "us-combo-shadow"
assert observed["reporting_builder"]["runtime_assembly"].account_group == "shared-live"
assert observed["reporting_builder"]["managed_symbols"] == ("AAA", "BIL")
assert observed["reporting_builder"]["signal_effective_after_trading_days"] == 1
assert observed["reporting_builder"]["runtime_assembly"].runtime_target.platform_id == "interactive_brokers"
Expand Down
26 changes: 26 additions & 0 deletions tests/test_runtime_config_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,32 @@ def test_load_platform_runtime_settings_supports_explicit_group_config_values(mo
assert settings.notify_lang == "zh"


def test_runtime_target_service_name_overrides_shared_account_group_service(monkeypatch):
monkeypatch.setenv(
"RUNTIME_TARGET_JSON",
runtime_target_json(
"us_equity_combo_leveraged",
dry_run_only=True,
deployment_selector="us-combo-shadow",
account_scope="us-combo-shadow",
service_name="interactive-brokers-us-combo-shadow-service",
),
)
monkeypatch.setenv("ACCOUNT_GROUP", "shared-live")
monkeypatch.setenv(
"IB_ACCOUNT_GROUP_CONFIG_JSON",
'{"groups":{"shared-live":{"ib_gateway_instance_name":"ib-gateway",'
'"ib_gateway_mode":"live","ib_client_id":1,'
'"service_name":"interactive-brokers-quant-live-u18336562-service",'
'"account_ids":["U123456"]}}}',
)

settings = load_platform_runtime_settings(project_id_resolver=lambda: "project-1")

assert settings.account_group == "shared-live"
assert settings.service_name == "interactive-brokers-us-combo-shadow-service"


def test_load_platform_runtime_settings_derives_hk_market_from_account_group(monkeypatch):
monkeypatch.setenv("RUNTIME_TARGET_JSON", runtime_target_json(SAMPLE_STRATEGY_PROFILE))
monkeypatch.setenv("ACCOUNT_GROUP", "hk-live")
Expand Down
Loading