Skip to content

Commit 0ece0b1

Browse files
Pigbibicodex
andcommitted
Fix account mapping collisions between platform-prefixed keys
Co-Authored-By: Codex <noreply@openai.com>
1 parent 920b91c commit 0ece0b1

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

tests/test_cash_financing.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,43 @@ console.log("\n=== 11. currentEntryForAccount 映射健壮性 ===\n");
11651165
assert(entry && entry.runtime_target_enabled === true, "11g: separator variants should fallback-match");
11661166
}
11671167

1168+
// 11h: 避免平台前缀歧义导致误匹配(longbridge/ibkr 多账号)
1169+
{
1170+
const state = {
1171+
currentStrategies: {
1172+
longbridge: {
1173+
"longbridge-hk": { runtime_target_enabled: false, reserved_cash_ratio: "0.11" },
1174+
"longbridge-sg": { runtime_target_enabled: true, reserved_cash_ratio: "0.03" },
1175+
},
1176+
ibkr: {
1177+
"ibkr-primary": { runtime_target_enabled: false, reserved_cash_ratio: "0.20" },
1178+
"ibkr-soxl": { runtime_target_enabled: true, reserved_cash_ratio: "0.05" },
1179+
},
1180+
},
1181+
};
1182+
const longbridgeSg = { key: "longbridge-sg", label: "LB|SG", target_name: "longbridge-sg" };
1183+
const longbridgeEntry = currentEntryForAccount(state, "longbridge", longbridgeSg);
1184+
assert(
1185+
longbridgeEntry && longbridgeEntry.runtime_target_enabled === true,
1186+
"11h-a: longbridge-sg should match longbridge-sg entry instead of longbridge-hk",
1187+
);
1188+
assert(
1189+
longbridgeEntry && longbridgeEntry.reserved_cash_ratio === "0.03",
1190+
"11h-b: longbridge-sg should use its own reserved_cash_ratio",
1191+
);
1192+
1193+
const ibkrSoxl = { key: "ibkr-soxl", label: "IBKR-SOXL", target_name: "ibkr-soxl" };
1194+
const ibkrEntry = currentEntryForAccount(state, "ibkr", ibkrSoxl);
1195+
assert(
1196+
ibkrEntry && ibkrEntry.runtime_target_enabled === true,
1197+
"11h-c: ibkr-soxl should match ibkr-soxl entry instead of ibkr-primary",
1198+
);
1199+
assert(
1200+
ibkrEntry && ibkrEntry.reserved_cash_ratio === "0.05",
1201+
"11h-d: ibkr-soxl should use its own reserved_cash_ratio",
1202+
);
1203+
}
1204+
11681205
// ============================================================
11691206
// 12. syncOptionOverlayForAccount (解析为具体值)
11701207
// ============================================================

web/strategy-switch-console/app.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,10 +1248,7 @@
12481248
if (compact) candidates.add(compact);
12491249

12501250
const parts = key.split(/[^a-z0-9]+/).filter(Boolean);
1251-
for (const part of parts) candidates.add(part);
1252-
if (parts.length > 1) {
1253-
candidates.add(parts[parts.length - 1]);
1254-
}
1251+
if (parts.length > 1) candidates.add(parts[parts.length - 1]);
12551252
}
12561253
return [...candidates];
12571254
}

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)