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
54 changes: 54 additions & 0 deletions tests/test_cash_financing.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ function syncCashOnlyExecutionForAccount(state, form, platform, account) {
form.cashOnlyExecutionMode = effective === true ? "enabled" : (effective === false ? "disabled" : "current");
}

function syncStrategyForAccount(state, form, platform, account) {
if (!form) return;
const selected = account || makeAccount("preview");
syncReservePolicyForAccount(state, form, platform, selected);
syncCashOnlyExecutionForAccount(state, form, platform, selected);
reconcileExecutionCashPolicy(form, "margin");
}

// --- 初始加载互斥检查(从 syncStrategyForAccount 提取) ---
function enforceMutualExclusionAfterSync(form) {
if (form && allowMarginExplicitlySelected(form)) {
Expand Down Expand Up @@ -781,6 +789,52 @@ console.log("\n=== 8. 回归测试:旧行为不应出现 ===\n");
assert(form.reservePolicyMode === "none", "8c: schwab reserve cleared to 'none'");
}

// ============================================================
// 15. syncStrategyForAccount 初始互斥纠偏
// ============================================================

console.log("\n=== 15. syncStrategyForAccount 初始互斥纠偏 ===\n");

// 15a: 融资映射+预留现金配置时,应在同步后清空为 none(修复初始映射 bug)
{
const state = {
currentStrategies: {
longbridge: {
sg: {
cash_only_execution: false, // financing allowed
min_reserved_cash_usd: "10000",
reserved_cash_ratio: "0.05",
},
},
},
};
const form = defaultReserveForm();
syncStrategyForAccount(state, form, "longbridge", makeAccount("sg"));
assert(form.cashOnlyExecutionMode === "disabled", "15a: cash-only mode resolves to disabled (allow margin)");
assert(form.reservePolicyMode === "none", "15a: reserve policy auto-cleared to none");
}

// 15b: cash-only=enabled 时,不应清空已有预留现金
{
const state = {
currentStrategies: {
longbridge: {
sg: {
cash_only_execution: true, // no financing
min_reserved_cash_usd: "10000",
reserved_cash_ratio: "0.05",
},
},
},
};
const form = defaultReserveForm();
syncStrategyForAccount(state, form, "longbridge", makeAccount("sg"));
assert(form.cashOnlyExecutionMode === "enabled", "15b: cash-only mode resolves to enabled (no margin)");
assert(form.reservePolicyMode === "max", "15b: reserve policy keeps max");
assert(form.minReservedCashUsd === "10000", "15b: reserve floor preserved");
assert(form.reservedCashRatio === "0.05", "15b: reserve ratio preserved");
}

// ============================================================
// 9. syncRuntimeTargetForAccount (解析为具体值)
// ============================================================
Expand Down
1 change: 1 addition & 0 deletions web/strategy-switch-console/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -1451,6 +1451,7 @@
syncIncomeLayerForAccount(platform);
syncOptionOverlayForAccount(platform);
syncCashOnlyExecutionForAccount(platform);
reconcileExecutionCashPolicy(state.forms[platform], "margin");
syncDcaForAccount(platform);
}

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

Large diffs are not rendered by default.

Loading