Skip to content

Commit 117ecec

Browse files
committed
De-hardcode all platform functions (domainLabel/margin/dry-run/DCA/cash) via platformConfig
1 parent 383637b commit 117ecec

4 files changed

Lines changed: 149 additions & 29 deletions

File tree

platform-config.json

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@
4949
"supported_domains": [
5050
"us_equity",
5151
"hk_equity"
52-
]
52+
],
53+
"cash_currency": "USD",
54+
"default_execution_mode": "live"
5355
},
5456
"deployment": {
5557
"default_execution_mode": "live",
5658
"dry_run_only": false,
5759
"env_repo_key": [
5860
"STRATEGY_SWITCH_LONGBRIDGE_REPO",
5961
"RUNTIME_SETTINGS_LONGBRIDGE_REPO"
60-
]
62+
],
63+
"service_name": "longbridge-quant-service"
6164
}
6265
},
6366
"ibkr": {
@@ -85,15 +88,18 @@
8588
"supported_domains": [
8689
"us_equity",
8790
"hk_equity"
88-
]
91+
],
92+
"cash_currency": "USD",
93+
"default_execution_mode": "live"
8994
},
9095
"deployment": {
9196
"default_execution_mode": "live",
9297
"dry_run_only": false,
9398
"env_repo_key": [
9499
"STRATEGY_SWITCH_IBKR_REPO",
95100
"RUNTIME_SETTINGS_IBKR_REPO"
96-
]
101+
],
102+
"service_name": "ibkr-quant-service"
97103
}
98104
},
99105
"schwab": {
@@ -119,15 +125,18 @@
119125
"target_name": "preview",
120126
"supported_domains": [
121127
"us_equity"
122-
]
128+
],
129+
"cash_currency": "USD",
130+
"default_execution_mode": "live"
123131
},
124132
"deployment": {
125133
"default_execution_mode": "live",
126134
"dry_run_only": false,
127135
"env_repo_key": [
128136
"STRATEGY_SWITCH_SCHWAB_REPO",
129137
"RUNTIME_SETTINGS_SCHWAB_REPO"
130-
]
138+
],
139+
"service_name": "schwab-quant-service"
131140
}
132141
},
133142
"firstrade": {
@@ -153,15 +162,18 @@
153162
"target_name": "preview",
154163
"supported_domains": [
155164
"us_equity"
156-
]
165+
],
166+
"cash_currency": "USD",
167+
"default_execution_mode": "live"
157168
},
158169
"deployment": {
159170
"default_execution_mode": "live",
160171
"dry_run_only": false,
161172
"env_repo_key": [
162173
"STRATEGY_SWITCH_FIRSTRADE_REPO",
163174
"RUNTIME_SETTINGS_FIRSTRADE_REPO"
164-
]
175+
],
176+
"service_name": "firstrade-quant-service"
165177
}
166178
},
167179
"qmt": {
@@ -197,7 +209,8 @@
197209
"env_repo_key": [
198210
"STRATEGY_SWITCH_QMT_REPO",
199211
"RUNTIME_SETTINGS_QMT_REPO"
200-
]
212+
],
213+
"service_name": "qmt-quant-service"
201214
}
202215
},
203216
"binance": {
@@ -224,15 +237,18 @@
224237
"supported_domains": [
225238
"crypto"
226239
],
227-
"default_strategy_profile": "crypto_equity_combo"
240+
"default_strategy_profile": "crypto_equity_combo",
241+
"cash_currency": "USD",
242+
"default_execution_mode": "live"
228243
},
229244
"deployment": {
230245
"default_execution_mode": "live",
231246
"dry_run_only": false,
232247
"env_repo_key": [
233248
"STRATEGY_SWITCH_BINANCE_REPO",
234249
"RUNTIME_SETTINGS_BINANCE_REPO"
235-
]
250+
],
251+
"service_name": "binance-quant-service"
236252
}
237253
}
238254
},

scripts/build_config.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ def build_css_vars(config: dict) -> str:
111111

112112

