Skip to content

Commit ad98da8

Browse files
committed
Require shared Telegram config in LongBridge quant
1 parent e788e4e commit ad98da8

5 files changed

Lines changed: 10 additions & 14 deletions

File tree

.github/workflows/sync-cloud-run-env.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ jobs:
8787
8888
gcloud run services update "${CLOUD_RUN_SERVICE}" \
8989
--region "${CLOUD_RUN_REGION}" \
90+
--remove-env-vars "TELEGRAM_CHAT_ID" \
9091
--update-env-vars "TELEGRAM_TOKEN=${TELEGRAM_TOKEN},GLOBAL_TELEGRAM_CHAT_ID=${GLOBAL_TELEGRAM_CHAT_ID},NOTIFY_LANG=${NOTIFY_LANG},LONGPORT_APP_KEY=${LONGPORT_APP_KEY},LONGPORT_APP_SECRET=${LONGPORT_APP_SECRET},LONGPORT_SECRET_NAME=${LONGPORT_SECRET_NAME},ACCOUNT_PREFIX=${ACCOUNT_PREFIX},SERVICE_NAME=${SERVICE_NAME}"
9192
9293
sync-sg:
@@ -171,4 +172,5 @@ jobs:
171172
172173
gcloud run services update "${CLOUD_RUN_SERVICE}" \
173174
--region "${CLOUD_RUN_REGION}" \
175+
--remove-env-vars "TELEGRAM_CHAT_ID" \
174176
--update-env-vars "TELEGRAM_TOKEN=${TELEGRAM_TOKEN},GLOBAL_TELEGRAM_CHAT_ID=${GLOBAL_TELEGRAM_CHAT_ID},NOTIFY_LANG=${NOTIFY_LANG},LONGPORT_APP_KEY=${LONGPORT_APP_KEY},LONGPORT_APP_SECRET=${LONGPORT_APP_SECRET},LONGPORT_SECRET_NAME=${LONGPORT_SECRET_NAME},ACCOUNT_PREFIX=${ACCOUNT_PREFIX},SERVICE_NAME=${SERVICE_NAME}"

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ BOXX: $34,000.00 Cash: $10,000.00
7575
| Variable | Required | Description |
7676
|----------|----------|-------------|
7777
| `TELEGRAM_TOKEN` | Yes | Bot token for alerts |
78-
| `TELEGRAM_CHAT_ID` | Conditional | Per-service chat or user ID for alerts. Falls back to `GLOBAL_TELEGRAM_CHAT_ID` if unset. |
79-
| `GLOBAL_TELEGRAM_CHAT_ID` | No | Optional shared Telegram chat ID for teams that route multiple quant services to the same destination. |
78+
| `GLOBAL_TELEGRAM_CHAT_ID` | Yes | Telegram chat or user ID used by this service. |
8079
| `LONGPORT_APP_KEY` | Yes | LongPort OpenAPI app key (for token refresh) |
8180
| `LONGPORT_APP_SECRET` | Yes | LongPort OpenAPI app secret (for token refresh) |
8281
| `LONGPORT_SECRET_NAME` | No | Secret Manager secret name for LongPort token (default: `longport_token`) |
@@ -116,7 +115,7 @@ Recommended setup:
116115
- Variables: `CLOUD_RUN_REGION`, `CLOUD_RUN_SERVICE`, `ACCOUNT_PREFIX`, `SERVICE_NAME`, `LONGPORT_SECRET_NAME`
117116
- Secrets: `LONGPORT_APP_KEY`, `LONGPORT_APP_SECRET`
118117

119-
On every push to `main`, the workflow updates both Cloud Run services with the shared and per-environment values above. It does **not** remove legacy `TELEGRAM_CHAT_ID`, so existing deployments keep working. Once you have confirmed both services are reading `GLOBAL_TELEGRAM_CHAT_ID` as intended, you can remove `TELEGRAM_CHAT_ID` from each Cloud Run service manually.
118+
On every push to `main`, the workflow updates both Cloud Run services with the shared and per-environment values above, and removes `TELEGRAM_CHAT_ID` from each Cloud Run service.
120119

121120
Important:
122121

