This commit is contained in:
薇薇安 2026-01-21 13:09:10 +08:00
parent 11e6361235
commit c28400e51e

View File

@ -47,7 +47,7 @@ const ConfigPanel = ({ currentUser }) => {
const [snapshotText, setSnapshotText] = useState('')
const [snapshotIncludeSecrets, setSnapshotIncludeSecrets] = useState(false)
const [snapshotBusy, setSnapshotBusy] = useState(false)
//
// 使8.08%0.08
const presets = {
@ -351,12 +351,16 @@ const ConfigPanel = ({ currentUser }) => {
useEffect(() => {
loadConfigs()
checkFeasibility()
loadSystemStatus()
if (isAdmin) {
loadSystemStatus()
}
loadBackendStatus()
loadAccountTradingStatus()
const timer = setInterval(() => {
loadSystemStatus()
if (isAdmin) {
loadSystemStatus()
}
loadBackendStatus()
loadAccountTradingStatus()
}, 3000)
@ -401,7 +405,7 @@ const ConfigPanel = ({ currentUser }) => {
}, 1000)
return () => clearInterval(timer)
}, [accountId])
const checkFeasibility = async () => {
setCheckingFeasibility(true)
try {
@ -525,21 +529,21 @@ const ConfigPanel = ({ currentUser }) => {
preset_detected: detectCurrentPreset(),
system_status: systemStatus
? {
running: !!systemStatus.running,
pid: systemStatus.pid || null,
program: systemStatus.program || null,
state: systemStatus.state || null,
}
running: !!systemStatus.running,
pid: systemStatus.pid || null,
program: systemStatus.program || null,
state: systemStatus.state || null,
}
: null,
feasibility_check_summary: feasibilityCheck
? {
feasible: !!feasibilityCheck.feasible,
account_balance: feasibilityCheck.account_balance ?? null,
base_leverage: feasibilityCheck.base_leverage ?? feasibilityCheck.leverage ?? null,
max_leverage: feasibilityCheck.max_leverage ?? null,
use_dynamic_leverage: feasibilityCheck.use_dynamic_leverage ?? null,
min_margin_usdt: feasibilityCheck.current_config?.min_margin_usdt ?? null,
}
feasible: !!feasibilityCheck.feasible,
account_balance: feasibilityCheck.account_balance ?? null,
base_leverage: feasibilityCheck.base_leverage ?? feasibilityCheck.leverage ?? null,
max_leverage: feasibilityCheck.max_leverage ?? null,
use_dynamic_leverage: feasibilityCheck.use_dynamic_leverage ?? null,
min_margin_usdt: feasibilityCheck.current_config?.min_margin_usdt ?? null,
}
: null,
configs: entries,
}
@ -593,7 +597,7 @@ const ConfigPanel = ({ currentUser }) => {
//
const detectCurrentPreset = () => {
if (!configs || Object.keys(configs).length === 0) return null
for (const [presetKey, preset] of Object.entries(presets)) {
let match = true
for (const [key, expectedValue] of Object.entries(preset.configs)) {
@ -602,7 +606,7 @@ const ConfigPanel = ({ currentUser }) => {
match = false
break
}
//
let currentValue = currentConfig.value
if (key.includes('PERCENT') || key.includes('PCT')) {
@ -613,7 +617,7 @@ const ConfigPanel = ({ currentUser }) => {
currentValue = currentValue * 100
}
}
//
if (typeof expectedValue === 'number' && typeof currentValue === 'number') {
if (Math.abs(currentValue - expectedValue) > 0.01) {
@ -625,19 +629,19 @@ const ConfigPanel = ({ currentUser }) => {
break
}
}
if (match) {
return presetKey
}
}
return null
}
const applyPreset = async (presetKey) => {
const preset = presets[presetKey]
if (!preset) return
setSaving(true)
setMessage('')
try {
@ -677,7 +681,7 @@ const ConfigPanel = ({ currentUser }) => {
type = 'number'
category = 'scan'
}
const detail = typeof getConfigDetail === 'function' ? getConfigDetail(key) : ''
const desc =
detail && typeof detail === 'string' && !detail.includes('暂无详细说明')
@ -706,7 +710,7 @@ const ConfigPanel = ({ currentUser }) => {
description: config.description
}
}).filter(Boolean)
const response = await api.updateConfigsBatch(configItems)
setMessage(response.message || `已应用${preset.name}`)
if (response.note) {
@ -795,345 +799,345 @@ const ConfigPanel = ({ currentUser }) => {
{/* 系统控制:清缓存 / 启停 / 重启supervisor */}
{isAdmin ? (
<div className="system-section">
<div className="system-header">
<h3>系统控制</h3>
<div className="system-status">
<span className={`system-status-badge ${systemStatus?.running ? 'running' : 'stopped'}`}>
{systemStatus?.running ? '运行中' : '未运行'}
<div className="system-section">
<div className="system-header">
<h3>系统控制</h3>
<div className="system-status">
<span className={`system-status-badge ${systemStatus?.running ? 'running' : 'stopped'}`}>
{systemStatus?.running ? '运行中' : '未运行'}
</span>
{systemStatus?.pid ? <span className="system-status-meta">PID: {systemStatus.pid}</span> : null}
{systemStatus?.program ? <span className="system-status-meta">程序: {systemStatus.program}</span> : null}
{systemStatus?.meta?.requested_at ? <span className="system-status-meta">上次重启: {systemStatus.meta.requested_at}</span> : null}
</div>
</div>
<div className="system-actions">
<button
type="button"
className="system-btn"
onClick={handleClearCache}
disabled={systemBusy}
title="清理Redis配置缓存并从数据库回灌。切换API Key后建议先点这里再重启交易系统。"
>
清除缓存
</button>
<button
type="button"
className="system-btn"
onClick={handleStopTrading}
disabled={systemBusy || systemStatus?.running === false}
title="通过 supervisorctl 停止交易系统"
>
停止
</button>
<button
type="button"
className="system-btn"
onClick={handleStartTrading}
disabled={systemBusy || systemStatus?.running === true}
title="通过 supervisorctl 启动交易系统"
>
启动
</button>
<button
type="button"
className="system-btn primary"
onClick={handleRestartTrading}
disabled={systemBusy}
title="通过 supervisorctl 重启交易系统建议切换API Key后使用"
>
重启交易系统
</button>
<button
type="button"
className="system-btn primary"
onClick={handleRestartBackend}
disabled={systemBusy}
title="通过 backend/restart.sh 重启后端uvicorn。重启期间接口会短暂不可用。"
>
重启后端服务
</button>
</div>
<div className="system-status" style={{ marginTop: '10px' }}>
<span className={`system-status-badge ${backendStatus?.running ? 'running' : 'stopped'}`}>
后端 {backendStatus?.running ? '运行中' : '未知'}
</span>
{systemStatus?.pid ? <span className="system-status-meta">PID: {systemStatus.pid}</span> : null}
{systemStatus?.program ? <span className="system-status-meta">程序: {systemStatus.program}</span> : null}
{systemStatus?.meta?.requested_at ? <span className="system-status-meta">上次重启: {systemStatus.meta.requested_at}</span> : null}
{backendStatus?.pid ? <span className="system-status-meta">PID: {backendStatus.pid}</span> : null}
{backendStatus?.meta?.requested_at ? <span className="system-status-meta">上次重启: {backendStatus.meta.requested_at}</span> : null}
</div>
<div className="system-hint">
建议流程先更新配置里的 Key 点击清除缓存 点击重启交易系统确保不再使用旧账号下单
</div>
</div>
<div className="system-actions">
<button
type="button"
className="system-btn"
onClick={handleClearCache}
disabled={systemBusy}
title="清理Redis配置缓存并从数据库回灌。切换API Key后建议先点这里再重启交易系统。"
>
清除缓存
</button>
<button
type="button"
className="system-btn"
onClick={handleStopTrading}
disabled={systemBusy || systemStatus?.running === false}
title="通过 supervisorctl 停止交易系统"
>
停止
</button>
<button
type="button"
className="system-btn"
onClick={handleStartTrading}
disabled={systemBusy || systemStatus?.running === true}
title="通过 supervisorctl 启动交易系统"
>
启动
</button>
<button
type="button"
className="system-btn primary"
onClick={handleRestartTrading}
disabled={systemBusy}
title="通过 supervisorctl 重启交易系统建议切换API Key后使用"
>
重启交易系统
</button>
<button
type="button"
className="system-btn primary"
onClick={handleRestartBackend}
disabled={systemBusy}
title="通过 backend/restart.sh 重启后端uvicorn。重启期间接口会短暂不可用。"
>
重启后端服务
</button>
</div>
<div className="system-status" style={{ marginTop: '10px' }}>
<span className={`system-status-badge ${backendStatus?.running ? 'running' : 'stopped'}`}>
后端 {backendStatus?.running ? '运行中' : '未知'}
</span>
{backendStatus?.pid ? <span className="system-status-meta">PID: {backendStatus.pid}</span> : null}
{backendStatus?.meta?.requested_at ? <span className="system-status-meta">上次重启: {backendStatus.meta.requested_at}</span> : null}
</div>
<div className="system-hint">
建议流程先更新配置里的 Key 点击清除缓存 点击重启交易系统确保不再使用旧账号下单
</div>
</div>
) : null}
{/* 账号管理(超管) */}
{isAdmin ? (
<div className="accounts-admin-section">
<div className="accounts-admin-header">
<h3>账号管理多账号</h3>
<div className="accounts-admin-actions">
<button
type="button"
className="system-btn"
onClick={async () => {
setAccountsBusy(true)
try {
await loadAccountsAdmin()
setShowAccountsAdmin((v) => !v)
} finally {
setAccountsBusy(false)
}
}}
disabled={accountsBusy}
title="创建/禁用账号;为每个账号配置独立 API KEY/SECRET交易/配置/统计会按账号隔离"
>
{showAccountsAdmin ? '收起' : '管理账号'}
</button>
<button
type="button"
className="system-btn"
onClick={async () => {
setAccountsBusy(true)
try {
await loadAccountsAdmin()
notifyAccountsUpdated()
setMessage('账号列表已刷新')
} finally {
setAccountsBusy(false)
}
}}
disabled={accountsBusy}
>
刷新
</button>
<div className="accounts-admin-section">
<div className="accounts-admin-header">
<h3>账号管理多账号</h3>
<div className="accounts-admin-actions">
<button
type="button"
className="system-btn"
onClick={async () => {
setAccountsBusy(true)
try {
await loadAccountsAdmin()
setShowAccountsAdmin((v) => !v)
} finally {
setAccountsBusy(false)
}
}}
disabled={accountsBusy}
title="创建/禁用账号;为每个账号配置独立 API KEY/SECRET交易/配置/统计会按账号隔离"
>
{showAccountsAdmin ? '收起' : '管理账号'}
</button>
<button
type="button"
className="system-btn"
onClick={async () => {
setAccountsBusy(true)
try {
await loadAccountsAdmin()
notifyAccountsUpdated()
setMessage('账号列表已刷新')
} finally {
setAccountsBusy(false)
}
}}
disabled={accountsBusy}
>
刷新
</button>
</div>
</div>
</div>
{showAccountsAdmin ? (
<div className="accounts-admin-body">
<div className="accounts-admin-card">
<div className="accounts-admin-card-title">新增账号</div>
<div className="accounts-form">
<label>
名称
<input
type="text"
value={newAccount.name}
onChange={(e) => setNewAccount({ ...newAccount, name: e.target.value })}
placeholder="例如user_a"
/>
</label>
<label>
API KEY
<input
type="password"
value={newAccount.api_key}
onChange={(e) => setNewAccount({ ...newAccount, api_key: e.target.value })}
placeholder="可先留空,后续再填"
/>
</label>
<label>
API SECRET
<input
type="password"
value={newAccount.api_secret}
onChange={(e) => setNewAccount({ ...newAccount, api_secret: e.target.value })}
placeholder="可先留空,后续再填"
/>
</label>
<label className="accounts-inline">
<span>测试网</span>
<input
type="checkbox"
checked={!!newAccount.use_testnet}
onChange={(e) => setNewAccount({ ...newAccount, use_testnet: e.target.checked })}
/>
</label>
<label>
状态
<select
value={newAccount.status}
onChange={(e) => setNewAccount({ ...newAccount, status: e.target.value })}
>
<option value="active">启用</option>
<option value="disabled">禁用</option>
</select>
</label>
<div className="accounts-form-actions">
<button
type="button"
className="system-btn primary"
disabled={accountsBusy || !newAccount.name.trim()}
onClick={async () => {
setAccountsBusy(true)
setMessage('')
try {
await api.createAccount(newAccount)
setMessage('账号已创建')
setNewAccount({ name: '', api_key: '', api_secret: '', use_testnet: false, status: 'active' })
await loadAccountsAdmin()
notifyAccountsUpdated()
} catch (e) {
setMessage('创建账号失败: ' + (e?.message || '未知错误'))
} finally {
setAccountsBusy(false)
}
}}
>
创建账号
</button>
</div>
</div>
</div>
<div className="accounts-admin-card">
<div className="accounts-admin-card-title">账号列表</div>
<div className="accounts-table">
{(accountsAdmin || []).length ? (
<table>
<thead>
<tr>
<th>ID</th>
<th>名称</th>
<th>状态</th>
<th>测试网</th>
<th>API KEY</th>
<th>SECRET</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{accountsAdmin.map((a) => (
<tr key={a.id}>
<td>#{a.id}</td>
<td>{a.name || '-'}</td>
<td>
<span className={`acct-badge ${a.status === 'active' ? 'ok' : 'off'}`}>
{a.status === 'active' ? '启用' : '禁用'}
</span>
</td>
<td>{a.use_testnet ? '是' : '否'}</td>
<td>{a.api_key_masked || (a.has_api_key ? '已配置' : '未配置')}</td>
<td>{a.has_api_secret ? '已配置' : '未配置'}</td>
<td className="accounts-actions-cell">
<button
type="button"
className="system-btn"
disabled={accountsBusy || a.id === 1}
title={a.id === 1 ? '默认账号建议保留' : '切换启用/禁用'}
onClick={async () => {
setAccountsBusy(true)
setMessage('')
try {
const next = a.status === 'active' ? 'disabled' : 'active'
await api.updateAccount(a.id, { status: next })
await loadAccountsAdmin()
notifyAccountsUpdated()
setMessage(`账号 #${a.id}${next === 'active' ? '启用' : '禁用'}`)
} catch (e) {
setMessage('更新账号失败: ' + (e?.message || '未知错误'))
} finally {
setAccountsBusy(false)
}
}}
>
{a.status === 'active' ? '禁用' : '启用'}
</button>
<button
type="button"
className="system-btn"
disabled={accountsBusy}
onClick={() => {
setCredEditId(a.id)
setCredForm({ api_key: '', api_secret: '', use_testnet: !!a.use_testnet })
}}
>
更新密钥
</button>
</td>
</tr>
))}
</tbody>
</table>
) : (
<div className="accounts-empty">暂无账号默认账号 #1 会自动存在</div>
)}
</div>
</div>
{credEditId ? (
{showAccountsAdmin ? (
<div className="accounts-admin-body">
<div className="accounts-admin-card">
<div className="accounts-admin-card-title">新账号 #{credEditId} 的密钥</div>
<div className="accounts-admin-card-title">新增账号</div>
<div className="accounts-form">
<label>
API KEY留空=不改
名称
<input
type="password"
value={credForm.api_key}
onChange={(e) => setCredForm({ ...credForm, api_key: e.target.value })}
type="text"
value={newAccount.name}
onChange={(e) => setNewAccount({ ...newAccount, name: e.target.value })}
placeholder="例如user_a"
/>
</label>
<label>
API SECRET留空=不改
API KEY
<input
type="password"
value={credForm.api_secret}
onChange={(e) => setCredForm({ ...credForm, api_secret: e.target.value })}
value={newAccount.api_key}
onChange={(e) => setNewAccount({ ...newAccount, api_key: e.target.value })}
placeholder="可先留空,后续再填"
/>
</label>
<label>
API SECRET
<input
type="password"
value={newAccount.api_secret}
onChange={(e) => setNewAccount({ ...newAccount, api_secret: e.target.value })}
placeholder="可先留空,后续再填"
/>
</label>
<label className="accounts-inline">
<span>测试网</span>
<input
type="checkbox"
checked={!!credForm.use_testnet}
onChange={(e) => setCredForm({ ...credForm, use_testnet: e.target.checked })}
checked={!!newAccount.use_testnet}
onChange={(e) => setNewAccount({ ...newAccount, use_testnet: e.target.checked })}
/>
</label>
<label>
状态
<select
value={newAccount.status}
onChange={(e) => setNewAccount({ ...newAccount, status: e.target.value })}
>
<option value="active">启用</option>
<option value="disabled">禁用</option>
</select>
</label>
<div className="accounts-form-actions">
<button
type="button"
className="system-btn"
disabled={accountsBusy}
onClick={() => setCredEditId(null)}
>
取消
</button>
<button
type="button"
className="system-btn primary"
disabled={accountsBusy}
disabled={accountsBusy || !newAccount.name.trim()}
onClick={async () => {
setAccountsBusy(true)
setMessage('')
try {
const payload = {}
if (credForm.api_key) payload.api_key = credForm.api_key
if (credForm.api_secret) payload.api_secret = credForm.api_secret
payload.use_testnet = !!credForm.use_testnet
await api.updateAccountCredentials(credEditId, payload)
setMessage(`账号 #${credEditId} 密钥已更新(建议重启该账号交易进程)`)
setCredEditId(null)
await api.createAccount(newAccount)
setMessage('账号已创建')
setNewAccount({ name: '', api_key: '', api_secret: '', use_testnet: false, status: 'active' })
await loadAccountsAdmin()
notifyAccountsUpdated()
} catch (e) {
setMessage('更新密钥失败: ' + (e?.message || '未知错误'))
setMessage('创建账号失败: ' + (e?.message || '未知错误'))
} finally {
setAccountsBusy(false)
}
}}
>
保存
创建账号
</button>
</div>
</div>
</div>
) : null}
</div>
) : null}
</div>
<div className="accounts-admin-card">
<div className="accounts-admin-card-title">账号列表</div>
<div className="accounts-table">
{(accountsAdmin || []).length ? (
<table>
<thead>
<tr>
<th>ID</th>
<th>名称</th>
<th>状态</th>
<th>测试网</th>
<th>API KEY</th>
<th>SECRET</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{accountsAdmin.map((a) => (
<tr key={a.id}>
<td>#{a.id}</td>
<td>{a.name || '-'}</td>
<td>
<span className={`acct-badge ${a.status === 'active' ? 'ok' : 'off'}`}>
{a.status === 'active' ? '启用' : '禁用'}
</span>
</td>
<td>{a.use_testnet ? '是' : '否'}</td>
<td>{a.api_key_masked || (a.has_api_key ? '已配置' : '未配置')}</td>
<td>{a.has_api_secret ? '已配置' : '未配置'}</td>
<td className="accounts-actions-cell">
<button
type="button"
className="system-btn"
disabled={accountsBusy || a.id === 1}
title={a.id === 1 ? '默认账号建议保留' : '切换启用/禁用'}
onClick={async () => {
setAccountsBusy(true)
setMessage('')
try {
const next = a.status === 'active' ? 'disabled' : 'active'
await api.updateAccount(a.id, { status: next })
await loadAccountsAdmin()
notifyAccountsUpdated()
setMessage(`账号 #${a.id}${next === 'active' ? '启用' : '禁用'}`)
} catch (e) {
setMessage('更新账号失败: ' + (e?.message || '未知错误'))
} finally {
setAccountsBusy(false)
}
}}
>
{a.status === 'active' ? '禁用' : '启用'}
</button>
<button
type="button"
className="system-btn"
disabled={accountsBusy}
onClick={() => {
setCredEditId(a.id)
setCredForm({ api_key: '', api_secret: '', use_testnet: !!a.use_testnet })
}}
>
更新密钥
</button>
</td>
</tr>
))}
</tbody>
</table>
) : (
<div className="accounts-empty">暂无账号默认账号 #1 会自动存在</div>
)}
</div>
</div>
{credEditId ? (
<div className="accounts-admin-card">
<div className="accounts-admin-card-title">更新账号 #{credEditId} 的密钥</div>
<div className="accounts-form">
<label>
API KEY留空=不改
<input
type="password"
value={credForm.api_key}
onChange={(e) => setCredForm({ ...credForm, api_key: e.target.value })}
/>
</label>
<label>
API SECRET留空=不改
<input
type="password"
value={credForm.api_secret}
onChange={(e) => setCredForm({ ...credForm, api_secret: e.target.value })}
/>
</label>
<label className="accounts-inline">
<span>测试网</span>
<input
type="checkbox"
checked={!!credForm.use_testnet}
onChange={(e) => setCredForm({ ...credForm, use_testnet: e.target.checked })}
/>
</label>
<div className="accounts-form-actions">
<button
type="button"
className="system-btn"
disabled={accountsBusy}
onClick={() => setCredEditId(null)}
>
取消
</button>
<button
type="button"
className="system-btn primary"
disabled={accountsBusy}
onClick={async () => {
setAccountsBusy(true)
setMessage('')
try {
const payload = {}
if (credForm.api_key) payload.api_key = credForm.api_key
if (credForm.api_secret) payload.api_secret = credForm.api_secret
payload.use_testnet = !!credForm.use_testnet
await api.updateAccountCredentials(credEditId, payload)
setMessage(`账号 #${credEditId} 密钥已更新(建议重启该账号交易进程)`)
setCredEditId(null)
await loadAccountsAdmin()
notifyAccountsUpdated()
} catch (e) {
setMessage('更新密钥失败: ' + (e?.message || '未知错误'))
} finally {
setAccountsBusy(false)
}
}}
>
保存
</button>
</div>
</div>
</div>
) : null}
</div>
) : null}
</div>
) : null}
{/* 预设方案快速切换 */}
<div className="preset-section">
<div className="preset-header">
@ -1233,7 +1237,7 @@ const ConfigPanel = ({ currentUser }) => {
})()}
</div>
</div>
{/* 配置可行性检查提示 */}
{feasibilityCheck && (
<div className={`feasibility-check ${feasibilityCheck.feasible ? 'feasible' : 'infeasible'}`}>
@ -1241,8 +1245,8 @@ const ConfigPanel = ({ currentUser }) => {
<h4>
{feasibilityCheck.feasible ? '✓ 配置可行' : '⚠ 配置冲突'}
</h4>
<button
onClick={checkFeasibility}
<button
onClick={checkFeasibility}
disabled={checkingFeasibility}
className="refresh-btn"
title="重新检查"
@ -1252,23 +1256,23 @@ const ConfigPanel = ({ currentUser }) => {
</div>
<div className="feasibility-info">
<p>
账户余额: <strong>{feasibilityCheck.account_balance?.toFixed(2) || 'N/A'}</strong> USDT |
账户余额: <strong>{feasibilityCheck.account_balance?.toFixed(2) || 'N/A'}</strong> USDT |
基础杠杆: <strong>{feasibilityCheck.base_leverage || feasibilityCheck.leverage || 'N/A'}x</strong>
{feasibilityCheck.use_dynamic_leverage && feasibilityCheck.max_leverage && (
<> | 最大杠杆: <strong>{feasibilityCheck.max_leverage}x</strong></>
)} |
)} |
最小保证金: <strong>{feasibilityCheck.current_config?.min_margin_usdt?.toFixed(2) || 'N/A'}</strong> USDT
</p>
{!feasibilityCheck.feasible && (
<div className="warning-text">
<p>
需要保证金占比: <strong>{feasibilityCheck.calculated_values?.required_position_percent?.toFixed(1)}%</strong> |
需要保证金占比: <strong>{feasibilityCheck.calculated_values?.required_position_percent?.toFixed(1)}%</strong> |
最大允许保证金占比: <strong>{feasibilityCheck.calculated_values?.max_allowed_position_percent?.toFixed(1)}%</strong>
</p>
{feasibilityCheck.calculated_values?.actual_min_margin !== undefined && (
<p>
最小保证金占比可提供保证金: <strong>{feasibilityCheck.calculated_values.actual_min_margin.toFixed(2)} USDT</strong>
(MIN_POSITION_PERCENT={feasibilityCheck.calculated_values.min_position_percent?.toFixed(1)}%) |
最小保证金占比可提供保证金: <strong>{feasibilityCheck.calculated_values.actual_min_margin.toFixed(2)} USDT</strong>
(MIN_POSITION_PERCENT={feasibilityCheck.calculated_values.min_position_percent?.toFixed(1)}%) |
最小保证金要求: <strong>{feasibilityCheck.current_config?.min_margin_usdt?.toFixed(2)} USDT</strong>
</p>
)}
@ -1317,7 +1321,7 @@ const ConfigPanel = ({ currentUser }) => {
</div>
)
}
//
return (
<div key={index} className="suggestion-item">
@ -1353,13 +1357,13 @@ const ConfigPanel = ({ currentUser }) => {
)}
</div>
)}
{message && (
<div className={`message ${message.includes('失败') || message.includes('错误') ? 'error' : 'success'}`}>
{message}
</div>
)}
{Object.entries(configCategories).map(([category, label]) => (
<section key={category} className="config-section">
<h3>{label}</h3>
@ -1465,7 +1469,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
}
return val === null || val === undefined ? '' : val
}
const [value, setValue] = useState(config.value)
const [localValue, setLocalValue] = useState(getInitialDisplayValue(config.value))
const [isEditing, setIsEditing] = useState(false)
@ -1485,7 +1489,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
const handleSave = () => {
setIsEditing(false)
// localValue
let processedValue = localValue
if (config.type === 'number') {
@ -1494,7 +1498,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
setLocalValue(value)
return
}
// "0." "."
let numValue
if (typeof localValue === 'string') {
@ -1515,7 +1519,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
} else {
numValue = localValue
}
if (isNaN(numValue)) {
//
const restoreValue = isPercentKey
@ -1524,7 +1528,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
setLocalValue(restoreValue)
return
}
processedValue = numValue
//
if (isPercentKey) {
@ -1546,7 +1550,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
} else if (config.type === 'boolean') {
processedValue = localValue === 'true' || localValue === true
}
//
if (processedValue !== value) {
onUpdate(processedValue)
@ -1577,7 +1581,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
<div className="config-item-header">
<label>{label}</label>
{config.description && (
<button
<button
className="help-btn"
onClick={() => setShowDetail(!showDetail)}
type="button"
@ -1591,8 +1595,8 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
{getConfigDetail(label)}
</div>
)}
<select
value={localValue ? 'true' : 'false'}
<select
value={localValue ? 'true' : 'false'}
onChange={(e) => {
handleChange(e.target.value)
//
@ -1619,7 +1623,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
<div className="config-item-header">
<label>{label}</label>
{config.description && (
<button
<button
className="help-btn"
onClick={() => setShowDetail(!showDetail)}
type="button"
@ -1633,8 +1637,8 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
{getConfigDetail(label)}
</div>
)}
<select
value={localValue}
<select
value={localValue}
onChange={(e) => {
handleChange(e.target.value)
//
@ -1660,7 +1664,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
<div className="config-item-header">
<label>{label}</label>
{config.description && (
<button
<button
className="help-btn"
onClick={() => setShowDetail(!showDetail)}
type="button"
@ -1682,7 +1686,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
onChange={(e) => {
// 使number0
let newValue = e.target.value
//
if (config.type === 'number') {
//
@ -1691,7 +1695,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
// //
// return
// }
// 0-100
if (isPercentKey) {
const numValue = parseFloat(newValue)
@ -1702,7 +1706,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
}
}
}
//
if (config.type === 'number' && isPercentKey) {
// "2."
@ -1764,7 +1768,7 @@ const ConfigItem = ({ label, config, onUpdate, disabled }) => {
/>
{isPercentKey && <span className="percent-suffix">%</span>}
{isEditing && (
<button
<button
className="save-btn"
onClick={handleSave}
disabled={disabled}
@ -1799,18 +1803,18 @@ const getConfigDetail = (key) => {
'PRIMARY_INTERVAL': '主周期。策略分析的主要时间周期用于计算技术指标RSI、MACD、布林带等。决定策略主要关注的市场趋势级别。周期越短反应越快周期越长趋势更明确。建议保守策略4h-1d平衡策略1h-4h激进策略15m-1h。',
'CONFIRM_INTERVAL': '确认周期。用于确认交易信号的更长时间周期增加信号的可靠性减少假信号。通常比主周期更长。建议保守策略1d平衡策略4h-1d激进策略1h-4h。',
'ENTRY_INTERVAL': '入场周期。用于精确入场的短时间周期优化入场点提高单笔交易的盈亏比。通常比主周期更短。建议保守策略1h平衡策略15m-30m激进策略5m-15m。',
//
'MAX_POSITION_PERCENT': '单笔最大保证金占用账户余额的百分比如0.02表示2%。系统会先按该比例分配“保证金”再根据杠杆换算名义价值下单。值越小越保守适合回归波段交易、降低单笔波动对账户的伤害。注意币安合约有最小名义价值要求通常≥5 USDT如果保证金过小且杠杆不够系统会提示无法满足最小名义价值。',
'MAX_TOTAL_POSITION_PERCENT': '总保证金上限账户余额的百分比如0.20表示20%)。所有持仓占用的保证金之和不能超过该上限,防止过度分散和风险集中。值越小越易控仓,便于管理持仓数量与节奏。',
'MIN_POSITION_PERCENT': '单笔最小保证金占用账户余额的百分比如0.01表示1%。用于避免过小仓位意义不大、易受手续费影响。如果你希望取消这一限制可设置为0等价于关闭最小占比。',
//
'STOP_LOSS_PERCENT': '止损百分比如0.08表示8%相对于保证金。当亏损达到此百分比时自动平仓止损限制单笔交易的最大亏损。值越小止损更严格单笔损失更小但可能被正常波动触发。值越大允许更大的回撤但单笔损失可能较大。建议保守策略10-15%平衡策略8-10%激进策略5-8%。注意止损应该小于止盈建议盈亏比至少1:1.5。系统会结合最小价格变动保护,取更宽松的一个。',
'TAKE_PROFIT_PERCENT': '止盈百分比如0.15表示15%相对于保证金。当盈利达到此百分比时自动平仓止盈锁定利润。值越大目标利润更高但可能错过及时止盈的机会持仓时间更长。值越小能更快锁定利润但可能错过更大的趋势。建议保守策略20-30%平衡策略15-20%激进策略10-15%。注意应该大于止损建议盈亏比至少1:1.5。系统会结合最小价格变动保护,取更宽松的一个。',
'MIN_STOP_LOSS_PRICE_PCT': '最小止损价格变动百分比存储为0~1前端输入按%显示支持小数如1.5%。用于防止止损过紧即使基于保证金的止损更紧也会使用至少该百分比的价格变动。建议1.5%-3%。',
'MIN_TAKE_PROFIT_PRICE_PCT': '最小止盈价格变动百分比存储为0~1前端输入按%显示支持小数如2.5%。用于防止止盈过紧即使基于保证金的止盈更紧也会使用至少该百分比的价格变动。建议2%-4%。',
//
'LEVERAGE': '交易杠杆倍数。放大资金利用率同时放大收益和风险。杠杆越高相同仓位下需要的保证金越少但风险越大。建议保守策略5-10倍平衡策略10倍激进策略10-15倍。注意高杠杆会增加爆仓风险请谨慎使用。',
'USE_TRAILING_STOP': '是否启用移动止损true/false。启用后当盈利达到激活阈值时止损会自动跟踪价格保护利润。适合趋势行情可以捕捉更大的利润空间。建议平衡和激进策略启用保守策略可关闭。',
@ -1826,7 +1830,7 @@ const getConfigDetail = (key) => {
'ENTRY_MAX_DRIFT_PCT_RANGING': '震荡/弱趋势最大追价偏离(%)。例如 0.15 表示 0.15%。越小越保守;建议 0.1%-0.3%。',
'TRAILING_STOP_ACTIVATION': '移动止损激活阈值百分比如0.01表示1%。当盈利达到此百分比时移动止损开始跟踪价格将止损移至成本价保本。值越小激活越早更早保护利润但可能过早退出。值越大激活越晚给价格更多波动空间。建议1-2%。',
'TRAILING_STOP_PROTECT': '移动止损保护利润百分比如0.01表示1%。当价格从最高点回撤达到此百分比时触发止损平仓锁定利润。值越小保护更严格能锁定更多利润但可能过早退出。值越大允许更大回撤可能捕捉更大趋势但利润可能回吐。建议1-2%。',
// API
'BINANCE_API_KEY': '币安API密钥。用于访问币安账户的凭证需要启用"合约交易"权限。请妥善保管,不要泄露。',
'BINANCE_API_SECRET': '币安API密钥。与API Key配对使用用于签名验证。请妥善保管不要泄露。',