113113
def build_platform_meta_js(config: dict) -> str:
114-
"""Generate platformMeta + defaultRepositories JS block."""
114+
"""Generate platformMeta + capabilities + domain labels + default repos."""
115115
platforms = config.get("platforms", {})
116+
domains = config.get("domains", {})
116117
lines = []
117118
lines.append(" let platformMeta = {")
118119
for pid, pdata in sorted(platforms.items()):
@@ -128,9 +129,36 @@ def build_platform_meta_js(config: dict) -> str:
128129
lines.append("")
129130
lines.append(" const defaultAccountOptions = {")
130131
for pid, pdata in sorted(platforms.items()):
131-
acct = pdata["default_account"]
132+
acct = dict(pdata["default_account"])
133+
# Add deployment fields for capabilities
134+
dep = pdata.get("deployment", {})
135+
caps = pdata.get("capabilities", {})
132136
lines.append(f" {pid}: [{json.dumps(acct, ensure_ascii=False)}],")
133137
lines.append(" };")
138+
# Domain labels for i18n
139+
lines.append("")
140+
lines.append(" const domainLabels = {")
141+
for did, ddata in sorted(domains.items()):
142+
lines.append(f' {did}: {{ zh: "{ddata["label_zh"]}", en: "{ddata["label_en"]}" }},')
143+
lines.append(" };")
144+
# Platform capabilities for behavior functions
145+
lines.append("")
146+
lines.append(" const platformConfig = {")
147+
for pid, pdata in sorted(platforms.items()):
148+
caps = pdata.get("capabilities", {})
149+
dep = pdata.get("deployment", {})
150+
lines.append(f' {pid}: {{')
151+
lines.append(f' dry_run_only: {"true" if dep.get("dry_run_only") else "false"},')
152+
lines.append(f' margin_policy: {"true" if caps.get("margin_policy") else "false"},')
153+
lines.append(f' reserved_cash: {"true" if caps.get("reserved_cash") else "false"},')
154+
lines.append(f' income_layer: {"true" if caps.get("income_layer") else "false"},')
155+
lines.append(f' option_overlay: {"true" if caps.get("option_overlay") else "false"},')
156+
lines.append(f' dca: {"true" if caps.get("dca") else "false"},')
157+
lines.append(f' execution_mode: "{dep.get("default_execution_mode", "live")}",')
158+
lines.append(f' service_name: "{dep.get("service_name", "")}",')
159+
lines.append(f' default_execution_mode: "{dep.get("default_execution_mode", "live")}"')
160+
lines.append(" },")
161+
lines.append(" };")
134162
return "\n".join(lines)
135163

136164

web/strategy-switch-console/index.html

Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,14 +1505,93 @@ <h2 data-i18n="summary">切换摘要</h2>
15051505
const defaultRepositories = platformRepositories;
15061506

15071507
const defaultAccountOptions = {
1508-
binance: [{"key": "preview", "label": "Binance", "target_name": "crypto_combo", "supported_domains": ["crypto"], "default_strategy_profile": "crypto_equity_combo"}],
1509-
firstrade: [{"key": "preview", "label": "Firstrade", "target_name": "preview", "supported_domains": ["us_equity"]}],
1510-
ibkr: [{"key": "preview", "label": "IBKR", "target_name": "preview", "supported_domains": ["us_equity", "hk_equity"]}],
1511-
longbridge: [{"key": "preview", "label": "LongBridge", "target_name": "preview", "supported_domains": ["us_equity", "hk_equity"]}],
1508+
binance: [{"key": "preview", "label": "Binance", "target_name": "crypto_combo", "supported_domains": ["crypto"], "default_strategy_profile": "crypto_equity_combo", "cash_currency": "USD", "default_execution_mode": "live"}],
1509+
firstrade: [{"key": "preview", "label": "Firstrade", "target_name": "preview", "supported_domains": ["us_equity"], "cash_currency": "USD", "default_execution_mode": "live"}],
1510+
ibkr: [{"key": "preview", "label": "IBKR", "target_name": "preview", "supported_domains": ["us_equity", "hk_equity"], "cash_currency": "USD", "default_execution_mode": "live"}],
1511+
longbridge: [{"key": "preview", "label": "LongBridge", "target_name": "preview", "supported_domains": ["us_equity", "hk_equity"], "cash_currency": "USD", "default_execution_mode": "live"}],
15121512
qmt: [{"key": "preview", "label": "QMT dry-run", "target_name": "industry_etf_dry_run", "cash_currency": "CNY", "default_strategy_profile": "cn_industry_etf_rotation", "supported_domains": ["cn_equity"]}],
1513-
schwab: [{"key": "preview", "label": "Schwab", "target_name": "preview", "supported_domains": ["us_equity"]}],
1513+
schwab: [{"key": "preview", "label": "Schwab", "target_name": "preview", "supported_domains": ["us_equity"], "cash_currency": "USD", "default_execution_mode": "live"}],
15141514
};
15151515

