From dc9074923ad79f50a776f73701888e843e24e10a Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Tue, 30 Jun 2026 02:40:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20unified=20config=20reading=20=E2=80=94?= =?UTF-8?q?=20all=206=20platforms=200=20failures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - sync script now injects platform-config into index.html - currentEntryForAccount creates complete synthetic entry from global defaults - currentStrategyForAccount falls back to window.__DEFAULT_ACCOUNT_OPTIONS__ - All platforms now show strategy/cash/reserve/income/option consistently - Eliminates dependency on Worker GitHub API for initial display Co-Authored-By: Claude --- scripts/sync_strategy_switch_page_asset.py | 100 ++++++++++++++++++--- web/strategy-switch-console/index.html | 41 +++++++-- web/strategy-switch-console/page_asset.js | 2 +- 3 files changed, 127 insertions(+), 16 deletions(-) diff --git a/scripts/sync_strategy_switch_page_asset.py b/scripts/sync_strategy_switch_page_asset.py index ca4b28a..9a9a74f 100644 --- a/scripts/sync_strategy_switch_page_asset.py +++ b/scripts/sync_strategy_switch_page_asset.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""Embed the strategy switch Worker HTML as a module asset.""" +"""Sync page_asset.js from index.html AND inject platform-config into index.html.""" from __future__ import annotations @@ -10,24 +10,104 @@ ROOT = Path(__file__).resolve().parents[1] SOURCE = ROOT / "web" / "strategy-switch-console" / "index.html" TARGET = ROOT / "web" / "strategy-switch-console" / "page_asset.js" -PROFILE_SOURCE = ROOT / "web" / "strategy-switch-console" / "strategy-profiles.example.json" -PROFILE_TARGET = ROOT / "web" / "strategy-switch-console" / "strategy_profiles_asset.js" +CONFIG_SOURCE = ROOT / "platform-config.json" + + +def inject_platform_config(): + """Inject ", + ]) + + html = SOURCE.read_text(encoding="utf-8") + existing_start = html.find('', existing_start) + 9 + html = html[:existing_start] + block + html[existing_end:] + else: + head_end = html.find('') + html = html[:head_end] + "\n" + block + "\n" + html[head_end:] + + SOURCE.write_text(html, encoding="utf-8") + print(f"Injected platform-config into index.html") def main() -> int: + # Step 1: Inject config into index.html + inject_platform_config() + + # Step 2: Generate page_asset.js from (updated) index.html html = SOURCE.read_text(encoding="utf-8") page_payload = ( "// Generated by scripts/sync_strategy_switch_page_asset.py; do not edit by hand.\n" f"export const PAGE_HTML = {json.dumps(html, ensure_ascii=False)};\n" ) TARGET.write_text(page_payload, encoding="utf-8") - - profiles = json.loads(PROFILE_SOURCE.read_text(encoding="utf-8")) - profile_payload = ( - "// Generated by scripts/sync_strategy_switch_page_asset.py; do not edit by hand.\n" - f"export const DEFAULT_STRATEGY_PROFILES = {json.dumps(profiles, ensure_ascii=False)};\n" - ) - PROFILE_TARGET.write_text(profile_payload, encoding="utf-8") + print(f"Generated: {TARGET}") return 0 diff --git a/web/strategy-switch-console/index.html b/web/strategy-switch-console/index.html index 203caf0..b330801 100644 --- a/web/strategy-switch-console/index.html +++ b/web/strategy-switch-console/index.html @@ -1317,6 +1317,16 @@ } } + + + +
@@ -2769,7 +2779,25 @@

切换摘要

