Skip to content

Commit 92fbe47

Browse files
committed
Show zero platform reserve defaults in switch console
1 parent 32bcd6b commit 92fbe47

5 files changed

Lines changed: 22 additions & 11 deletions

File tree

tests/strategy_switch_worker_validation.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,18 @@ assert.ok(indexHtml.includes('id="reserved-cash-ratio-input"'));
2727
assert.ok(indexHtml.includes('id="reserve-policy-mode-select"'));
2828
assert.ok(indexHtml.includes("account-block"));
2929
assert.ok(indexHtml.includes("strategy-block"));
30+
assert.ok(indexHtml.includes("grid-template-columns: repeat(4, minmax(0, 1fr));"));
31+
assert.ok(indexHtml.includes("grid-column: 1 / span 2;"));
32+
assert.ok(indexHtml.includes("grid-column: 3 / span 2;"));
3033
assert.ok(indexHtml.includes('reservePolicyNone'));
3134
assert.ok(indexHtml.includes('reservePolicyRatio'));
3235
assert.ok(indexHtml.includes('reservePolicyFloor'));
3336
assert.ok(indexHtml.includes('reservePolicyMax'));
3437
assert.ok(indexHtml.includes('reservedCashDefault'));
38+
assert.ok(indexHtml.includes('平台默认:0 {currency} / 0%'));
39+
assert.equal(indexHtml.includes('比例沿用策略默认,通常 3%'), false);
40+
assert.equal(indexHtml.includes('平台默认:max(0 {currency}, 3%)'), false);
41+
assert.ok(indexHtml.includes('function platformReservedCashDefaultText('));
3542
assert.ok(indexHtml.includes('platformMinReservedCashVariables'));
3643
assert.ok(indexHtml.includes('platformReservedCashRatioVariables'));
3744
assert.ok(indexHtml.includes('extra_variables_json'));

web/strategy-switch-console/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ The Worker validates dispatch inputs against this config, including whether the
118118

119119
For signed-in users, `/api/config` also reads the target repositories' current GitHub Variables. It prefers account-specific `CLOUD_RUN_SERVICE_TARGETS_JSON`, then matching `RUNTIME_TARGET_JSON.strategy_profile`, then `STRATEGY_PROFILE`; if none can be read safely, the page falls back to `default_strategy_profile`.
120120

121-
The switch form also accepts optional reserved-cash overrides: minimum reserved cash in the selected account currency and reserved-cash ratio. Set `cash_currency` to `USD` or `HKD` in account config when the account has a fixed cash currency; otherwise the page infers HKD for HK-equity strategy selections and USD for US-equity selections. Leave reserved-cash fields blank to keep the platform's existing defaults. When set, the Worker passes them to `manual-strategy-switch.yml`, which writes the platform-specific variables such as `IBKR_MIN_RESERVED_CASH_USD` and `IBKR_RESERVED_CASH_RATIO`.
121+
The switch form also accepts optional reserved-cash overrides: minimum reserved cash in the selected account currency and reserved-cash ratio. Set `cash_currency` to `USD` or `HKD` in account config when the account has a fixed cash currency; otherwise the page infers HKD for HK-equity strategy selections and USD for US-equity selections. Keeping the current policy leaves existing platform variables unchanged; when no explicit platform variables are configured, the platform source default is no extra reserve (`0` in the account currency and `0%`). When set, the Worker passes the values to `manual-strategy-switch.yml`, which writes the platform-specific variables such as `IBKR_MIN_RESERVED_CASH_USD` and `IBKR_RESERVED_CASH_RATIO`.
122122

123123
Successful strategy switches also sync the selected account's `default_strategy_profile` back to the KV `account_options` key. The web endpoint does this immediately after dispatching the workflow, and the manual GitHub workflow calls the Worker's internal sync endpoint after applying platform variables when the `runtime-strategy-switch` environment variable `STRATEGY_SWITCH_CONSOLE_URL` is set. For that workflow callback, set the GitHub environment secret `STRATEGY_SWITCH_SYNC_TOKEN` to the same value as the Worker secret with that name.
124124

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Worker 会校验 dispatch 参数必须匹配这里的某个账号项,也会校
125125

126126
登录用户访问 `/api/config` 时,Worker 还会读取目标平台仓库的当前 GitHub Variables。读取优先级是账号匹配的 `CLOUD_RUN_SERVICE_TARGETS_JSON`、匹配的 `RUNTIME_TARGET_JSON.strategy_profile``STRATEGY_PROFILE`;都读不到时,页面才回退到 `default_strategy_profile`
127127

