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
35 changes: 30 additions & 5 deletions tests/strategy_switch_worker_validation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ const accountOptions = __test.normalizeAccountOptionsPayload(
"test_account_options",
);

assert.deepEqual(accountOptions.longbridge[0].supported_domains, ["hk_equity"]);
assert.deepEqual(accountOptions.longbridge[1].supported_domains, ["us_equity"]);
assert.deepEqual(accountOptions.ibkr[0].supported_domains, ["us_equity"]);
assert.deepEqual(accountOptions.longbridge[0].supported_domains, ["us_equity", "hk_equity"]);
assert.deepEqual(accountOptions.longbridge[1].supported_domains, ["us_equity", "hk_equity"]);
assert.deepEqual(accountOptions.ibkr[0].supported_domains, ["us_equity", "hk_equity"]);

const longbridgeHk = __test.assertConfiguredAccount(
{
Expand Down Expand Up @@ -111,13 +111,38 @@ __test.assertStrategyAllowedForAccount(
ibkrAccount,
strategyProfiles,
);
__test.assertStrategyAllowedForAccount(
{
platform: "ibkr",
strategy_profile: "hk_low_vol_dividend_quality_snapshot",
},
ibkrAccount,
strategyProfiles,
);

const schwabAccount = __test.assertConfiguredAccount(
{
platform: "schwab",
target_name: "default",
strategy_profile: "tqqq_growth_income",
},
accountOptions,
);
__test.assertStrategyAllowedForAccount(
{
platform: "schwab",
strategy_profile: "tqqq_growth_income",
},
schwabAccount,
strategyProfiles,
);
assert.throws(
() => __test.assertStrategyAllowedForAccount(
{
platform: "ibkr",
platform: "schwab",
strategy_profile: "hk_low_vol_dividend_quality_snapshot",
},
ibkrAccount,
schwabAccount,
strategyProfiles,
),
/not supported/,
Expand Down
3 changes: 2 additions & 1 deletion web/strategy-switch-console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Each account item supports:
"account_scope": "live-u1599-tqqq",
"service_name": "interactive-brokers-live-u1599-tqqq-service",
"default_strategy_profile": "tqqq_growth_income",
"supported_domains": ["us_equity"]
"supported_domains": ["us_equity", "hk_equity"]
}
```

Expand All @@ -124,6 +124,7 @@ When adding or renaming a strategy profile:
- Run `python3 scripts/sync_strategy_switch_page_asset.py` so `strategy_profiles_asset.js` is regenerated.
- Set `domain` on each strategy profile. Current values are `us_equity` and `hk_equity`.
- Set each affected account's `default_strategy_profile` and `supported_domains` in `account-options.example.json` and the deployed KV account config.
- Use `["us_equity", "hk_equity"]` for LongBridge and IBKR accounts unless you intentionally want to narrow a specific account.
- Update the deployed KV `strategy_profiles` key from `strategy-profiles.example.json`.
- Make sure the platform repository's current `RUNTIME_TARGET_JSON.strategy_profile` or account-specific `CLOUD_RUN_SERVICE_TARGETS_JSON` uses the same id.
- Use lower-case ids with letters, numbers, dot, underscore, dash, or equals only. Do not encode account names or secrets in profile ids.
Expand Down
3 changes: 2 additions & 1 deletion web/strategy-switch-console/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ wrangler secret put STRATEGY_SWITCH_ACCOUNT_OPTIONS_JSON < /tmp/strategy-switch-
"account_scope": "live-u1599-tqqq",
"service_name": "interactive-brokers-live-u1599-tqqq-service",
"default_strategy_profile": "tqqq_growth_income",
"supported_domains": ["us_equity"]
"supported_domains": ["us_equity", "hk_equity"]
}
```

Expand All @@ -131,6 +131,7 @@ Worker 会校验 dispatch 参数必须匹配这里的某个账号项,也会校
- 运行 `python3 scripts/sync_strategy_switch_page_asset.py` 重新生成 `strategy_profiles_asset.js`。
- 给每个策略 profile 设置 `domain`。当前支持 `us_equity` 和 `hk_equity`。
- 在 `account-options.example.json` 和已部署的 KV 账号配置里更新对应账号的 `default_strategy_profile` 和 `supported_domains`。
- LongBridge 和 IBKR 账号默认写 `["us_equity", "hk_equity"]`,除非你明确要把某个账号限制成单市场。
- 用 `strategy-profiles.example.json` 更新已部署 KV 的 `strategy_profiles` key。
- 确认平台仓库当前的 `RUNTIME_TARGET_JSON.strategy_profile` 或账号级 `CLOUD_RUN_SERVICE_TARGETS_JSON` 使用同一个 id。
- profile id 只使用小写字母、数字、点、下划线、短横线或等号。不要把账号名、密码、token、密钥信息写进 profile id。
Expand Down
12 changes: 6 additions & 6 deletions web/strategy-switch-console/account-options.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
"target_name": "hk",
"account_selector": "HK",
"default_strategy_profile": "hk_low_vol_dividend_quality_snapshot",
"supported_domains": ["hk_equity"]
"supported_domains": ["us_equity", "hk_equity"]
},
{
"key": "sg",
"label": "sg",
"target_name": "sg",
"account_selector": "SG",
"default_strategy_profile": "tqqq_growth_income",
"supported_domains": ["us_equity"]
"supported_domains": ["us_equity", "hk_equity"]
},
{
"key": "paper",
"label": "paper",
"target_name": "paper",
"account_selector": "PAPER",
"default_strategy_profile": "mega_cap_leader_rotation_top50_balanced",
"supported_domains": ["us_equity"]
"supported_domains": ["us_equity", "hk_equity"]
}
],
"ibkr": [
Expand All @@ -35,7 +35,7 @@
"account_scope": "live-u1599-tqqq",
"service_name": "interactive-brokers-live-u1599-tqqq-service",
"default_strategy_profile": "tqqq_growth_income",
"supported_domains": ["us_equity"]
"supported_domains": ["us_equity", "hk_equity"]
},
{
"key": "u16608560",
Expand All @@ -46,7 +46,7 @@
"account_scope": "live-u1660-soxl",
"service_name": "interactive-brokers-live-u1660-soxl-service",
"default_strategy_profile": "soxl_soxx_trend_income",
"supported_domains": ["us_equity"]
"supported_domains": ["us_equity", "hk_equity"]
},
{
"key": "u18336562",
Expand All @@ -57,7 +57,7 @@
"account_scope": "live-u1833-smart-dca",
"service_name": "interactive-brokers-live-u1833-smart-dca-service",
"default_strategy_profile": "nasdaq_sp500_smart_dca",
"supported_domains": ["us_equity"]
"supported_domains": ["us_equity", "hk_equity"]
}
],
"schwab": [
Expand Down
28 changes: 8 additions & 20 deletions web/strategy-switch-console/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,9 @@ <h2 data-i18n="summary">切换摘要</h2>

const defaultAccountOptions = {
longbridge: [
{ key: "hk", label: "hk", target_name: "hk", account_selector: "HK", default_strategy_profile: "hk_low_vol_dividend_quality_snapshot", supported_domains: ["hk_equity"] },
{ key: "sg", label: "sg", target_name: "sg", account_selector: "SG", default_strategy_profile: "tqqq_growth_income", supported_domains: ["us_equity"] },
{ key: "paper", label: "paper", target_name: "paper", account_selector: "PAPER", default_strategy_profile: "mega_cap_leader_rotation_top50_balanced", supported_domains: ["us_equity"] },
{ key: "hk", label: "hk", target_name: "hk", account_selector: "HK", default_strategy_profile: "hk_low_vol_dividend_quality_snapshot", supported_domains: ["us_equity", "hk_equity"] },
{ key: "sg", label: "sg", target_name: "sg", account_selector: "SG", default_strategy_profile: "tqqq_growth_income", supported_domains: ["us_equity", "hk_equity"] },
{ key: "paper", label: "paper", target_name: "paper", account_selector: "PAPER", default_strategy_profile: "mega_cap_leader_rotation_top50_balanced", supported_domains: ["us_equity", "hk_equity"] },
],
ibkr: [
{
Expand All @@ -642,7 +642,7 @@ <h2 data-i18n="summary">切换摘要</h2>
account_scope: "live-u1599-tqqq",
service_name: "interactive-brokers-live-u1599-tqqq-service",
default_strategy_profile: "tqqq_growth_income",
supported_domains: ["us_equity"],
supported_domains: ["us_equity", "hk_equity"],
},
{
key: "u16608560",
Expand All @@ -653,7 +653,7 @@ <h2 data-i18n="summary">切换摘要</h2>
account_scope: "live-u1660-soxl",
service_name: "interactive-brokers-live-u1660-soxl-service",
default_strategy_profile: "soxl_soxx_trend_income",
supported_domains: ["us_equity"],
supported_domains: ["us_equity", "hk_equity"],
},
{
key: "u18336562",
Expand All @@ -664,7 +664,7 @@ <h2 data-i18n="summary">切换摘要</h2>
account_scope: "live-u1833-smart-dca",
service_name: "interactive-brokers-live-u1833-smart-dca-service",
default_strategy_profile: "nasdaq_sp500_smart_dca",
supported_domains: ["us_equity"],
supported_domains: ["us_equity", "hk_equity"],
},
],
schwab: [
Expand Down Expand Up @@ -852,20 +852,8 @@ <h2 data-i18n="summary">切换摘要</h2>
}

function inferSupportedDomains(platform, account) {
const tokens = [
account?.key,
account?.label,
account?.target_name,
account?.account_selector,
account?.account_scope,
account?.deployment_selector,
account?.service_name,
]
.join(" ")
.toLowerCase()
.split(/[^a-z0-9]+/)
.filter(Boolean);
if (platform === "longbridge" && tokens.includes("hk")) return ["hk_equity"];
void account;
if (platform === "longbridge" || platform === "ibkr") return ["us_equity", "hk_equity"];
return ["us_equity"];
}

Expand Down
2 changes: 1 addition & 1 deletion web/strategy-switch-console/page_asset.js

Large diffs are not rendered by default.

16 changes: 2 additions & 14 deletions web/strategy-switch-console/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,20 +785,8 @@ function supportedDomainsForAccount(platform, option) {
}

function inferAccountSupportedDomains(platform, option) {
const tokens = [
option?.key,
option?.label,
option?.target_name,
option?.account_selector,
option?.account_scope,
option?.deployment_selector,
option?.service_name,
]
.join(" ")
.toLowerCase()
.split(/[^a-z0-9]+/)
.filter(Boolean);
if (platform === "longbridge" && tokens.includes("hk")) return ["hk_equity"];
void option;
if (platform === "longbridge" || platform === "ibkr") return ["us_equity", "hk_equity"];
return ["us_equity"];
}

Expand Down