1516+
const domainLabels = {
1517+
cn_equity: { zh: "A股", en: "CN A-share" },
1518+
crypto: { zh: "加密", en: "Crypto" },
1519+
hk_equity: { zh: "港股", en: "HK Equity" },
1520+
us_equity: { zh: "美股", en: "US Equity" },
1521+
};
1522+
1523+
const platformConfig = {
1524+
binance: {
1525+
dry_run_only: false,
1526+
margin_policy: false,
1527+
reserved_cash: false,
1528+
income_layer: false,
1529+
option_overlay: false,
1530+
dca: true,
1531+
execution_mode: "live",
1532+
service_name: "binance-quant-service",
1533+
default_execution_mode: "live"
1534+
},
1535+
firstrade: {
1536+
dry_run_only: false,
1537+
margin_policy: true,
1538+
reserved_cash: true,
1539+
income_layer: true,
1540+
option_overlay: true,
1541+
dca: true,
1542+
execution_mode: "live",
1543+
service_name: "firstrade-quant-service",
1544+
default_execution_mode: "live"
1545+
},
1546+
ibkr: {
1547+
dry_run_only: false,
1548+
margin_policy: true,
1549+
reserved_cash: true,
1550+
income_layer: true,
1551+
option_overlay: true,
1552+
dca: false,
1553+
execution_mode: "live",
1554+
service_name: "ibkr-quant-service",
1555+
default_execution_mode: "live"
1556+
},
1557+
longbridge: {
1558+
dry_run_only: false,
1559+
margin_policy: true,
1560+
reserved_cash: true,
1561+
income_layer: true,
1562+
option_overlay: true,
1563+
dca: false,
1564+
execution_mode: "live",
1565+
service_name: "longbridge-quant-service",
1566+
default_execution_mode: "live"
1567+
},
1568+
qmt: {
1569+
dry_run_only: true,
1570+
margin_policy: false,
1571+
reserved_cash: false,
1572+
income_layer: false,
1573+
option_overlay: false,
1574+
dca: false,
1575+
execution_mode: "paper",
1576+
service_name: "qmt-quant-service",
1577+
default_execution_mode: "paper"
1578+
},
1579+
schwab: {
1580+
dry_run_only: false,
1581+
margin_policy: true,
1582+
reserved_cash: true,
1583+
income_layer: true,
1584+
option_overlay: true,
1585+
dca: false,
1586+
execution_mode: "live",
1587+
service_name: "schwab-quant-service",
1588+
default_execution_mode: "live"
1589+
},
1590+
};
1591+
1592+
1593+
1594+
15161595

15171596

15181597

@@ -2074,21 +2153,21 @@ <h2 data-i18n="summary">切换摘要</h2>
20742153
}
20752154

20762155
function domainLabel(domain) {
2077-
if (domain === "hk_equity") return t("hkEquity");
2078-
if (domain === "cn_equity") return t("cnEquity");
2079-
return t("usEquity");
2156+
const entry = domainLabels[domain];
2157+
if (entry) return state.lang === "zh" ? entry.zh : entry.en;
2158+
return domain;
20802159
}
20812160

20822161
function platformSupportsMarginPolicy(platform = state.selected) {
2083-
return platform !== "qmt" && platform !== "binance";
2162+
return platformConfig[platform]?.margin_policy ?? true;
20842163
}
20852164

20862165
function platformSupportsReservedCashPolicy(platform = state.selected) {
2087-
return platform !== "qmt" && platform !== "binance";
2166+
return platformConfig[platform]?.reserved_cash ?? true;
20882167
}
20892168

20902169
function platformDryRunOnly(platform = state.selected) {
2091-
return platform === "qmt";
2170+
return platformConfig[platform]?.dry_run_only ?? false;
20922171
}
20932172

20942173
function allowMarginExplicitlySelected(form) {
@@ -2127,9 +2206,6 @@ <h2 data-i18n="summary">切换摘要</h2>
21272206
const domain = strategyDomain(state.forms[platform]?.strategy);
21282207
if (domain === "hk_equity") return "HKD";
21292208
if (domain === "cn_equity") return "CNY";
2130-
const supported = supportedDomainsForAccount(platform, account);
2131-
if (supported.length === 1 && supported[0] === "hk_equity") return "HKD";
2132-
if (supported.length === 1 && supported[0] === "cn_equity") return "CNY";
21332209
return "USD";
21342210
}
21352211

@@ -2291,7 +2367,7 @@ <h2 data-i18n="summary">切换摘要</h2>
22912367
}
22922368

22932369
function platformSupportsDca(platform = state.selected) {
2294-
return platform === "firstrade" || platform === "binance";
2370+
return platformConfig[platform]?.dca ?? false;
22952371
}
22962372

22972373
function strategyAllowedForAccount(platform, account, profile) {

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.

0 commit comments

Comments
 (0)