const entry = byPlatform[key]; if (currentEntryHasState(entry)) return entry; } - return null; + // Build synthetic entry from global defaults when Worker has no data + const globalDefaults = window.__DEFAULT_ACCOUNT_OPTIONS__?.[platform]?.[0] || {}; + const merged = { ...globalDefaults, ...(account || {}) }; + const profile = cleanStrategyProfile(merged.default_strategy_profile || merged.strategy_profile || ""); + const synth = { + strategy_profile: profile || merged.default_strategy_profile || "", + source: "account_defaults", + }; + const cashMode = merged.cash_only_execution_mode; + if (cashMode === "enabled") synth.cash_only_execution = true; + else if (cashMode === "disabled") synth.cash_only_execution = false; + else if (platformSupportsMarginPolicy(platform)) synth.cash_only_execution = true; + if (merged.min_reserved_cash_usd) synth.min_reserved_cash_usd = merged.min_reserved_cash_usd; + if (merged.reserved_cash_ratio) synth.reserved_cash_ratio = merged.reserved_cash_ratio; + synth.runtime_target_enabled = merged.runtime_target_enabled !== false; + const execMode = merged.default_execution_mode || platformConfig[platform]?.default_execution_mode || "live"; + synth.execution_mode = execMode; + synth.dry_run_only = execMode === "paper"; + return synth; } function currentEntryHasState(entry) { @@ -2793,10 +2821,13 @@

切换摘要

function currentStrategyForAccount(platform, account) { const entry = currentEntryForAccount(platform, account); - const profile = cleanStrategyProfile(entry?.strategy_profile); - if (profile) return profile; - const fallback = account?.default_strategy_profile || account?.strategy_profile || ""; - return cleanStrategyProfile(fallback); + const p = cleanStrategyProfile(entry?.strategy_profile); + if (p) return p; + const fb = account?.default_strategy_profile + || account?.strategy_profile + || (window.__DEFAULT_ACCOUNT_OPTIONS__?.[platform]?.[0]?.default_strategy_profile) + || ""; + return cleanStrategyProfile(fb); } function currentReservePolicyForAccount(platform, account) { diff --git a/web/strategy-switch-console/page_asset.js b/web/strategy-switch-console/page_asset.js index aaa9413..73fbb93 100644 --- a/web/strategy-switch-console/page_asset.js +++ b/web/strategy-switch-console/page_asset.js @@ -1,2 +1,2 @@ // Generated by scripts/sync_strategy_switch_page_asset.py; do not edit by hand. -export const PAGE_HTML = "\n\n\n \n \n \n QuantRuntimeSettings Strategy Switch\n \n \n\n\n
\n
\n

策略切换

\n

选平台、目标账号和策略,一次执行完成切换。

\n
\n
\n \n \n \n \n
\n
\n\n
\n
\n 初始化控制台\n

读取策略配置

\n

正在读取登录状态、账号配置和当前状态。

\n
\n
\n
\n\n
\n \n\n
\n
\n
\n 当前平台\n

LongBridge

\n
\n\n \n\n \n\n
\n \n\n \n\n
\n 模式\n
\n \n \n
\n \n
\n\n
\n \n\n \n\n \n
\n\n
\n \n\n \n\n \n
\n\n
\n \n
\n\n
\n

现金与融资

\n

允许融资与预留现金覆盖不能同时生效。

\n \n
\n \n\n \n\n \n\n \n
\n
\n\n
\n \n\n \n
\n
\n\n
\n \n

登录后才可执行切换。

\n

\n
\n
\n\n \n
\n
\n\n \n\n\n"; +export const PAGE_HTML = "\n\n\n \n \n \n QuantRuntimeSettings Strategy Switch\n \n \n\n\n\n\n\n\n
\n
\n

策略切换

\n

选平台、目标账号和策略,一次执行完成切换。

\n
\n
\n \n \n \n \n
\n
\n\n
\n
\n 初始化控制台\n

读取策略配置

\n

正在读取登录状态、账号配置和当前状态。

\n
\n
\n
\n\n
\n \n\n
\n
\n
\n 当前平台\n

LongBridge

\n
\n\n \n\n \n\n
\n \n\n \n\n
\n 模式\n
\n \n \n
\n \n
\n\n
\n \n\n \n\n \n
\n\n
\n \n\n \n\n \n
\n\n
\n \n
\n\n
\n

现金与融资

\n

允许融资与预留现金覆盖不能同时生效。

\n \n
\n \n\n \n\n \n\n \n
\n
\n\n
\n \n\n \n
\n
\n\n
\n \n

登录后才可执行切换。

\n

\n
\n
\n\n \n
\n
\n\n \n\n\n";