Skip to content

Commit 4331950

Browse files
authored
Allow LongBridge and IBKR multi-market strategies (#19)
1 parent d23eaf8 commit 4331950

7 files changed

Lines changed: 51 additions & 48 deletions

File tree

tests/strategy_switch_worker_validation.mjs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ const accountOptions = __test.normalizeAccountOptionsPayload(
6969
"test_account_options",
7070
);
7171

72-
assert.deepEqual(accountOptions.longbridge[0].supported_domains, ["hk_equity"]);
73-
assert.deepEqual(accountOptions.longbridge[1].supported_domains, ["us_equity"]);
74-
assert.deepEqual(accountOptions.ibkr[0].supported_domains, ["us_equity"]);
72+
assert.deepEqual(accountOptions.longbridge[0].supported_domains, ["us_equity", "hk_equity"]);
73+
assert.deepEqual(accountOptions.longbridge[1].supported_domains, ["us_equity", "hk_equity"]);
74+
assert.deepEqual(accountOptions.ibkr[0].supported_domains, ["us_equity", "hk_equity"]);
7575

7676
const longbridgeHk = __test.assertConfiguredAccount(
7777
{
@@ -111,13 +111,38 @@ __test.assertStrategyAllowedForAccount(
111111
ibkrAccount,
112112
strategyProfiles,
113113
);
114+
__test.assertStrategyAllowedForAccount(
115+
{
116+
platform: "ibkr",
117+
strategy_profile: "hk_low_vol_dividend_quality_snapshot",
118+
},
119+
ibkrAccount,
120+
strategyProfiles,
121+
);
122+
123+
const schwabAccount = __test.assertConfiguredAccount(
124+
{
125+
platform: "schwab",
126+
target_name: "default",
127+
strategy_profile: "tqqq_growth_income",
128+
},
129+
accountOptions,
130+
);
131+
__test.assertStrategyAllowedForAccount(
132+
{
133+
platform: "schwab",
134+
strategy_profile: "tqqq_growth_income",
135+
},
136+
schwabAccount,
137+
strategyProfiles,
138+
);
114139
assert.throws(
115140
() => __test.assertStrategyAllowedForAccount(
116141
{
117-
platform: "ibkr",
142+
platform: "schwab",
118143
strategy_profile: "hk_low_vol_dividend_quality_snapshot",
119144
},
120-
ibkrAccount,
145+
schwabAccount,
121146
strategyProfiles,
122147
),
123148
/not supported/,

web/strategy-switch-console/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Each account item supports:
104104
"account_scope": "live-u1599-tqqq",
105105
"service_name": "interactive-brokers-live-u1599-tqqq-service",
106106
"default_strategy_profile": "tqqq_growth_income",
107-
"supported_domains": ["us_equity"]
107+
"supported_domains": ["us_equity", "hk_equity"]
108108
}
109109
```
110110

@@ -124,6 +124,7 @@ When adding or renaming a strategy profile:
124124
- Run `python3 scripts/sync_strategy_switch_page_asset.py` so `strategy_profiles_asset.js` is regenerated.
125125
- Set `domain` on each strategy profile. Current values are `us_equity` and `hk_equity`.
126126
- Set each affected account's `default_strategy_profile` and `supported_domains` in `account-options.example.json` and the deployed KV account config.
127+
- Use `["us_equity", "hk_equity"]` for LongBridge and IBKR accounts unless you intentionally want to narrow a specific account.
127128
- Update the deployed KV `strategy_profiles` key from `strategy-profiles.example.json`.
128129
- Make sure the platform repository's current `RUNTIME_TARGET_JSON.strategy_profile` or account-specific `CLOUD_RUN_SERVICE_TARGETS_JSON` uses the same id.
129130
- Use lower-case ids with letters, numbers, dot, underscore, dash, or equals only. Do not encode account names or secrets in profile ids.

web/strategy-switch-console/README.zh-CN.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ wrangler secret put STRATEGY_SWITCH_ACCOUNT_OPTIONS_JSON < /tmp/strategy-switch-
111111
"account_scope": "live-u1599-tqqq",
112112
"service_name": "interactive-brokers-live-u1599-tqqq-service",
113113
"default_strategy_profile": "tqqq_growth_income",
114-
"supported_domains": ["us_equity"]
114+
"supported_domains": ["us_equity", "hk_equity"]
115115
}
116116
```
117117

@@ -131,6 +131,7 @@ Worker 会校验 dispatch 参数必须匹配这里的某个账号项,也会校
131131
- 运行 `python3 scripts/sync_strategy_switch_page_asset.py` 重新生成 `strategy_profiles_asset.js`
132132
- 给每个策略 profile 设置 `domain`。当前支持 `us_equity``hk_equity`
133133
-`account-options.example.json` 和已部署的 KV 账号配置里更新对应账号的 `default_strategy_profile``supported_domains`
134+
- LongBridge 和 IBKR 账号默认写 `["us_equity", "hk_equity"]`,除非你明确要把某个账号限制成单市场。
134135
-`strategy-profiles.example.json` 更新已部署 KV 的 `strategy_profiles` key。
135136
- 确认平台仓库当前的 `RUNTIME_TARGET_JSON.strategy_profile` 或账号级 `CLOUD_RUN_SERVICE_TARGETS_JSON` 使用同一个 id。
136137
- profile id 只使用小写字母、数字、点、下划线、短横线或等号。不要把账号名、密码、token、密钥信息写进 profile id。

web/strategy-switch-console/account-options.example.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@
66
"target_name": "hk",
77
"account_selector": "HK",
88
"default_strategy_profile": "hk_low_vol_dividend_quality_snapshot",
9-
"supported_domains": ["hk_equity"]
9+
"supported_domains": ["us_equity", "hk_equity"]
1010
},
1111
{
1212
"key": "sg",
1313
"label": "sg",
1414
"target_name": "sg",
1515
"account_selector": "SG",
1616
"default_strategy_profile": "tqqq_growth_income",
17-
"supported_domains": ["us_equity"]
17+
"supported_domains": ["us_equity", "hk_equity"]
1818
},
1919
{
2020
"key": "paper",
2121
"label": "paper",
2222
"target_name": "paper",
2323
"account_selector": "PAPER",
2424
"default_strategy_profile": "mega_cap_leader_rotation_top50_balanced",
25-
"supported_domains": ["us_equity"]
25+
"supported_domains": ["us_equity", "hk_equity"]
2626
}
2727
],
2828
"ibkr": [
@@ -35,7 +35,7 @@
3535
"account_scope": "live-u1599-tqqq",
3636
"service_name": "interactive-brokers-live-u1599-tqqq-service",
3737
"default_strategy_profile": "tqqq_growth_income",
38-
"supported_domains": ["us_equity"]
38+
"supported_domains": ["us_equity", "hk_equity"]
3939
},
4040
{
4141
"key": "u16608560",
@@ -46,7 +46,7 @@
4646
"account_scope": "live-u1660-soxl",
4747
"service_name": "interactive-brokers-live-u1660-soxl-service",
4848
"default_strategy_profile": "soxl_soxx_trend_income",
49-
"supported_domains": ["us_equity"]
49+
"supported_domains": ["us_equity", "hk_equity"]
5050
},
5151
{
5252
"key": "u18336562",
@@ -57,7 +57,7 @@
5757
"account_scope": "live-u1833-smart-dca",
5858
"service_name": "interactive-brokers-live-u1833-smart-dca-service",
5959
"default_strategy_profile": "nasdaq_sp500_smart_dca",
60-
"supported_domains": ["us_equity"]
60+
"supported_domains": ["us_equity", "hk_equity"]
6161
}
6262
],
6363
"schwab": [

web/strategy-switch-console/index.html

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,9 @@ <h2 data-i18n="summary">切换摘要</h2>
628628

629629
const defaultAccountOptions = {
630630
longbridge: [
631-
{ key: "hk", label: "hk", target_name: "hk", account_selector: "HK", default_strategy_profile: "hk_low_vol_dividend_quality_snapshot", supported_domains: ["hk_equity"] },
632-
{ key: "sg", label: "sg", target_name: "sg", account_selector: "SG", default_strategy_profile: "tqqq_growth_income", supported_domains: ["us_equity"] },
633-
{ key: "paper", label: "paper", target_name: "paper", account_selector: "PAPER", default_strategy_profile: "mega_cap_leader_rotation_top50_balanced", supported_domains: ["us_equity"] },
631+
{ 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"] },
632+
{ key: "sg", label: "sg", target_name: "sg", account_selector: "SG", default_strategy_profile: "tqqq_growth_income", supported_domains: ["us_equity", "hk_equity"] },
633+
{ 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"] },
634634
],
635635
ibkr: [
636636
{
@@ -642,7 +642,7 @@ <h2 data-i18n="summary">切换摘要</h2>
642642
account_scope: "live-u1599-tqqq",
643643
service_name: "interactive-brokers-live-u1599-tqqq-service",
644644
default_strategy_profile: "tqqq_growth_income",
645-
supported_domains: ["us_equity"],
645+
supported_domains: ["us_equity", "hk_equity"],
646646
},
647647
{
648648
key: "u16608560",
@@ -653,7 +653,7 @@ <h2 data-i18n="summary">切换摘要</h2>
653653
account_scope: "live-u1660-soxl",
654654
service_name: "interactive-brokers-live-u1660-soxl-service",
655655
default_strategy_profile: "soxl_soxx_trend_income",
656-
supported_domains: ["us_equity"],
656+
supported_domains: ["us_equity", "hk_equity"],
657657
},
658658
{
659659
key: "u18336562",
@@ -664,7 +664,7 @@ <h2 data-i18n="summary">切换摘要</h2>
664664
account_scope: "live-u1833-smart-dca",
665665
service_name: "interactive-brokers-live-u1833-smart-dca-service",
666666
default_strategy_profile: "nasdaq_sp500_smart_dca",
667-
supported_domains: ["us_equity"],
667+
supported_domains: ["us_equity", "hk_equity"],
668668
},
669669
],
670670
schwab: [
@@ -852,20 +852,8 @@ <h2 data-i18n="summary">切换摘要</h2>
852852
}
853853

854854
function inferSupportedDomains(platform, account) {
855-
const tokens = [
856-
account?.key,
857-
account?.label,
858-
account?.target_name,
859-
account?.account_selector,
860-
account?.account_scope,
861-
account?.deployment_selector,
862-
account?.service_name,
863-
]
864-
.join(" ")
865-
.toLowerCase()
866-
.split(/[^a-z0-9]+/)
867-
.filter(Boolean);
868-
if (platform === "longbridge" && tokens.includes("hk")) return ["hk_equity"];
855+
void account;
856+
if (platform === "longbridge" || platform === "ibkr") return ["us_equity", "hk_equity"];
869857
return ["us_equity"];
870858
}
871859

web/strategy-switch-console/page_asset.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/strategy-switch-console/worker.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -785,20 +785,8 @@ function supportedDomainsForAccount(platform, option) {
785785
}
786786

787787
function inferAccountSupportedDomains(platform, option) {
788-
const tokens = [
789-
option?.key,
790-
option?.label,
791-
option?.target_name,
792-
option?.account_selector,
793-
option?.account_scope,
794-
option?.deployment_selector,
795-
option?.service_name,
796-
]
797-
.join(" ")
798-
.toLowerCase()
799-
.split(/[^a-z0-9]+/)
800-
.filter(Boolean);
801-
if (platform === "longbridge" && tokens.includes("hk")) return ["hk_equity"];
788+
void option;
789+
if (platform === "longbridge" || platform === "ibkr") return ["us_equity", "hk_equity"];
802790
return ["us_equity"];
803791
}
804792

0 commit comments

Comments
 (0)