From 345416e32fe46122036ec8eb48f802cbdccb7a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=87=E8=96=87=E5=AE=89?= Date: Sat, 14 Feb 2026 14:55:40 +0800 Subject: [PATCH] 1 --- backend/api/routes/config.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/backend/api/routes/config.py b/backend/api/routes/config.py index 39d25ba..886d248 100644 --- a/backend/api/routes/config.py +++ b/backend/api/routes/config.py @@ -52,6 +52,25 @@ USER_RISK_KNOBS = { "SCAN_INTERVAL", } +# 普通用户/关联账号可见的配置项默认值(含 category),确保「市场扫描」「仓位控制」「风险控制」分组都能展示 +USER_VISIBLE_DEFAULTS = { + "MIN_MARGIN_USDT": {"value": 5.0, "type": "number", "category": "risk", "description": "最小单笔保证金(USDT),低于此值不下单"}, + "MIN_POSITION_PERCENT": {"value": 0.0, "type": "number", "category": "position", "description": "最小单笔保证金占比(%),0 表示不限制"}, + "MAX_POSITION_PERCENT": {"value": 2.0, "type": "number", "category": "position", "description": "单笔最大保证金占比(%)"}, + "MAX_TOTAL_POSITION_PERCENT": {"value": 20.0, "type": "number", "category": "position", "description": "总仓位最大保证金占比(%)"}, + "AUTO_TRADE_ENABLED": {"value": True, "type": "boolean", "category": "risk", "description": "自动交易总开关:关闭后仅生成推荐,不会自动下单"}, + "MAX_OPEN_POSITIONS": {"value": 3, "type": "number", "category": "position", "description": "同时持仓数量上限"}, + "MAX_DAILY_ENTRIES": {"value": 8, "type": "number", "category": "risk", "description": "每日最多开仓次数"}, + "TOP_N_SYMBOLS": {"value": 8, "type": "number", "category": "scan", "description": "每次扫描后优先处理的交易对数量"}, + "MIN_SIGNAL_STRENGTH": {"value": 8, "type": "number", "category": "scan", "description": "最小信号强度(0-10)"}, + "MIN_VOLUME_24H": {"value": 30_000_000, "type": "number", "category": "scan", "description": "24h 成交量下限(USD)"}, + "MIN_VOLATILITY": {"value": 3.0, "type": "number", "category": "scan", "description": "最小波动率过滤"}, + "SCAN_EXTRA_SYMBOLS_FOR_SUPPLEMENT": {"value": 8, "type": "number", "category": "scan", "description": "智能补单多返回的候选数量"}, + "EXCLUDE_MAJOR_COINS": {"value": True, "type": "boolean", "category": "scan", "description": "是否排除主流币(BTC/ETH 等)"}, + "MAX_SCAN_SYMBOLS": {"value": 1500, "type": "number", "category": "scan", "description": "最大扫描交易对数量"}, + "SCAN_INTERVAL": {"value": 1800, "type": "number", "category": "scan", "description": "市场扫描间隔(秒)"}, +} + RISK_KNOBS_DEFAULTS = { "AUTO_TRADE_ENABLED": { "value": True, @@ -300,6 +319,10 @@ async def get_all_configs( is_admin = (user.get("role") or "user") == "admin" gid = _global_strategy_account_id() if (not is_admin) or (is_admin and int(account_id) != int(gid)): + # 先补齐用户可见项的默认值(含 category),避免关联账号因 DB 无记录而缺少「市场扫描」「仓位控制」等分组 + for k in USER_RISK_KNOBS: + if k not in result and k in USER_VISIBLE_DEFAULTS: + result[k] = USER_VISIBLE_DEFAULTS[k] allowed = set(USER_RISK_KNOBS) | {"BINANCE_API_KEY", "BINANCE_API_SECRET", "USE_TESTNET"} result = {k: v for k, v in result.items() if k in allowed} return result