Skip to content

Commit d28cd2d

Browse files
committed
fix: default hk token secret name
1 parent d3f5a26 commit d28cd2d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ BOXX: $34,000.00 Cash: $10,000.00
8383
| `GLOBAL_TELEGRAM_CHAT_ID` | Yes | Telegram chat or user ID used by this service. |
8484
| `LONGPORT_APP_KEY` | Yes | LongPort OpenAPI app key (for token refresh); recommended to inject from Secret Manager secret `longport-app-key` |
8585
| `LONGPORT_APP_SECRET` | Yes | LongPort OpenAPI app secret (for token refresh); recommended to inject from Secret Manager secret `longport-app-secret` |
86-
| `LONGPORT_SECRET_NAME` | No | Secret Manager secret name for LongPort token (default: `longport_token`) |
86+
| `LONGPORT_SECRET_NAME` | No | Secret Manager secret name for LongPort token (default: `longport_token_hk`) |
8787
| `ACCOUNT_PREFIX` | No | Alert/log prefix for account/environment (default: `DEFAULT`) |
8888
| `SERVICE_NAME` | No | Alert/log prefix for service identity (default: `longbridge-quant-semiconductor-rotation-income`) |
8989
| `STRATEGY_PROFILE` | No | Strategy profile selector (default: `semiconductor_rotation_income`; supported value: `semiconductor_rotation_income`) |
9090
| `ACCOUNT_REGION` | No | Account region marker for platform-style deployment (e.g. `HK`, `SG`; defaults to `ACCOUNT_PREFIX` / service-name suffix / `DEFAULT`) |
9191
| `NOTIFY_LANG` | No | Notification language: `en` (English, default) or `zh` (Chinese) |
9292
| `GOOGLE_CLOUD_PROJECT` | No | GCP project ID (defaults to ADC project when unset) |
9393

94-
Secret Manager must contain the secret named by `LONGPORT_SECRET_NAME` (default: `longport_token`), where the **latest version = active access token**. The app refreshes it when expiry is within 30 days.
94+
Secret Manager must contain the secret named by `LONGPORT_SECRET_NAME` (default: `longport_token_hk`), where the **latest version = active access token**. The app refreshes it when expiry is within 30 days.
9595

9696
Recommended shared runtime secrets in the `longbridgequant` project:
9797

@@ -157,12 +157,12 @@ Important:
157157
### Quick deploy
158158

159159
1. Enable **Cloud Run** and **Secret Manager API** in GCP.
160-
2. Create secret `longport_token` (or your custom `LONGPORT_SECRET_NAME`) in Secret Manager and add your LongPort access token as the first version.
160+
2. Create secret `longport_token_hk` for HK / `longport_token_sg` for SG (or your custom `LONGPORT_SECRET_NAME`) in Secret Manager and add your LongPort access token as the first version.
161161
3. Set the required env vars above on the Cloud Run service.
162162
4. Deploy the app to Cloud Run (e.g. `gcloud run deploy` from repo root with Dockerfile or buildpack).
163163
5. Create a Cloud Scheduler job that POSTs to the Cloud Run URL on a schedule (e.g. `45 15 * * 1-5` for ~15 min before US market close on weekdays).
164164

165-
IAM: the Cloud Run service account needs **Secret Manager Admin** (or Secret Accessor for `longport_token`) and **Logs Writer**. Build/deploy typically uses a separate account with Artifact Registry Writer, Cloud Run Admin, Service Account User.
165+
IAM: the Cloud Run service account needs **Secret Manager Admin** (or Secret Accessor for the configured `LONGPORT_SECRET_NAME`, such as `longport_token_hk` / `longport_token_sg`) and **Logs Writer**. Build/deploy typically uses a separate account with Artifact Registry Writer, Cloud Run Admin, Service Account User.
166166

167167
### Parameters (main.py)
168168

