Skip to content

Commit 7246d80

Browse files
Pigbibicodex
andcommitted
Fix initial cash/reserve sync conflict for margin mapping
Co-Authored-By: Codex <noreply@openai.com>
1 parent 7e1c84a commit 7246d80

3 files changed

Lines changed: 56 additions & 1 deletion

File tree

tests/test_cash_financing.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,14 @@ function syncCashOnlyExecutionForAccount(state, form, platform, account) {
271271
form.cashOnlyExecutionMode = effective === true ? "enabled" : (effective === false ? "disabled" : "current");
272272
}
273273

274+
function syncStrategyForAccount(state, form, platform, account) {
275+
if (!form) return;
276+
const selected = account || makeAccount("preview");
277+
syncReservePolicyForAccount(state, form, platform, selected);
278+
syncCashOnlyExecutionForAccount(state, form, platform, selected);
279+
reconcileExecutionCashPolicy(form, "margin");
280+
}
281+
274282
// --- 初始加载互斥检查(从 syncStrategyForAccount 提取) ---
275283
function enforceMutualExclusionAfterSync(form) {
276284
if (form && allowMarginExplicitlySelected(form)) {
@@ -781,6 +789,52 @@ console.log("\n=== 8. 回归测试:旧行为不应出现 ===\n");
781789
assert(form.reservePolicyMode === "none", "8c: schwab reserve cleared to 'none'");
782790
}
783791

792+
// ============================================================
793+
// 15. syncStrategyForAccount 初始互斥纠偏
794+
// ============================================================
795+
796+
console.log("\n=== 15. syncStrategyForAccount 初始互斥纠偏 ===\n");
797+
798+
// 15a: 融资映射+预留现金配置时,应在同步后清空为 none(修复初始映射 bug)
799+
{
800+
const state = {
801+
currentStrategies: {
802+
longbridge: {
803+
sg: {
804+
cash_only_execution: false, // financing allowed
805+
min_reserved_cash_usd: "10000",
806+
reserved_cash_ratio: "0.05",
807+
},
808+
},
809+
},
810+
};
811+
const form = defaultReserveForm();
812+
syncStrategyForAccount(state, form, "longbridge", makeAccount("sg"));
813+
assert(form.cashOnlyExecutionMode === "disabled", "15a: cash-only mode resolves to disabled (allow margin)");
814+
assert(form.reservePolicyMode === "none", "15a: reserve policy auto-cleared to none");
815+
}
816+
817+
// 15b: cash-only=enabled 时,不应清空已有预留现金
818+
{
819+
const state = {
820+
currentStrategies: {
821+
longbridge: {
822+
sg: {
823+
cash_only_execution: true, // no financing
824+
min_reserved_cash_usd: "10000",
825+
reserved_cash_ratio: "0.05",
826+
},
827+
},
828+
},
829+
};
830+
const form = defaultReserveForm();
831+
syncStrategyForAccount(state, form, "longbridge", makeAccount("sg"));
832+
assert(form.cashOnlyExecutionMode === "enabled", "15b: cash-only mode resolves to enabled (no margin)");
833+
assert(form.reservePolicyMode === "max", "15b: reserve policy keeps max");
834+
assert(form.minReservedCashUsd === "10000", "15b: reserve floor preserved");
835+
assert(form.reservedCashRatio === "0.05", "15b: reserve ratio preserved");
836+
}
837+
784838
// ============================================================
785839
// 9. syncRuntimeTargetForAccount (解析为具体值)
786840
// ============================================================

web/strategy-switch-console/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@
14511451
syncIncomeLayerForAccount(platform);
14521452
syncOptionOverlayForAccount(platform);
14531453
syncCashOnlyExecutionForAccount(platform);
1454+
reconcileExecutionCashPolicy(state.forms[platform], "margin");
14541455
syncDcaForAccount(platform);
14551456
}
14561457

web/strategy-switch-console/app_js.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)