128-
切换表单也支持可选的预留现金覆盖项:所选账号币种下的最小预留现金和预留现金比例。如果账号现金币种固定,可以在账号配置里把 `cash_currency` 设为 `USD``HKD`;否则页面会按所选策略推断,港股策略显示 HKD,美股策略显示 USD。预留现金字段留空表示沿用平台现有默认值。填写后,Worker 会把它们传给 `manual-strategy-switch.yml`,由 workflow 写入平台对应变量,例如 `IBKR_MIN_RESERVED_CASH_USD``IBKR_RESERVED_CASH_RATIO`
128+
切换表单也支持可选的预留现金覆盖项:所选账号币种下的最小预留现金和预留现金比例。如果账号现金币种固定,可以在账号配置里把 `cash_currency` 设为 `USD``HKD`;否则页面会按所选策略推断,港股策略显示 HKD,美股策略显示 USD。沿用当前策略会保留平台现有变量;如果平台没有显式配置预留现金变量,源码默认是不额外预留(账号币种 `0`、比例 `0%`。填写后,Worker 会把它们传给 `manual-strategy-switch.yml`,由 workflow 写入平台对应变量,例如 `IBKR_MIN_RESERVED_CASH_USD``IBKR_RESERVED_CASH_RATIO`
129129

130130
策略切换成功后也会把当前账号的 `default_strategy_profile` 同步回 KV 的 `account_options` key。网页接口会在触发 workflow 成功后立即同步;如果 `runtime-strategy-switch` 环境变量里配置了 `STRATEGY_SWITCH_CONSOLE_URL`,手动 GitHub workflow 在写入平台变量后也会回调 Worker 内部接口同步。这个 workflow 回调需要 GitHub 环境 secret `STRATEGY_SWITCH_SYNC_TOKEN`,值要和 Worker 里同名 secret 保持一致。
131131

web/strategy-switch-console/index.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@
406406

407407
.quick-form {
408408
display: grid;
409-
grid-template-columns: minmax(0, 1.2fr) repeat(2, minmax(0, 0.5fr));
409+
grid-template-columns: repeat(4, minmax(0, 1fr));
410410
align-items: start;
411411
gap: 14px;
412412
}
@@ -424,20 +424,20 @@
424424

425425
.account-block,
426426
.mode-block {
427-
grid-column: 1;
427+
grid-column: 1 / span 2;
428428
}
429429

430430
.strategy-block,
431431
.reserve-policy-block {
432-
grid-column: 2 / span 2;
432+
grid-column: 3 / span 2;
433433
}
434434

435435
.min-reserve-block {
436-
grid-column: 2;
436+
grid-column: 1 / span 2;
437437
}
438438

439439
.reserve-ratio-block {
440-
grid-column: 3;
440+
grid-column: 3 / span 2;
441441
}
442442

443443
select,
@@ -916,7 +916,7 @@ <h2 data-i18n="summary">切换摘要</h2>
916916
reservePolicyMax: "固定金额和比例取较大值",
917917
reservedCashModeMeta: "选择是否沿用、清空或覆盖平台预留现金。",
918918
reservedCashNone: "不设置",
919-
reservedCashDefault: "未配置(使用平台内置默认)",
919+
reservedCashDefault: "未配置(平台默认:0 {currency} / 0%)",
920920
reservedCashMeta: "固定金额下限,可单独设置或与比例取较大值。",
921921
reservedCashRatioMeta: "例如 0.03 表示 3%。",
922922
summary: "当前 / 待提交",
@@ -984,7 +984,7 @@ <h2 data-i18n="summary">切换摘要</h2>
984984
reservePolicyMax: "Max of amount and ratio",
985985
reservedCashModeMeta: "Choose whether to keep, clear, or override platform reserved cash.",
986986
reservedCashNone: "None",
987-
reservedCashDefault: "Not configured (uses platform built-in default)",
987+
reservedCashDefault: "Not configured (platform default: 0 {currency} / 0%)",
988988
reservedCashMeta: "Fixed cash floor. Use alone or with a ratio.",
989989
reservedCashRatioMeta: "Use 0.03 for 3%.",
990990
summary: "Current / Pending",
@@ -1431,6 +1431,10 @@ <h2 data-i18n="summary">切换摘要</h2>
14311431
return formatRatioPercent(ratio);
14321432
}
14331433

1434+
function platformReservedCashDefaultText(platform = state.selected, account = selectedAccount(platform)) {
1435+
return t("reservedCashDefault").replace("{currency}", selectedCashCurrency(platform, account));
1436+
}
1437+
14341438
function currentReservedCashPolicyText(platform = state.selected, account = selectedAccount(platform)) {
14351439
const entry = currentEntryForAccount(platform, account);
14361440
const policy = currentReservePolicyForAccount(platform, account);
@@ -1441,7 +1445,7 @@ <h2 data-i18n="summary">切换摘要</h2>
14411445
},
14421446
platform,
14431447
account,
1444-
entry ? t("reservedCashDefault") : t("notRead"),
1448+
entry ? platformReservedCashDefaultText(platform, account) : t("notRead"),
14451449
);
14461450
}
14471451

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)