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
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def _runtime_error_notification_message(exc):

def _notify_runtime_error(exc):
token = os.getenv("TG_TOKEN", "")
chat_id = os.getenv("GLOBAL_TELEGRAM_CHAT_ID", "")
chat_id = os.getenv("QSL_GLOBAL_TELEGRAM_CHAT_ID") or os.getenv("GLOBAL_TELEGRAM_CHAT_ID", "")
if not token or not chat_id:
print("Binance runtime error notification skipped: no Telegram target configured.")
return False
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = "QuantStrategyLab platform layer for Binance exchange."
requires-python = ">=3.11"
dependencies = [
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@3acab1923a97b805b077c85c6c19657be0143bac",
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@9f7e7f8335e97f83f66677ad5e73254a1a421759",
"crypto-strategies @ git+https://github.com/QuantStrategyLab/CryptoStrategies.git@ef78312d7653095f585c4f75d45bf765bedc2751",
"python-binance",
"pandas",
Expand All @@ -23,7 +23,7 @@ test = [

[tool.uv]
override-dependencies = [
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@3acab1923a97b805b077c85c6c19657be0143bac",
"quant-platform-kit @ git+https://github.com/QuantStrategyLab/QuantPlatformKit.git@9f7e7f8335e97f83f66677ad5e73254a1a421759",
]

[tool.ruff]
Expand Down
2 changes: 1 addition & 1 deletion qsl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ expires_at = "2026-09-30"
next_action = "keep uv.lock current and maintain QPK/CryptoStrategies pin consistency"

[qsl.requires]
quant_platform_kit = "3acab1923a97b805b077c85c6c19657be0143bac"
quant_platform_kit = "9f7e7f8335e97f83f66677ad5e73254a1a421759"
crypto_strategies = "ef78312d7653095f585c4f75d45bf765bedc2751"

[qsl.compat]
Expand Down
2 changes: 1 addition & 1 deletion runtime_config_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def build_live_runtime(
api_key=os.getenv("BINANCE_API_KEY", ""),
api_secret=os.getenv("BINANCE_API_SECRET", ""),
tg_token=os.getenv("TG_TOKEN", ""),
tg_chat_id=os.getenv("GLOBAL_TELEGRAM_CHAT_ID", ""),
tg_chat_id=os.getenv("QSL_GLOBAL_TELEGRAM_CHAT_ID") or os.getenv("GLOBAL_TELEGRAM_CHAT_ID", ""),
state_loader=state_loader,
state_writer=state_writer,
notifier=notifier,
Expand Down
2 changes: 1 addition & 1 deletion scripts/runtime_workflow_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _assess_runtime_heartbeat(

def _send_telegram(message: str) -> bool:
token = os.environ.get("TG_TOKEN") or os.environ.get("TELEGRAM_TOKEN")
chats = _split_values(os.environ.get("GLOBAL_TELEGRAM_CHAT_ID"))
chats = _split_values(os.environ.get("QSL_GLOBAL_TELEGRAM_CHAT_ID") or os.environ.get("GLOBAL_TELEGRAM_CHAT_ID"))
if not token or not chats:
print("Telegram heartbeat notification skipped: target is not configured.", file=sys.stderr)
return False
Expand Down
22 changes: 22 additions & 0 deletions tests/test_main_runtime_error_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,28 @@ def test_runtime_error_notification_requires_transport_acknowledgement(self):
):
self.assertFalse(main._notify_runtime_error(RuntimeError("boom")))

def test_runtime_error_notification_prefers_qsl_global_telegram_chat_id(self):
observed = {}

def fake_send_tg_msg(token, chat_id, _text):
observed["token"] = token
observed["chat_id"] = chat_id
return True

with patch.dict(
os.environ,
{
"TG_TOKEN": "token-1",
"QSL_GLOBAL_TELEGRAM_CHAT_ID": "qsl-chat-id",
"GLOBAL_TELEGRAM_CHAT_ID": "legacy-chat-id",
},
clear=False,
):
with patch.object(main, "send_tg_msg", fake_send_tg_msg):
self.assertTrue(main._notify_runtime_error(RuntimeError("boom")))

self.assertEqual(observed, {"token": "token-1", "chat_id": "qsl-chat-id"})


if __name__ == "__main__":
unittest.main()
16 changes: 16 additions & 0 deletions tests/test_runtime_config_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ def test_build_live_runtime_uses_global_telegram_chat_id(self):

self.assertEqual(runtime.tg_chat_id, "shared-chat-id")

def test_build_live_runtime_prefers_qsl_global_telegram_chat_id(self):
with patch.dict(
os.environ,
{
"BINANCE_API_KEY": "api-key",
"BINANCE_API_SECRET": "api-secret",
"TG_TOKEN": "tg-token",
"QSL_GLOBAL_TELEGRAM_CHAT_ID": "qsl-chat-id",
"GLOBAL_TELEGRAM_CHAT_ID": "legacy-chat-id",
},
clear=False,
):
runtime = build_live_runtime()

self.assertEqual(runtime.tg_chat_id, "qsl-chat-id")

def test_build_live_runtime_uses_runtime_target_json(self):
runtime_target = {
"platform_id": "binance",
Expand Down
35 changes: 35 additions & 0 deletions tests/test_runtime_workflow_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,41 @@ def read(self):
with patch.object(heartbeat.urllib.request, "urlopen", return_value=FakeResponse()):
self.assertFalse(heartbeat._send_telegram("heartbeat failed"))

def test_send_telegram_prefers_qsl_global_telegram_chat_id(self) -> None:
class FakeResponse:
status = 200

def __enter__(self):
return self

def __exit__(self, *_args):
return None

def read(self):
return b'{"ok":true}'

observed = {}

def fake_urlopen(request, timeout):
observed["body"] = request.data.decode("utf-8")
observed["timeout"] = timeout
return FakeResponse()

with patch.dict(
os.environ,
{
"TG_TOKEN": "token-1",
"QSL_GLOBAL_TELEGRAM_CHAT_ID": "qsl-chat-id",
"GLOBAL_TELEGRAM_CHAT_ID": "legacy-chat-id",
},
clear=True,
):
with patch.object(heartbeat.urllib.request, "urlopen", side_effect=fake_urlopen):
self.assertTrue(heartbeat._send_telegram("heartbeat failed"))

self.assertIn("chat_id=qsl-chat-id", observed["body"])
self.assertNotIn("legacy-chat-id", observed["body"])


if __name__ == "__main__":
unittest.main()
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.