From e22048fe0d9a6b6fc7a12a9d1b190dd79a1ad55b Mon Sep 17 00:00:00 2001 From: ddrwode <34234@3来 34> Date: Fri, 6 Feb 2026 14:09:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=89=8D=E6=94=B9=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../四分之一,五分钟,反手条件充足_保守模式.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bitmart/保守模式参数优化/四分之一,五分钟,反手条件充足_保守模式.py b/bitmart/保守模式参数优化/四分之一,五分钟,反手条件充足_保守模式.py index cc0b47d..b877420 100644 --- a/bitmart/保守模式参数优化/四分之一,五分钟,反手条件充足_保守模式.py +++ b/bitmart/保守模式参数优化/四分之一,五分钟,反手条件充足_保守模式.py @@ -142,6 +142,9 @@ class BitmartFuturesTransactionConservative: self.auto_optimize_stability_weight = float(os.getenv("BITMART_AUTO_OPT_STABILITY_WEIGHT", "0.6")) self.auto_optimize_stress_slippage = os.getenv("BITMART_AUTO_OPT_STRESS_SLIPPAGE", "0.8,1.0,1.2,1.4") self.auto_optimize_stress_fee = os.getenv("BITMART_AUTO_OPT_STRESS_FEE", "1.0,1.15,1.3") + self.auto_optimize_allow_method_fallback = os.getenv( + "BITMART_AUTO_OPT_ALLOW_METHOD_FALLBACK", "1" + ).strip().lower() not in {"0", "false", "off", "no"} self.auto_optimize_data_file = os.getenv("BITMART_AUTO_OPT_DATA_FILE", "").strip() self.auto_optimize_script_path = Path(__file__).with_name("optimize_params.py") self.auto_optimized_this_run = False @@ -256,6 +259,20 @@ class BitmartFuturesTransactionConservative: output_path = self.get_runtime_params_path() output_path.parent.mkdir(parents=True, exist_ok=True) + method = str(self.auto_optimize_method).strip().lower() or "auto" + if method not in {"auto", "optuna", "random"}: + logger.warning(f"未知优化方法 {method},自动改为 auto") + method = "auto" + if method == "optuna" and self.auto_optimize_allow_method_fallback: + try: + import optuna # noqa: F401 + except Exception: + logger.warning( + "当前环境未安装 optuna,启动前优化自动降级为 random。" + "如需 optuna,请执行: pip install optuna" + ) + method = "random" + cmd = [ sys.executable, str(script_path), @@ -272,7 +289,7 @@ class BitmartFuturesTransactionConservative: "--window-step-days", str(self.auto_optimize_window_step_days), "--method", - str(self.auto_optimize_method), + method, "--n-trials", str(self.auto_optimize_n_trials), "--valid-score-weight",