1
This commit is contained in:
parent
5f18abbe2f
commit
41630bf580
|
|
@ -240,6 +240,35 @@ async def logs_test_write(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/trading/trigger-scan")
|
||||||
|
async def trigger_scan(
|
||||||
|
_admin: Dict[str, Any] = Depends(require_system_admin),
|
||||||
|
) -> Dict[str, Any]:
|
||||||
|
"""
|
||||||
|
触发手动扫描:
|
||||||
|
通过设置 Redis 信号(ats:trigger-scan),通知所有运行中的 strategy 进程立即执行扫描。
|
||||||
|
"""
|
||||||
|
client = _get_redis_client_for_logs()
|
||||||
|
if client is None:
|
||||||
|
raise HTTPException(status_code=503, detail="Redis 不可用,无法触发扫描")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 设置触发信号(当前时间戳),让 strategy 检测到变化
|
||||||
|
import time
|
||||||
|
ts = int(time.time())
|
||||||
|
# 使用 setex 设置 60秒过期,防止永久残留(虽然 strategy 只关心变化,但过期是个好习惯)
|
||||||
|
# 注意:strategy 端比较的是时间戳大小,所以只要比上一次大即可
|
||||||
|
client.setex("ats:trigger-scan", 600, str(ts))
|
||||||
|
|
||||||
|
return {
|
||||||
|
"message": "已发送扫描触发信号",
|
||||||
|
"timestamp": ts
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"触发扫描失败: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=f"触发扫描失败: {e}")
|
||||||
|
|
||||||
|
|
||||||
def _get_redis_client_for_logs():
|
def _get_redis_client_for_logs():
|
||||||
"""
|
"""
|
||||||
获取 Redis 客户端(优先复用 config_manager 的连接;失败则自行创建)。
|
获取 Redis 客户端(优先复用 config_manager 的连接;失败则自行创建)。
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ DEFAULTS_TO_SYNC = [
|
||||||
"description": "做空时 RSI 低于此值则不做空(避免深超卖反弹)。2026-01-31新增。"},
|
"description": "做空时 RSI 低于此值则不做空(避免深超卖反弹)。2026-01-31新增。"},
|
||||||
{"config_key": "MAX_CHANGE_PERCENT_FOR_SHORT", "config_value": "10", "config_type": "number", "category": "strategy",
|
{"config_key": "MAX_CHANGE_PERCENT_FOR_SHORT", "config_value": "10", "config_type": "number", "category": "strategy",
|
||||||
"description": "做空时 24h 涨跌幅超过此值则不做空(24h 仍大涨时不做空)。单位:百分比数值。2026-01-31新增。"},
|
"description": "做空时 24h 涨跌幅超过此值则不做空(24h 仍大涨时不做空)。单位:百分比数值。2026-01-31新增。"},
|
||||||
{"config_key": "TAKE_PROFIT_1_PERCENT", "config_value": "0.2", "config_type": "number", "category": "strategy",
|
{"config_key": "TAKE_PROFIT_1_PERCENT", "config_value": "0.3", "config_type": "number", "category": "strategy",
|
||||||
"description": "分步止盈第一目标(保证金百分比,如 0.2=20%)。2026-02-12 提高以改善盈亏比。"},
|
"description": "分步止盈第一目标(保证金百分比,如 0.2=20%)。2026-02-12 提高以改善盈亏比。"},
|
||||||
{"config_key": "MIN_RR_FOR_TP1", "config_value": "1.5", "config_type": "number", "category": "strategy",
|
{"config_key": "MIN_RR_FOR_TP1", "config_value": "1.5", "config_type": "number", "category": "strategy",
|
||||||
"description": "第一目标止盈相对止损的最小盈亏比(TP1 至少为止损距离的 1.5 倍)。2026-02-12 新增。"},
|
"description": "第一目标止盈相对止损的最小盈亏比(TP1 至少为止损距离的 1.5 倍)。2026-02-12 新增。"},
|
||||||
|
|
@ -44,10 +44,10 @@ DEFAULTS_TO_SYNC = [
|
||||||
"description": "仓位放大系数:1.0=正常,1.2=+20%,上限2.0。盈利时适度调高可扩大收益。"},
|
"description": "仓位放大系数:1.0=正常,1.2=+20%,上限2.0。盈利时适度调高可扩大收益。"},
|
||||||
{"config_key": "USE_FIXED_RISK_SIZING", "config_value": "true", "config_type": "boolean", "category": "risk",
|
{"config_key": "USE_FIXED_RISK_SIZING", "config_value": "true", "config_type": "boolean", "category": "risk",
|
||||||
"description": "是否启用固定风险仓位计算(推荐)。若启用,则忽略 MAX_POSITION_PERCENT,改用 FIXED_RISK_PERCENT 计算仓位。"},
|
"description": "是否启用固定风险仓位计算(推荐)。若启用,则忽略 MAX_POSITION_PERCENT,改用 FIXED_RISK_PERCENT 计算仓位。"},
|
||||||
{"config_key": "FIXED_RISK_PERCENT", "config_value": "0.025", "config_type": "number", "category": "risk",
|
{"config_key": "FIXED_RISK_PERCENT", "config_value": "0.03", "config_type": "number", "category": "risk",
|
||||||
"description": "每笔交易风险占总账户的百分比(如 0.025=2.5%)。配合止损距离计算仓位,风险可控。"},
|
"description": "每笔交易风险占总账户的百分比(如 0.025=2.5%)。配合止损距离计算仓位,风险可控。"},
|
||||||
{"config_key": "MIN_MARGIN_USDT", "config_value": "2.0", "config_type": "number", "category": "risk",
|
{"config_key": "MIN_MARGIN_USDT", "config_value": "10.0", "config_type": "number", "category": "risk",
|
||||||
"description": "最小保证金(USDT)。2026-02-13 提高到 2.0 USDT 以避免无效小单。"},
|
"description": "最小保证金(USDT)。2026-02-13 提高到 10.0 USDT 以避免无效小单。"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,643 +0,0 @@
|
||||||
{
|
|
||||||
"fetched_at": "2026-02-13T07:58:47.687Z",
|
|
||||||
"note": "display_value 对 PERCENT/PCT 做了百分比换算;敏感字段可选择脱敏/明文。",
|
|
||||||
"preset_detected": null,
|
|
||||||
"system_status": {
|
|
||||||
"running": true,
|
|
||||||
"pid": 4103975,
|
|
||||||
"program": "auto_sys",
|
|
||||||
"state": "RUNNING"
|
|
||||||
},
|
|
||||||
"configs": [
|
|
||||||
{
|
|
||||||
"key": "MAX_POSITION_PERCENT",
|
|
||||||
"category": "position",
|
|
||||||
"category_label": "仓位控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.002,
|
|
||||||
"display_value": 0.2,
|
|
||||||
"description": "预设方案配置项:MAX_POSITION_PERCENT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_TOTAL_POSITION_PERCENT",
|
|
||||||
"category": "position",
|
|
||||||
"category_label": "仓位控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.008,
|
|
||||||
"display_value": 0.8,
|
|
||||||
"description": "预设方案配置项:MAX_TOTAL_POSITION_PERCENT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_POSITION_PERCENT",
|
|
||||||
"category": "position",
|
|
||||||
"category_label": "仓位控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0,
|
|
||||||
"display_value": 0,
|
|
||||||
"description": "预设方案配置项:MIN_POSITION_PERCENT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "AUTO_TRADE_ALLOW_4H_NEUTRAL",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": false,
|
|
||||||
"display_value": false,
|
|
||||||
"description": "AUTO_TRADE_ALLOW_4H_NEUTRAL配置"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "AUTO_TRADE_ONLY_TRENDING",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "AUTO_TRADE_ONLY_TRENDING配置"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "BETA_FILTER_ENABLED",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "大盘共振过滤:BTC/ETH 下跌时屏蔽多单。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "BETA_FILTER_THRESHOLD",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": -0.005,
|
|
||||||
"display_value": -0.005,
|
|
||||||
"description": "大盘共振阈值(比例,如 -0.005 表示 -0.5%)。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_CHASE_MAX_STEPS",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 2,
|
|
||||||
"display_value": 2,
|
|
||||||
"description": "最大追价步数(逐步减小限价回调幅度,靠近当前价)。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_CONFIRM_TIMEOUT_SEC",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 120,
|
|
||||||
"display_value": 120,
|
|
||||||
"description": "下单后确认成交等待时间(秒)。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_MARKET_FALLBACK_AFTER_SEC",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 60,
|
|
||||||
"display_value": 60,
|
|
||||||
"description": "趋势强时:超过该时间仍未成交,会在偏离不超过上限时转市价兜底(减少错过)。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_MAX_DRIFT_PCT_RANGING",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.3,
|
|
||||||
"display_value": 0.3,
|
|
||||||
"description": "震荡/弱趋势最大追价偏离(%)。例如 0.3 表示 0.3%。越小越保守。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_MAX_DRIFT_PCT_TRENDING",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.8,
|
|
||||||
"display_value": 0.8,
|
|
||||||
"description": "趋势强时最大追价偏离(%)。例如 0.6 表示 0.6%。越小越保守。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_SHORT_TREND_FILTER_ENABLED",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "预设方案配置项:ENTRY_SHORT_TREND_FILTER_ENABLED"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_STEP_WAIT_SEC",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 20,
|
|
||||||
"display_value": 20,
|
|
||||||
"description": "每次追价/调整前等待成交时间(秒)。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_SYMBOL_COOLDOWN_SEC",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 1800,
|
|
||||||
"display_value": 1800,
|
|
||||||
"description": "预设方案配置项:ENTRY_SYMBOL_COOLDOWN_SEC"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "LEVERAGE",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 10,
|
|
||||||
"display_value": 10,
|
|
||||||
"description": "基础杠杆倍数"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_CHANGE_PERCENT_FOR_LONG",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.25,
|
|
||||||
"display_value": 25,
|
|
||||||
"description": "做多时 24h 涨跌幅超过此值则不开多(避免追大涨)。单位:百分比数值,如 25 表示 25%。2026-01-31新增。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_CHANGE_PERCENT_FOR_SHORT",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.1,
|
|
||||||
"display_value": 10,
|
|
||||||
"description": "做空时 24h 涨跌幅超过此值则不做空(24h 仍大涨时不做空)。单位:百分比数值。2026-01-31新增。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_LEVERAGE",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 20,
|
|
||||||
"display_value": 20,
|
|
||||||
"description": "最大杠杆倍数(动态杠杆上限,降低到15更保守)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_RSI_FOR_LONG",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 65,
|
|
||||||
"display_value": 65,
|
|
||||||
"description": "做多时 RSI 超过此值则不开多(避免超买区追多)。2026-01-31新增。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_RR_FOR_TP1",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 1.2,
|
|
||||||
"display_value": 1.2,
|
|
||||||
"description": "第一目标止盈相对止损的最小盈亏比(如 1.5 表示 TP1 至少为止损距离的 1.5 倍)。2026-02-12 新增。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_RSI_FOR_SHORT",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 30,
|
|
||||||
"display_value": 30,
|
|
||||||
"description": "做空时 RSI 低于此值则不做空(避免深超卖反弹)。2026-01-31新增。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "RSI_EXTREME_REVERSE_ONLY_NEUTRAL_4H",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": false,
|
|
||||||
"display_value": false,
|
|
||||||
"description": "建议开启:仅在 4H 趋势为中性时允许 RSI 反向单,避免在强趋势里逆势抄底/摸顶,降低风险。关闭则反向可与 4H 同向(仍受“禁止逆4H趋势”约束)。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "SMART_ENTRY_ENABLED",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "预设方案配置项:SMART_ENTRY_ENABLED"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "SYMBOL_LOSS_COOLDOWN_ENABLED",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "是否启用同一交易对连续亏损后的冷却(避免连续亏损后继续交易)。2026-01-29新增。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "SYMBOL_LOSS_COOLDOWN_SEC",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 3600,
|
|
||||||
"display_value": 3600,
|
|
||||||
"description": "连续亏损后的冷却时间(秒),默认1小时。2026-01-29新增。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "SYMBOL_MAX_CONSECUTIVE_LOSSES",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 2,
|
|
||||||
"display_value": 2,
|
|
||||||
"description": "最大允许连续亏损次数(超过则禁止交易该交易对一段时间)。2026-01-29新增。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "TAKE_PROFIT_1_PERCENT",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.2,
|
|
||||||
"display_value": 20,
|
|
||||||
"description": "分步止盈第一目标(保证金百分比,如 0.15=15%)。第一目标触发后了结50%仓位,剩余追求第二目标。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "TRADING_PROFILE",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "string",
|
|
||||||
"value": "conservative",
|
|
||||||
"display_value": "conservative",
|
|
||||||
"description": "交易预设:conservative(稳健,低频+高门槛) / fast(快速验证,高频+宽松过滤)。仅作为默认值,具体参数仍可单独调整。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "TRAILING_STOP_ACTIVATION",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.15,
|
|
||||||
"display_value": 0.15,
|
|
||||||
"description": "移动止损激活阈值(盈利10%后激活,给趋势更多空间)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "TRAILING_STOP_PROTECT",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.05,
|
|
||||||
"display_value": 0.05,
|
|
||||||
"description": "移动止损保护利润(保护5%利润,更合理)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "USE_DYNAMIC_LEVERAGE",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "是否启用动态杠杆(根据信号强度调整杠杆倍数)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "USE_TRAILING_STOP",
|
|
||||||
"category": "strategy",
|
|
||||||
"category_label": "策略参数",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "预设方案配置项:USE_TRAILING_STOP"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ATR_MULTIPLIER_MAX",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.5,
|
|
||||||
"display_value": 0.5,
|
|
||||||
"description": "动态ATR倍数最大值0.5"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ATR_MULTIPLIER_MIN",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.5,
|
|
||||||
"display_value": 0.5,
|
|
||||||
"description": "动态ATR倍数最小值0.5"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ATR_PERIOD",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 7,
|
|
||||||
"display_value": 7,
|
|
||||||
"description": "ATR计算周期(默认7)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ATR_STOP_LOSS_MULTIPLIER",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 2.5,
|
|
||||||
"display_value": 2.5,
|
|
||||||
"description": "ATR止损倍数(0.4 - 0.6倍ATR,信号强 → 倍数低 (0.4);信号弱 → 倍数高 (0.6))"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "FIXED_RISK_PERCENT",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.02,
|
|
||||||
"display_value": 2,
|
|
||||||
"description": "每笔单子承受的风险百分比(相对于总资金)。例如 0.02 表示 2%。启用固定风险后,每笔亏损限制在该百分比内。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_LEVERAGE_SMALL_CAP",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 8,
|
|
||||||
"display_value": 8,
|
|
||||||
"description": "高波动/小众币最大允许杠杆(与之前盈利阶段一致)。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_LEVERAGE",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 8,
|
|
||||||
"display_value": 8,
|
|
||||||
"description": "动态杠杆下限(如 8 表示不低于 8 倍)。之前盈利阶段多为 8x,避免被压到 2–4x 导致单笔盈利过少。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_STOP_LOSS_PRICE_PCT",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.025,
|
|
||||||
"display_value": 2.5,
|
|
||||||
"description": "最小止损价格变动:2%(防止止损过紧)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_TAKE_PROFIT_PRICE_PCT",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.03,
|
|
||||||
"display_value": 3,
|
|
||||||
"description": "最小止盈价格变动:3%(防止止盈过紧)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "POSITION_SCALE_FACTOR",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 1.25,
|
|
||||||
"display_value": 1.25,
|
|
||||||
"description": "仓位放大系数:1.0=正常,1.2=+20% 仓位,1.5=+50%,上限 2.0。盈利时适度调高可扩大收益,仍受单笔上限约束。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "RISK_REWARD_RATIO",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 2,
|
|
||||||
"display_value": 2,
|
|
||||||
"description": "盈亏比(止损距离的倍数,用于计算止盈)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "STOP_LOSS_PERCENT",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.1,
|
|
||||||
"display_value": 10,
|
|
||||||
"description": "止损:10%(相对于保证金)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "TAKE_PROFIT_PERCENT",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.2,
|
|
||||||
"display_value": 20,
|
|
||||||
"description": "预设方案配置项:TAKE_PROFIT_PERCENT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "USE_ATR_STOP_LOSS",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "是否使用ATR动态止损(优先于固定百分比)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "USE_DYNAMIC_ATR_MULTIPLIER",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": false,
|
|
||||||
"display_value": false,
|
|
||||||
"description": "是否根据波动率动态调整ATR倍数"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "USE_FIXED_RISK_SIZING",
|
|
||||||
"category": "risk",
|
|
||||||
"category_label": "风险控制",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "使用固定风险百分比计算仓位(凯利公式)。启用后,每笔单子承受的风险固定为 FIXED_RISK_PERCENT,避免大额亏损。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ATR_TAKE_PROFIT_MULTIPLIER",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 2,
|
|
||||||
"display_value": 2,
|
|
||||||
"description": "预设方案配置项:ATR_TAKE_PROFIT_MULTIPLIER"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "CONFIRM_INTERVAL",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "string",
|
|
||||||
"value": "4h",
|
|
||||||
"display_value": "4h",
|
|
||||||
"description": "确认周期:4小时"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "ENTRY_INTERVAL",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "string",
|
|
||||||
"value": "15m",
|
|
||||||
"display_value": "15m",
|
|
||||||
"description": "入场周期:15分钟"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "EXCLUDE_MAJOR_COINS",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": true,
|
|
||||||
"display_value": true,
|
|
||||||
"description": "是否排除主流币(BTC、ETH、BNB等),专注于山寨币。山寨币策略建议开启。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "KLINE_INTERVAL",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "string",
|
|
||||||
"value": "1h",
|
|
||||||
"display_value": "1h",
|
|
||||||
"description": "K线周期:1小时"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "LIMIT_ORDER_OFFSET_PCT",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.1,
|
|
||||||
"display_value": 0.1,
|
|
||||||
"description": "预设方案配置项:LIMIT_ORDER_OFFSET_PCT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_DAILY_ENTRIES",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 10,
|
|
||||||
"display_value": 10,
|
|
||||||
"description": "预设方案配置项:MAX_DAILY_ENTRIES"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_OPEN_POSITIONS",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 5,
|
|
||||||
"display_value": 5,
|
|
||||||
"description": "预设方案配置项:MAX_OPEN_POSITIONS"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_SCAN_SYMBOLS",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 500,
|
|
||||||
"display_value": 500,
|
|
||||||
"description": "扫描的最大交易对数量(0表示扫描所有,建议100-500)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MAX_TREND_MOVE_BEFORE_ENTRY",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.05,
|
|
||||||
"display_value": 0.05,
|
|
||||||
"description": "预设方案配置项:MAX_TREND_MOVE_BEFORE_ENTRY"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_CHANGE_PERCENT",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.02,
|
|
||||||
"display_value": 2,
|
|
||||||
"description": "最小涨跌幅阈值:2%"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_HOLD_TIME_SEC",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 1800,
|
|
||||||
"display_value": 1800,
|
|
||||||
"description": "预设方案配置项:MIN_HOLD_TIME_SEC"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_SIGNAL_STRENGTH",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 8,
|
|
||||||
"display_value": 8,
|
|
||||||
"description": "预设方案配置项:MIN_SIGNAL_STRENGTH"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_VOLATILITY",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 0.02,
|
|
||||||
"display_value": 0.02,
|
|
||||||
"description": "最小波动率:2%"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_VOLUME_24H",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 10000000,
|
|
||||||
"display_value": 10000000,
|
|
||||||
"description": "最小24小时成交量:1000万USDT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "MIN_VOLUME_24H_STRICT",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 50000000,
|
|
||||||
"display_value": 50000000,
|
|
||||||
"description": "严格成交量过滤,24H Volume低于此值(USD)直接剔除"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "POSITION_SYNC_INTERVAL",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 60,
|
|
||||||
"display_value": 60,
|
|
||||||
"description": "持仓状态同步间隔(秒),默认1分钟,用于同步币安实际持仓与数据库状态"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "PRIMARY_INTERVAL",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "string",
|
|
||||||
"value": "1h",
|
|
||||||
"display_value": "1h",
|
|
||||||
"description": "主周期:1小时"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "SCAN_EXTRA_SYMBOLS_FOR_SUPPLEMENT",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 15,
|
|
||||||
"display_value": 15,
|
|
||||||
"description": "智能补单:多返回的候选数量。当前 TOP_N 中部分因冷却等被跳过时,仍会尝试这批额外候选,避免无单可下。"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "SCAN_INTERVAL",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 1800,
|
|
||||||
"display_value": 1800,
|
|
||||||
"description": "预设方案配置项:SCAN_INTERVAL"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "TOP_N_SYMBOLS",
|
|
||||||
"category": "scan",
|
|
||||||
"category_label": "市场扫描",
|
|
||||||
"type": "number",
|
|
||||||
"value": 20,
|
|
||||||
"display_value": 20,
|
|
||||||
"description": "预设方案配置项:TOP_N_SYMBOLS"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -416,6 +416,19 @@ const ConfigPanel = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleTriggerScan = async () => {
|
||||||
|
setSystemBusy(true)
|
||||||
|
setMessage('')
|
||||||
|
try {
|
||||||
|
const res = await api.triggerScan()
|
||||||
|
setMessage(res.message || '已触发手动扫描')
|
||||||
|
} catch (e) {
|
||||||
|
setMessage('触发扫描失败: ' + (e?.message || '未知错误'))
|
||||||
|
} finally {
|
||||||
|
setSystemBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleRestartTrading = async () => {
|
const handleRestartTrading = async () => {
|
||||||
setSystemBusy(true)
|
setSystemBusy(true)
|
||||||
setMessage('')
|
setMessage('')
|
||||||
|
|
@ -908,6 +921,9 @@ const ConfigPanel = () => {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="system-actions">
|
<div className="system-actions">
|
||||||
|
<button type="button" className="system-btn primary" onClick={handleTriggerScan} disabled={systemBusy || !accountTradingStatus?.running} title="通知该账号交易进程立即执行一次市场扫描(无需重启)">
|
||||||
|
立即扫描
|
||||||
|
</button>
|
||||||
<button type="button" className="system-btn" onClick={handleAccountTradingEnsure} disabled={systemBusy} title="为该账号生成/刷新 supervisor program 配置(需要 owner/admin)">
|
<button type="button" className="system-btn" onClick={handleAccountTradingEnsure} disabled={systemBusy} title="为该账号生成/刷新 supervisor program 配置(需要 owner/admin)">
|
||||||
生成配置
|
生成配置
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
|
|
@ -223,48 +223,48 @@ const GlobalConfig = () => {
|
||||||
const presets = {
|
const presets = {
|
||||||
altcoin: {
|
altcoin: {
|
||||||
name: '山寨币策略(推荐)',
|
name: '山寨币策略(推荐)',
|
||||||
desc: '【安全推荐】针对山寨币高波动优化:已修复止损BUG。1.5%风险/单,2.0倍ATR紧止损,10%强平保护。避开大市值币种,追求高盈亏比。',
|
desc: '【安全推荐】针对山寨币高波动优化:已修复止损BUG。3%风险/单,30%激活移动止损,10%强平保护。避开大市值币种,追求高盈亏比。',
|
||||||
configs: {
|
configs: {
|
||||||
// 风险与止盈止损
|
// 风险与止盈止损
|
||||||
ATR_STOP_LOSS_MULTIPLIER: 2.0,
|
ATR_STOP_LOSS_MULTIPLIER: 3.0, // 恢复到3.0以适应宽止损
|
||||||
STOP_LOSS_PERCENT: 0.10, // 10% 强平保护
|
STOP_LOSS_PERCENT: 0.10, // 10% 强平保护
|
||||||
MIN_STOP_LOSS_PRICE_PCT: 0.005, // 0.5% 最小价格止损
|
MIN_STOP_LOSS_PRICE_PCT: 0.005, // 0.5% 最小价格止损
|
||||||
MIN_TAKE_PROFIT_PRICE_PCT: 0.006, // 0.6% 最小价格止盈
|
MIN_TAKE_PROFIT_PRICE_PCT: 0.006, // 0.6% 最小价格止盈
|
||||||
RISK_REWARD_RATIO: 2.0,
|
RISK_REWARD_RATIO: 3.0, // 3.0盈亏比
|
||||||
TAKE_PROFIT_1_PERCENT: 0.20, // 20% 第一止盈
|
TAKE_PROFIT_1_PERCENT: 0.30, // 30% 第一止盈
|
||||||
TAKE_PROFIT_PERCENT: 0.30, // 30% 第二止盈
|
TAKE_PROFIT_PERCENT: 0.80, // 80% 第二止盈
|
||||||
MIN_RR_FOR_TP1: 1.2,
|
MIN_RR_FOR_TP1: 1.5, // 1.5倍盈亏比
|
||||||
MIN_HOLD_TIME_SEC: 1800,
|
MIN_HOLD_TIME_SEC: 0, // 取消持仓时间锁
|
||||||
USE_FIXED_RISK_SIZING: true,
|
USE_FIXED_RISK_SIZING: true,
|
||||||
FIXED_RISK_PERCENT: 0.015, // 1.5% 风险
|
FIXED_RISK_PERCENT: 0.03, // 3% 风险(优化:从小资金1%提升到3%)
|
||||||
USE_DYNAMIC_ATR_MULTIPLIER: false,
|
USE_DYNAMIC_ATR_MULTIPLIER: false,
|
||||||
|
|
||||||
USE_TRAILING_STOP: true,
|
USE_TRAILING_STOP: true,
|
||||||
TRAILING_STOP_ACTIVATION: 0.15,
|
TRAILING_STOP_ACTIVATION: 0.30, // 30% 激活移动止损(优化:避免微利过早止损)
|
||||||
TRAILING_STOP_PROTECT: 0.05,
|
TRAILING_STOP_PROTECT: 0.10, // 10% 保护利润
|
||||||
|
|
||||||
MAX_POSITION_PERCENT: 0.15, // 15% 单仓上限
|
MAX_POSITION_PERCENT: 0.20, // 20% 单仓上限
|
||||||
MAX_TOTAL_POSITION_PERCENT: 0.60, // 60% 总仓上限
|
MAX_TOTAL_POSITION_PERCENT: 0.80, // 80% 总仓上限
|
||||||
MAX_DAILY_ENTRIES: 10,
|
MAX_DAILY_ENTRIES: 15,
|
||||||
MAX_OPEN_POSITIONS: 5,
|
MAX_OPEN_POSITIONS: 4,
|
||||||
LEVERAGE: 10,
|
LEVERAGE: 8,
|
||||||
MAX_LEVERAGE: 20,
|
MAX_LEVERAGE: 20,
|
||||||
MIN_LEVERAGE: 8,
|
MIN_LEVERAGE: 8,
|
||||||
MAX_LEVERAGE_SMALL_CAP: 8,
|
MAX_LEVERAGE_SMALL_CAP: 8,
|
||||||
USE_DYNAMIC_LEVERAGE: true,
|
USE_DYNAMIC_LEVERAGE: true,
|
||||||
|
|
||||||
MIN_VOLUME_24H: 10000000,
|
MIN_VOLUME_24H: 30000000,
|
||||||
MIN_VOLATILITY: 0.02,
|
MIN_VOLATILITY: 0.03,
|
||||||
TOP_N_SYMBOLS: 20,
|
TOP_N_SYMBOLS: 30,
|
||||||
MAX_SCAN_SYMBOLS: 500,
|
MAX_SCAN_SYMBOLS: 500,
|
||||||
MIN_SIGNAL_STRENGTH: 8,
|
MIN_SIGNAL_STRENGTH: 8,
|
||||||
EXCLUDE_MAJOR_COINS: true,
|
EXCLUDE_MAJOR_COINS: true,
|
||||||
SCAN_EXTRA_SYMBOLS_FOR_SUPPLEMENT: 15,
|
SCAN_EXTRA_SYMBOLS_FOR_SUPPLEMENT: 20,
|
||||||
|
|
||||||
SCAN_INTERVAL: 1800,
|
SCAN_INTERVAL: 900,
|
||||||
PRIMARY_INTERVAL: '1h',
|
PRIMARY_INTERVAL: '4h',
|
||||||
ENTRY_INTERVAL: '15m',
|
ENTRY_INTERVAL: '1h',
|
||||||
CONFIRM_INTERVAL: '4h',
|
CONFIRM_INTERVAL: '1d',
|
||||||
|
|
||||||
AUTO_TRADE_ONLY_TRENDING: true,
|
AUTO_TRADE_ONLY_TRENDING: true,
|
||||||
AUTO_TRADE_ALLOW_4H_NEUTRAL: false,
|
AUTO_TRADE_ALLOW_4H_NEUTRAL: false,
|
||||||
|
|
@ -280,7 +280,7 @@ const GlobalConfig = () => {
|
||||||
BETA_FILTER_ENABLED: true,
|
BETA_FILTER_ENABLED: true,
|
||||||
BETA_FILTER_THRESHOLD: -0.005,
|
BETA_FILTER_THRESHOLD: -0.005,
|
||||||
ENTRY_SHORT_TREND_FILTER_ENABLED: true,
|
ENTRY_SHORT_TREND_FILTER_ENABLED: true,
|
||||||
MAX_TREND_MOVE_BEFORE_ENTRY: 0.05,
|
MAX_TREND_MOVE_BEFORE_ENTRY: 0.04,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
conservative: {
|
conservative: {
|
||||||
|
|
@ -399,8 +399,8 @@ const GlobalConfig = () => {
|
||||||
MAX_CHANGE_PERCENT_FOR_LONG: { value: 25, type: 'number', category: 'strategy', description: '做多时 24h 涨跌幅超过此值则不开多(避免追大涨)。单位:百分比数值,如 25 表示 25%。' },
|
MAX_CHANGE_PERCENT_FOR_LONG: { value: 25, type: 'number', category: 'strategy', description: '做多时 24h 涨跌幅超过此值则不开多(避免追大涨)。单位:百分比数值,如 25 表示 25%。' },
|
||||||
MIN_RSI_FOR_SHORT: { value: 30, type: 'number', category: 'strategy', description: '做空时 RSI 低于此值则不做空(避免深超卖反弹)。2026-01-31新增。' },
|
MIN_RSI_FOR_SHORT: { value: 30, type: 'number', category: 'strategy', description: '做空时 RSI 低于此值则不做空(避免深超卖反弹)。2026-01-31新增。' },
|
||||||
MAX_CHANGE_PERCENT_FOR_SHORT: { value: 10, type: 'number', category: 'strategy', description: '做空时 24h 涨跌幅超过此值则不做空(24h 仍大涨时不做空)。单位:百分比数值。' },
|
MAX_CHANGE_PERCENT_FOR_SHORT: { value: 10, type: 'number', category: 'strategy', description: '做空时 24h 涨跌幅超过此值则不做空(24h 仍大涨时不做空)。单位:百分比数值。' },
|
||||||
TAKE_PROFIT_1_PERCENT: { value: 0.2, type: 'number', category: 'strategy', description: '分步止盈第一目标(保证金百分比,如 0.2=20%)。2026-02-12 提高以改善盈亏比。' },
|
TAKE_PROFIT_1_PERCENT: { value: 0.3, type: 'number', category: 'strategy', description: '分步止盈第一目标(保证金百分比,如 0.2=20%)。2026-02-12 提高以改善盈亏比。' },
|
||||||
SCAN_EXTRA_SYMBOLS_FOR_SUPPLEMENT: { value: 8, type: 'number', category: 'scan', description: '智能补单:多返回的候选数量,冷却时仍可尝试后续交易对。' },
|
SCAN_EXTRA_SYMBOLS_FOR_SUPPLEMENT: { value: 20, type: 'number', category: 'scan', description: '智能补单:多返回的候选数量,冷却时仍可尝试后续交易对。' },
|
||||||
SYMBOL_LOSS_COOLDOWN_ENABLED: { value: true, type: 'boolean', category: 'strategy', description: '是否启用同一交易对连续亏损后的冷却。' },
|
SYMBOL_LOSS_COOLDOWN_ENABLED: { value: true, type: 'boolean', category: 'strategy', description: '是否启用同一交易对连续亏损后的冷却。' },
|
||||||
SYMBOL_MAX_CONSECUTIVE_LOSSES: { value: 2, type: 'number', category: 'strategy', description: '最大允许连续亏损次数(超过则禁止交易该交易对一段时间)。' },
|
SYMBOL_MAX_CONSECUTIVE_LOSSES: { value: 2, type: 'number', category: 'strategy', description: '最大允许连续亏损次数(超过则禁止交易该交易对一段时间)。' },
|
||||||
SYMBOL_LOSS_COOLDOWN_SEC: { value: 3600, type: 'number', category: 'strategy', description: '连续亏损后的冷却时间(秒),默认1小时。' },
|
SYMBOL_LOSS_COOLDOWN_SEC: { value: 3600, type: 'number', category: 'strategy', description: '连续亏损后的冷却时间(秒),默认1小时。' },
|
||||||
|
|
@ -411,20 +411,20 @@ const GlobalConfig = () => {
|
||||||
BETA_FILTER_THRESHOLD: { value: -0.005, type: 'number', category: 'strategy', description: '大盘共振阈值(比例,如 -0.005 表示 -0.5%)。' },
|
BETA_FILTER_THRESHOLD: { value: -0.005, type: 'number', category: 'strategy', description: '大盘共振阈值(比例,如 -0.005 表示 -0.5%)。' },
|
||||||
RSI_EXTREME_REVERSE_ENABLED: { value: false, type: 'boolean', category: 'strategy', description: '开启后:原信号做多但 RSI 超买(≥做多上限)时改为做空;原信号做空但 RSI 超卖(≤做空下限)时改为做多。属均值回归思路,可填补超买超卖时不下单的空置;默认关闭。' },
|
RSI_EXTREME_REVERSE_ENABLED: { value: false, type: 'boolean', category: 'strategy', description: '开启后:原信号做多但 RSI 超买(≥做多上限)时改为做空;原信号做空但 RSI 超卖(≤做空下限)时改为做多。属均值回归思路,可填补超买超卖时不下单的空置;默认关闭。' },
|
||||||
RSI_EXTREME_REVERSE_ONLY_NEUTRAL_4H: { value: true, type: 'boolean', category: 'strategy', description: '建议开启:仅在 4H 趋势为中性时允许 RSI 反向单,避免在强趋势里逆势抄底/摸顶,降低风险。关闭则反向可与 4H 同向(仍受“禁止逆4H趋势”约束)。' },
|
RSI_EXTREME_REVERSE_ONLY_NEUTRAL_4H: { value: true, type: 'boolean', category: 'strategy', description: '建议开启:仅在 4H 趋势为中性时允许 RSI 反向单,避免在强趋势里逆势抄底/摸顶,降低风险。关闭则反向可与 4H 同向(仍受“禁止逆4H趋势”约束)。' },
|
||||||
TAKE_PROFIT_PERCENT: { value: 0.25, type: 'number', category: 'risk', description: '止盈百分比(保证金比例,如 25.0=25%)。' },
|
TAKE_PROFIT_PERCENT: { value: 0.80, type: 'number', category: 'risk', description: '止盈百分比(保证金比例,如 25.0=25%)。' },
|
||||||
STOP_LOSS_PERCENT: { value: 0.08, type: 'number', category: 'risk', description: '止损百分比(保证金比例,如 8.0=8%)。' },
|
STOP_LOSS_PERCENT: { value: 0.10, type: 'number', category: 'risk', description: '止损百分比(保证金比例,如 8.0=8%)。' },
|
||||||
TRAILING_STOP_ACTIVATION: { value: 0.20, type: 'number', category: 'risk', description: '移动止损激活阈值(盈利达到此比例后激活,如 20.0=20%)。' },
|
TRAILING_STOP_ACTIVATION: { value: 0.30, type: 'number', category: 'risk', description: '移动止损激活阈值(盈利达到此比例后激活,如 20.0=20%)。' },
|
||||||
TRAILING_STOP_PROTECT: { value: 0.10, type: 'number', category: 'risk', description: '移动止损保护阈值(回撤至此比例时触发止损,如 10.0=10%)。' },
|
TRAILING_STOP_PROTECT: { value: 0.10, type: 'number', category: 'risk', description: '移动止损保护阈值(回撤至此比例时触发止损,如 10.0=10%)。' },
|
||||||
LEVERAGE: { value: 10, type: 'number', category: 'risk', description: '基础杠杆倍数。' },
|
LEVERAGE: { value: 8, type: 'number', category: 'risk', description: '基础杠杆倍数。' },
|
||||||
MAX_POSITION_PERCENT: { value: 0.12, type: 'number', category: 'risk', description: '单笔最大保证金占可用资金比例(如 0.12=12%),加大可提高单笔盈利。' },
|
MAX_POSITION_PERCENT: { value: 0.20, type: 'number', category: 'risk', description: '单笔最大保证金占可用资金比例(如 0.12=12%),加大可提高单笔盈利。' },
|
||||||
MAX_LEVERAGE: { value: 20, type: 'number', category: 'risk', description: '动态杠杆上限(如 20 表示最高 20 倍),配合单笔仓位提高收益。' },
|
MAX_LEVERAGE: { value: 20, type: 'number', category: 'risk', description: '动态杠杆上限(如 20 表示最高 20 倍),配合单笔仓位提高收益。' },
|
||||||
MIN_LEVERAGE: { value: 8, type: 'number', category: 'risk', description: '动态杠杆下限(如 8 表示不低于 8 倍)。之前盈利阶段多为 8x,避免被压到 2–4x 导致单笔盈利过少。' },
|
MIN_LEVERAGE: { value: 8, type: 'number', category: 'risk', description: '动态杠杆下限(如 8 表示不低于 8 倍)。之前盈利阶段多为 8x,避免被压到 2–4x 导致单笔盈利过少。' },
|
||||||
MAX_LEVERAGE_SMALL_CAP: { value: 8, type: 'number', category: 'risk', description: '高波动/小众币最大允许杠杆(与之前盈利阶段一致)。' },
|
MAX_LEVERAGE_SMALL_CAP: { value: 8, type: 'number', category: 'risk', description: '高波动/小众币最大允许杠杆(与之前盈利阶段一致)。' },
|
||||||
RISK_REWARD_RATIO: { value: 3, type: 'number', category: 'risk', description: '盈亏比目标(用于计算动态止盈止损,建议 3:1)。' },
|
RISK_REWARD_RATIO: { value: 3, type: 'number', category: 'risk', description: '盈亏比目标(用于计算动态止盈止损,建议 3:1)。' },
|
||||||
ATR_TAKE_PROFIT_MULTIPLIER: { value: 1.5, type: 'number', category: 'risk', description: 'ATR 止盈倍数。' },
|
ATR_TAKE_PROFIT_MULTIPLIER: { value: 6.0, type: 'number', category: 'risk', description: 'ATR 止盈倍数。' },
|
||||||
ATR_STOP_LOSS_MULTIPLIER: { value: 3, type: 'number', category: 'risk', description: 'ATR 止损倍数(2026-02-12:3 减少噪音止损)。' },
|
ATR_STOP_LOSS_MULTIPLIER: { value: 3.0, type: 'number', category: 'risk', description: 'ATR 止损倍数(2026-02-12:3 减少噪音止损)。' },
|
||||||
USE_FIXED_RISK_SIZING: { value: false, type: 'boolean', category: 'risk', description: '是否使用固定风险仓位计算(基于止损距离和账户余额)。' },
|
USE_FIXED_RISK_SIZING: { value: true, type: 'boolean', category: 'risk', description: '是否使用固定风险仓位计算(基于止损距离和账户余额)。' },
|
||||||
FIXED_RISK_PERCENT: { value: 0.01, type: 'number', category: 'risk', description: '每笔交易固定风险百分比(如 0.01=1%)。' },
|
FIXED_RISK_PERCENT: { value: 0.03, type: 'number', category: 'risk', description: '每笔交易固定风险百分比(如 0.01=1%)。' },
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadConfigs = async () => {
|
const loadConfigs = async () => {
|
||||||
|
|
@ -578,6 +578,19 @@ const GlobalConfig = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleTriggerScan = async () => {
|
||||||
|
setSystemBusy(true)
|
||||||
|
setMessage('')
|
||||||
|
try {
|
||||||
|
const res = await api.triggerScan()
|
||||||
|
setMessage(res.message || '已触发手动扫描')
|
||||||
|
} catch (e) {
|
||||||
|
setMessage('触发扫描失败: ' + (e?.message || '未知错误'))
|
||||||
|
} finally {
|
||||||
|
setSystemBusy(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const applyPreset = async (presetKey) => {
|
const applyPreset = async (presetKey) => {
|
||||||
const preset = presets[presetKey]
|
const preset = presets[presetKey]
|
||||||
|
|
@ -1048,6 +1061,15 @@ const GlobalConfig = () => {
|
||||||
<div className="system-control-group" style={{ marginTop: '15px' }}>
|
<div className="system-control-group" style={{ marginTop: '15px' }}>
|
||||||
<h4 className="control-group-title" style={{ margin: '10px 0 8px', fontSize: '14px', color: '#666' }}>交易服务管理</h4>
|
<h4 className="control-group-title" style={{ margin: '10px 0 8px', fontSize: '14px', color: '#666' }}>交易服务管理</h4>
|
||||||
<div className="system-actions">
|
<div className="system-actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="system-btn primary"
|
||||||
|
onClick={handleTriggerScan}
|
||||||
|
disabled={systemBusy}
|
||||||
|
title="通知所有交易进程立即执行一次市场扫描(无需重启)"
|
||||||
|
>
|
||||||
|
立即触发扫描
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className="system-btn primary"
|
className="system-btn primary"
|
||||||
|
|
|
||||||
|
|
@ -217,6 +217,17 @@ export const api = {
|
||||||
},
|
},
|
||||||
|
|
||||||
// 交易进程(按账号;需要 owner 或 admin)
|
// 交易进程(按账号;需要 owner 或 admin)
|
||||||
|
triggerScan: async () => {
|
||||||
|
const response = await fetch(buildUrl('/api/system/trading/trigger-scan'), {
|
||||||
|
method: 'POST',
|
||||||
|
headers: withAuthHeaders({ 'Content-Type': 'application/json' }),
|
||||||
|
})
|
||||||
|
if (!response.ok) {
|
||||||
|
const error = await response.json().catch(() => ({ detail: '触发扫描失败' }))
|
||||||
|
throw new Error(error.detail || '触发扫描失败')
|
||||||
|
}
|
||||||
|
return response.json()
|
||||||
|
},
|
||||||
getAccountTradingStatus: async (accountId) => {
|
getAccountTradingStatus: async (accountId) => {
|
||||||
const response = await fetch(buildUrl(`/api/accounts/${accountId}/trading/status`), { headers: withAccountHeaders() })
|
const response = await fetch(buildUrl(`/api/accounts/${accountId}/trading/status`), { headers: withAccountHeaders() })
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,7 @@ DEFAULT_TRADING_CONFIG = {
|
||||||
|
|
||||||
# ===== 仓位管理优化(山寨币专属)=====
|
# ===== 仓位管理优化(山寨币专属)=====
|
||||||
'USE_FIXED_RISK_SIZING': True, # 固定每笔风险,避免亏损扩大
|
'USE_FIXED_RISK_SIZING': True, # 固定每笔风险,避免亏损扩大
|
||||||
'FIXED_RISK_PERCENT': 0.01, # 每笔最多亏总资金1%(山寨币风险高)
|
'FIXED_RISK_PERCENT': 0.03, # 每笔最多亏总资金3%(针对小资金账户优化,300U账户单笔风险约9U)
|
||||||
'MAX_LEVERAGE_SMALL_CAP': 8, # 高波动/小众币最大杠杆(与之前盈利阶段一致)
|
'MAX_LEVERAGE_SMALL_CAP': 8, # 高波动/小众币最大杠杆(与之前盈利阶段一致)
|
||||||
'MIN_LEVERAGE': 8, # 动态杠杆下限,避免被压到 2–4x 导致单笔盈利过少
|
'MIN_LEVERAGE': 8, # 动态杠杆下限,避免被压到 2–4x 导致单笔盈利过少
|
||||||
'ATR_LEVERAGE_REDUCTION_THRESHOLD': 0.05, # ATR超过5%时降低杠杆
|
'ATR_LEVERAGE_REDUCTION_THRESHOLD': 0.05, # ATR超过5%时降低杠杆
|
||||||
|
|
@ -256,8 +256,8 @@ DEFAULT_TRADING_CONFIG = {
|
||||||
'MAX_LEVERAGE': 20, # 最大杠杆
|
'MAX_LEVERAGE': 20, # 最大杠杆
|
||||||
# 移动止损:必须开启!山寨币利润要保护
|
# 移动止损:必须开启!山寨币利润要保护
|
||||||
'USE_TRAILING_STOP': True,
|
'USE_TRAILING_STOP': True,
|
||||||
'TRAILING_STOP_ACTIVATION': 0.10, # 盈利10%后激活(更早锁定利润)
|
'TRAILING_STOP_ACTIVATION': 0.30, # 盈利30%后激活(延迟激活,避免微利震荡出局,约合3%价格波动)
|
||||||
'TRAILING_STOP_PROTECT': 0.02, # 保护2%利润(紧跟趋势)
|
'TRAILING_STOP_PROTECT': 0.10, # 保护10%利润(确保至少有1%价格波动的利润)
|
||||||
|
|
||||||
# 最小持仓时间锁:立即取消!山寨币30分钟可能暴涨暴跌50%
|
# 最小持仓时间锁:立即取消!山寨币30分钟可能暴涨暴跌50%
|
||||||
'MIN_HOLD_TIME_SEC': 0, # 取消持仓时间锁
|
'MIN_HOLD_TIME_SEC': 0, # 取消持仓时间锁
|
||||||
|
|
|
||||||
|
|
@ -671,8 +671,8 @@ class RiskManager:
|
||||||
margin_value = notional_value / actual_leverage
|
margin_value = notional_value / actual_leverage
|
||||||
|
|
||||||
# 检查最小保证金要求(margin 语义:MIN_MARGIN_USDT 本身就是保证金下限)
|
# 检查最小保证金要求(margin 语义:MIN_MARGIN_USDT 本身就是保证金下限)
|
||||||
# 2026-02-13 优化:默认最小保证金提高到 2.0 USDT,避免无效小单
|
# 2026-02-13 优化:默认最小保证金提高到 10.0 USDT,避免无效小单
|
||||||
min_margin_usdt = config.TRADING_CONFIG.get('MIN_MARGIN_USDT', 2.0)
|
min_margin_usdt = config.TRADING_CONFIG.get('MIN_MARGIN_USDT', 10.0)
|
||||||
logger.info(f" 当前保证金: {margin_value:.4f} USDT (杠杆: {actual_leverage}x)")
|
logger.info(f" 当前保证金: {margin_value:.4f} USDT (杠杆: {actual_leverage}x)")
|
||||||
|
|
||||||
if margin_value < min_margin_usdt:
|
if margin_value < min_margin_usdt:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
from typing import List, Dict, Optional
|
from typing import List, Dict, Optional
|
||||||
try:
|
try:
|
||||||
from .binance_client import BinanceClient
|
from .binance_client import BinanceClient
|
||||||
|
|
@ -55,6 +56,7 @@ class TradingStrategy:
|
||||||
执行交易策略
|
执行交易策略
|
||||||
"""
|
"""
|
||||||
self.running = True
|
self.running = True
|
||||||
|
self.last_scan_trigger_ts = int(time.time()) # 初始化触发时间戳
|
||||||
logger.info("交易策略开始执行...")
|
logger.info("交易策略开始执行...")
|
||||||
|
|
||||||
# 启动所有现有持仓的WebSocket实时监控
|
# 启动所有现有持仓的WebSocket实时监控
|
||||||
|
|
@ -86,7 +88,7 @@ class TradingStrategy:
|
||||||
|
|
||||||
if not top_symbols:
|
if not top_symbols:
|
||||||
logger.warning("未找到符合条件的交易对,等待下次扫描...")
|
logger.warning("未找到符合条件的交易对,等待下次扫描...")
|
||||||
await asyncio.sleep(config.TRADING_CONFIG['SCAN_INTERVAL'])
|
await self._wait_for_next_scan(config.TRADING_CONFIG.get('SCAN_INTERVAL', 3600))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 2. 对每个交易对执行交易逻辑(使用技术指标)
|
# 2. 对每个交易对执行交易逻辑(使用技术指标)
|
||||||
|
|
@ -290,10 +292,9 @@ class TradingStrategy:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"重新加载配置失败: {e}")
|
logger.debug(f"重新加载配置失败: {e}")
|
||||||
|
|
||||||
# 等待下次扫描
|
# 等待下次扫描(支持手动触发)
|
||||||
scan_interval = config.TRADING_CONFIG.get('SCAN_INTERVAL', 3600)
|
scan_interval = config.TRADING_CONFIG.get('SCAN_INTERVAL', 3600)
|
||||||
logger.info(f"等待 {scan_interval} 秒后进行下次扫描...")
|
await self._wait_for_next_scan(scan_interval)
|
||||||
await asyncio.sleep(scan_interval)
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"策略执行出错: {e}", exc_info=True)
|
logger.error(f"策略执行出错: {e}", exc_info=True)
|
||||||
|
|
@ -314,6 +315,31 @@ class TradingStrategy:
|
||||||
logger.warning(f"停止持仓监控时出错: {e}")
|
logger.warning(f"停止持仓监控时出错: {e}")
|
||||||
logger.info("交易策略已停止")
|
logger.info("交易策略已停止")
|
||||||
|
|
||||||
|
async def _wait_for_next_scan(self, scan_interval: int):
|
||||||
|
"""
|
||||||
|
等待下次扫描,同时监听手动触发信号
|
||||||
|
"""
|
||||||
|
logger.info(f"等待 {scan_interval} 秒后进行下次扫描...")
|
||||||
|
|
||||||
|
# 分片等待,每秒检查一次触发信号
|
||||||
|
waited = 0
|
||||||
|
check_interval = 1 # 检查间隔(秒)
|
||||||
|
|
||||||
|
while waited < scan_interval and self.running:
|
||||||
|
# 检查是否有手动触发信号
|
||||||
|
try:
|
||||||
|
if self.client and self.client.redis_cache:
|
||||||
|
trigger_ts = await self.client.redis_cache.get_int("ats:trigger-scan", 0)
|
||||||
|
if trigger_ts > self.last_scan_trigger_ts:
|
||||||
|
logger.info(f"检测到手动扫描触发信号 (ts={trigger_ts}),立即执行扫描")
|
||||||
|
self.last_scan_trigger_ts = trigger_ts
|
||||||
|
break
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
await asyncio.sleep(check_interval)
|
||||||
|
waited += check_interval
|
||||||
|
|
||||||
async def _check_volume_confirmation(self, symbol_info: Dict) -> bool:
|
async def _check_volume_confirmation(self, symbol_info: Dict) -> bool:
|
||||||
"""
|
"""
|
||||||
成交量确认 - 确保有足够的成交量支撑
|
成交量确认 - 确保有足够的成交量支撑
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,18 @@ try:
|
||||||
|
|
||||||
configs_to_update = [
|
configs_to_update = [
|
||||||
# Key, Value, Type, Category, Description
|
# Key, Value, Type, Category, Description
|
||||||
('TAKE_PROFIT_PERCENT', 0.60, 'number', 'risk', '第二目标/单目标止盈60%(保证金百分比)'),
|
('TAKE_PROFIT_PERCENT', 0.80, 'number', 'risk', '第二目标/单目标止盈80%(保证金百分比)'),
|
||||||
('TAKE_PROFIT_1_PERCENT', 0.30, 'number', 'risk', '第一目标止盈30%(保证金百分比)'),
|
('TAKE_PROFIT_1_PERCENT', 0.30, 'number', 'risk', '第一目标止盈30%(保证金百分比)'),
|
||||||
('STOP_LOSS_PERCENT', 0.10, 'number', 'risk', '止损10%(保证金百分比)'),
|
('STOP_LOSS_PERCENT', 0.10, 'number', 'risk', '止损10%(保证金百分比)'),
|
||||||
('TRAILING_STOP_ACTIVATION', 0.30, 'number', 'risk', '移动止损激活阈值(保证金百分比)'),
|
('TRAILING_STOP_ACTIVATION', 0.30, 'number', 'risk', '移动止损激活阈值(保证金百分比)'),
|
||||||
('TRAILING_STOP_PROTECT', 0.05, 'number', 'risk', '移动止损保护阈值(保证金百分比)'),
|
('TRAILING_STOP_PROTECT', 0.10, 'number', 'risk', '移动止损保护阈值(保证金百分比)'),
|
||||||
('LEVERAGE', 4, 'number', 'risk', '基础杠杆倍数'),
|
('LEVERAGE', 8, 'number', 'risk', '基础杠杆倍数'),
|
||||||
('RISK_REWARD_RATIO', 3.0, 'number', 'risk', '盈亏比目标'),
|
('RISK_REWARD_RATIO', 3.0, 'number', 'risk', '盈亏比目标'),
|
||||||
('ATR_TAKE_PROFIT_MULTIPLIER', 4.5, 'number', 'risk', 'ATR止盈倍数'),
|
('ATR_TAKE_PROFIT_MULTIPLIER', 6.0, 'number', 'risk', 'ATR止盈倍数'),
|
||||||
('ATR_STOP_LOSS_MULTIPLIER', 1.5, 'number', 'risk', 'ATR止损倍数'),
|
('ATR_STOP_LOSS_MULTIPLIER', 3.0, 'number', 'risk', 'ATR止损倍数'),
|
||||||
('USE_FIXED_RISK_SIZING', True, 'bool', 'risk', '是否使用固定风险仓位计算'),
|
('USE_FIXED_RISK_SIZING', True, 'bool', 'risk', '是否使用固定风险仓位计算'),
|
||||||
('FIXED_RISK_PERCENT', 0.01, 'number', 'risk', '每笔交易固定风险百分比'),
|
('FIXED_RISK_PERCENT', 0.03, 'number', 'risk', '每笔交易固定风险百分比'),
|
||||||
('MAX_LEVERAGE_SMALL_CAP', 4, 'number', 'risk', '小众币最大杠杆')
|
('MAX_LEVERAGE_SMALL_CAP', 8, 'number', 'risk', '小众币最大杠杆')
|
||||||
]
|
]
|
||||||
|
|
||||||
print("Updating Global Strategy Config...")
|
print("Updating Global Strategy Config...")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user