@@ -217,8 +216,7 @@ BOXX: $34,000.00 现金: $10,000.00
217216
| 变量 | 必需 | 说明 |
218217
|------|------|------|
219218
| `TELEGRAM_TOKEN` || Telegram 机器人 Token |
220-
| `TELEGRAM_CHAT_ID` | 条件必需 | 当前服务自己的 Chat ID。不填时会回退到 `GLOBAL_TELEGRAM_CHAT_ID`|
221-
| `GLOBAL_TELEGRAM_CHAT_ID` || 可选的共享 Telegram Chat ID。适合多个 quant 服务共用一个接收目标。 |
219+
| `GLOBAL_TELEGRAM_CHAT_ID` || 这个服务使用的 Telegram Chat ID。 |
222220
| `LONGPORT_APP_KEY` || LongPort OpenAPI 应用密钥(用于刷新 Token) |
223221
| `LONGPORT_APP_SECRET` || LongPort OpenAPI 应用密钥(用于刷新 Token) |
224222
| `LONGPORT_SECRET_NAME` || Secret Manager 中的密钥名称(默认: `longport_token`|
@@ -258,7 +256,7 @@ Secret Manager 中需存在 `LONGPORT_SECRET_NAME` 指定的密钥(默认: `lo
258256
- Variables: `CLOUD_RUN_REGION``CLOUD_RUN_SERVICE``ACCOUNT_PREFIX``SERVICE_NAME``LONGPORT_SECRET_NAME`
259257
- Secrets: `LONGPORT_APP_KEY``LONGPORT_APP_SECRET`
260258

261-
每次 push 到 `main` 时,这个 workflow 会分别更新两个 Cloud Run 服务,把共享和各自隔离的变量同步进去。它**不会主动删除**旧的 `TELEGRAM_CHAT_ID`,这样现有部署不会被硬切断。等你确认两个服务都已经按预期读取 `GLOBAL_TELEGRAM_CHAT_ID` 后,再手动把各自 Cloud Run 上旧的 `TELEGRAM_CHAT_ID` 删掉即可
259+
每次 push 到 `main` 时,这个 workflow 会分别更新两个 Cloud Run 服务,把共享和各自隔离的变量同步进去,并删除旧的 `TELEGRAM_CHAT_ID`
262260

263261
注意:
264262

main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_project_id():
5050
SERVICE_NAME = os.getenv("SERVICE_NAME", "longbridge-quant")
5151
NOTIFY_LANG = os.getenv("NOTIFY_LANG", "en")
5252
TG_TOKEN = os.getenv("TELEGRAM_TOKEN")
53-
TG_CHAT_ID = os.getenv("TELEGRAM_CHAT_ID") or os.getenv("GLOBAL_TELEGRAM_CHAT_ID")
53+
TG_CHAT_ID = os.getenv("GLOBAL_TELEGRAM_CHAT_ID")
5454

5555
# Execution: reserve ratio, minimum trade size (ratio of equity and absolute floor)
5656
CASH_RESERVE_RATIO = 0.03

tests/test_shared_chat_id_fallback.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ def install_stub_modules():
5656
return patch.dict(sys.modules, modules)
5757

5858

59-
class SharedChatIdFallbackTests(unittest.TestCase):
60-
def test_global_telegram_chat_id_is_used_when_service_chat_id_missing(self):
59+
class SharedChatIdTests(unittest.TestCase):
60+
def test_global_telegram_chat_id_is_used(self):
6161
with install_stub_modules():
6262
with patch.dict(
6363
os.environ,
6464
{
65-
"TELEGRAM_CHAT_ID": "",
6665
"GLOBAL_TELEGRAM_CHAT_ID": "shared-chat-id",
6766
},
6867
clear=False,

tests/test_sync_cloud_run_env_workflow.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ grep -Fq "SG Cloud Run env sync is enabled, but these values are missing:" "$wor
2020
grep -Fq "set CLOUD_RUN_REGION on the longbridge-hk Environment" "$workflow_file"
2121
grep -Fq "set CLOUD_RUN_REGION on the longbridge-sg Environment" "$workflow_file"
2222
grep -Fq "if: steps.config.outputs.enabled == 'true'" "$workflow_file"
23-
if grep -Fq -- "--remove-env-vars TELEGRAM_CHAT_ID" "$workflow_file"; then
24-
echo "workflow should not force-remove TELEGRAM_CHAT_ID; keep backward compatibility" >&2
25-
exit 1
26-
fi
23+
grep -Fq -- '--remove-env-vars "TELEGRAM_CHAT_ID"' "$workflow_file"

0 commit comments

Comments
 (0)