@@ -253,15 +253,15 @@ BOXX: $34,000.00 现金: $10,000.00
253253
| `GLOBAL_TELEGRAM_CHAT_ID` || 这个服务使用的 Telegram Chat ID。 |
254254
| `LONGPORT_APP_KEY` || LongPort OpenAPI 应用密钥(用于刷新 Token);建议通过 Secret Manager 的 `longport-app-key` 注入 |
255255
| `LONGPORT_APP_SECRET` || LongPort OpenAPI 应用密钥(用于刷新 Token);建议通过 Secret Manager 的 `longport-app-secret` 注入 |
256-
| `LONGPORT_SECRET_NAME` || Secret Manager 中的密钥名称(默认: `longport_token`|
256+
| `LONGPORT_SECRET_NAME` || Secret Manager 中的密钥名称(默认: `longport_token_hk`|
257257
| `ACCOUNT_PREFIX` || 通知/日志前缀,区分账户环境(默认: `DEFAULT`|
258258
| `SERVICE_NAME` || 通知/日志前缀,区分服务(默认: `longbridge-quant-semiconductor-rotation-income`|
259259
| `STRATEGY_PROFILE` || 策略档位选择(默认: `semiconductor_rotation_income`;当前支持值: `semiconductor_rotation_income`|
260260
| `ACCOUNT_REGION` || 平台化部署时的账户区域标记(如 `HK``SG`;默认按 `ACCOUNT_PREFIX` / 服务名后缀 / `DEFAULT` 推断) |
261261
| `NOTIFY_LANG` || 通知语言: `en`(英文,默认)或 `zh`(中文) |
262262
| `GOOGLE_CLOUD_PROJECT` || GCP 项目 ID(未设置时使用 ADC 默认项目) |
263263

264-
Secret Manager 中需存在 `LONGPORT_SECRET_NAME` 指定的密钥(默认: `longport_token`),**最新版本 = 当前有效的 access token**。Token 到期前 30 天会自动刷新。
264+
Secret Manager 中需存在 `LONGPORT_SECRET_NAME` 指定的密钥(默认: `longport_token_hk`),**最新版本 = 当前有效的 access token**。Token 到期前 30 天会自动刷新。
265265

266266
建议在 `longbridgequant` 项目里统一维护这些运行时 secret:
267267

@@ -327,12 +327,12 @@ Secret Manager 中需存在 `LONGPORT_SECRET_NAME` 指定的密钥(默认: `lo
327327
### 快速部署
328328

329329
1. 在 GCP 中启用 **Cloud Run****Secret Manager API**
330-
2. 在 Secret Manager 中创建密钥 `longport_token`(或自定义名称),将 LongPort access token 作为第一个版本写入。
330+
2. 在 Secret Manager 中为 HK 创建 `longport_token_hk`、为 SG 创建 `longport_token_sg`(或使用你自定义的 `LONGPORT_SECRET_NAME`),并将 LongPort access token 作为第一个版本写入。
331331
3. 在 Cloud Run 服务上配置上述环境变量。
332332
4. 部署至 Cloud Run(如从仓库根目录执行 `gcloud run deploy`)。
333333
5. 创建 Cloud Scheduler 定时任务,POST 到 Cloud Run URL(如 `45 15 * * 1-5`,工作日美股收盘前约 15 分钟)。
334334

335-
IAM: Cloud Run 服务账号需要 **Secret Manager Admin**`longport_token` 的 Secret Accessor)和 **Logs Writer** 权限。
335+
IAM: Cloud Run 服务账号需要 **Secret Manager Admin**或当前 `LONGPORT_SECRET_NAME` 对应 secret 的 Secret Accessor,例如 `longport_token_hk` / `longport_token_sg`)和 **Logs Writer** 权限。
336336

337337
### 策略参数 (main.py)
338338

runtime_config_support.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
DEFAULT_ACCOUNT_REGION = "DEFAULT"
1414
DEFAULT_STRATEGY_PROFILE = PLATFORM_DEFAULT_STRATEGY_PROFILE
15+
DEFAULT_LONGPORT_SECRET_NAME = "longport_token_hk"
1516

1617

1718
@dataclass(frozen=True)
@@ -64,7 +65,7 @@ def load_platform_runtime_settings(
6465
)
6566
return PlatformRuntimeSettings(
6667
project_id=project_id_resolver(),
67-
secret_name=os.getenv("LONGPORT_SECRET_NAME", "longport_token"),
68+
secret_name=os.getenv("LONGPORT_SECRET_NAME", DEFAULT_LONGPORT_SECRET_NAME),
6869
account_prefix=account_prefix,
6970
service_name=service_name,
7071
strategy_profile=strategy_definition.profile,

tests/test_runtime_config_support.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from runtime_config_support import (
1616
DEFAULT_ACCOUNT_REGION,
17+
DEFAULT_LONGPORT_SECRET_NAME,
1718
DEFAULT_STRATEGY_PROFILE,
1819
infer_account_region,
1920
load_platform_runtime_settings,
@@ -27,7 +28,7 @@ def test_load_platform_runtime_settings_uses_defaults(self):
2728
settings = load_platform_runtime_settings(project_id_resolver=lambda: "project-1")
2829

2930
self.assertEqual(settings.project_id, "project-1")
30-
self.assertEqual(settings.secret_name, "longport_token")
31+
self.assertEqual(settings.secret_name, DEFAULT_LONGPORT_SECRET_NAME)
3132
self.assertEqual(settings.account_prefix, "DEFAULT")
3233
self.assertEqual(settings.service_name, "longbridge-quant-semiconductor-rotation-income")
3334
self.assertEqual(settings.strategy_profile, DEFAULT_STRATEGY_PROFILE)

0 commit comments

Comments
 (0)