This commit is contained in:
薇薇安 2026-01-17 20:53:57 +08:00
parent 0570ff6823
commit dc2aa49035
2 changed files with 79 additions and 8 deletions

View File

@ -142,29 +142,92 @@ async def check_config_feasibility():
worst_margin = worst['actual_min_margin']
# 方案1基于最坏情况最大杠杆降低最小保证金
# 建议值应该比计算值小一点确保可行比如0.51 -> 0.5
if not worst['condition2_ok']:
# 计算建议值比实际支持值小0.01-0.05,确保可行
suggested_margin = max(0.01, worst_margin - 0.01) # 至少保留0.01的余量
# 如果差值较大,可以多减一点
if worst_margin > 1.0:
suggested_margin = worst_margin - 0.05
# 保留2位小数向下取整
suggested_margin = round(suggested_margin - 0.005, 2) # 减0.005确保向下取整
if suggested_margin < 0.01:
suggested_margin = 0.01
suggestions.append({
"type": "reduce_min_margin_to_supported",
"title": f"降低最小保证金(考虑{worst_leverage}x杠杆",
"description": f"将 MIN_MARGIN_USDT 调整为 {worst_margin:.2f} USDT当前: {min_margin_usdt:.2f} USDT。在{worst_leverage}x杠杆下实际只支持 {worst_margin:.2f} USDT",
"description": f"将 MIN_MARGIN_USDT 调整为 {suggested_margin:.2f} USDT当前: {min_margin_usdt:.2f} USDT。在{worst_leverage}x杠杆下实际支持 {worst_margin:.2f} USDT,建议设置为 {suggested_margin:.2f} USDT 以确保可行",
"config_key": "MIN_MARGIN_USDT",
"suggested_value": round(worst_margin, 2),
"suggested_value": suggested_margin,
"reason": f"{worst_leverage}x杠杆下使用最小仓位 {min_position_percent*100:.1f}% 时,实际保证金只有 {worst_margin:.2f} USDT无法满足 {min_margin_usdt:.2f} USDT 的要求"
})
# 方案1b增加最小仓位百分比作为替代方案
# 计算需要的最小仓位百分比min_position_percent >= (min_margin_usdt * leverage) / available_balance
required_min_position_percent = (min_margin_usdt * worst_leverage) / available_balance if available_balance > 0 else 0
# 建议值应该比计算值大一点确保可行比如0.0102 -> 0.011
suggested_min_position_percent = required_min_position_percent + 0.001 # 多0.1%
# 如果差值较大,可以多加一点
if required_min_position_percent > 0.02:
suggested_min_position_percent = required_min_position_percent + 0.002 # 多0.2%
# 确保不超过最大仓位百分比
if suggested_min_position_percent > max_position_percent:
suggested_min_position_percent = max_position_percent
# 保留4位小数
suggested_min_position_percent = round(suggested_min_position_percent, 4)
if suggested_min_position_percent > min_position_percent and suggested_min_position_percent <= max_position_percent:
suggestions.append({
"type": "increase_min_position_percent",
"title": f"增加最小仓位百分比(考虑{worst_leverage}x杠杆",
"description": f"将 MIN_POSITION_PERCENT 调整为 {suggested_min_position_percent*100:.2f}%(当前: {min_position_percent*100:.2f}%)。在{worst_leverage}x杠杆下需要至少 {required_min_position_percent*100:.2f}% 才能满足最小保证金 {min_margin_usdt:.2f} USDT 的要求,建议设置为 {suggested_min_position_percent*100:.2f}% 以确保可行",
"config_key": "MIN_POSITION_PERCENT",
"suggested_value": suggested_min_position_percent,
"reason": f"{worst_leverage}x杠杆下当前最小仓位 {min_position_percent*100:.2f}% 只能提供 {worst_margin:.2f} USDT 保证金,需要至少 {required_min_position_percent*100:.2f}% 才能满足 {min_margin_usdt:.2f} USDT 的要求"
})
# 方案2基于最大杠杆计算需要的最小保证金
max_leverage_result = next((r for r in leverage_results if r['leverage'] == max_leverage), None)
if max_leverage_result and not max_leverage_result['feasible']:
if max_leverage_result['required_position_percent'] > max_position_percent:
suggested_min_margin_max_lev = (available_balance * max_position_percent) / max_leverage
# 同样,建议值应该比计算值小一点
suggested_margin_max_lev = max(0.01, suggested_min_margin_max_lev - 0.01)
if suggested_min_margin_max_lev > 1.0:
suggested_margin_max_lev = suggested_min_margin_max_lev - 0.05
suggested_margin_max_lev = round(suggested_margin_max_lev - 0.005, 2)
if suggested_margin_max_lev < 0.01:
suggested_margin_max_lev = 0.01
suggestions.append({
"type": "reduce_min_margin_for_max_leverage",
"title": f"降低最小保证金(支持{max_leverage}x杠杆",
"description": f"将 MIN_MARGIN_USDT 调整为 {suggested_min_margin_max_lev:.2f} USDT当前: {min_margin_usdt:.2f} USDT以支持{max_leverage}x杠杆",
"description": f"将 MIN_MARGIN_USDT 调整为 {suggested_margin_max_lev:.2f} USDT当前: {min_margin_usdt:.2f} USDT以支持{max_leverage}x杠杆",
"config_key": "MIN_MARGIN_USDT",
"suggested_value": round(suggested_min_margin_max_lev, 2),
"suggested_value": suggested_margin_max_lev,
"reason": f"{max_leverage}x杠杆下需要 {max_leverage_result['required_position_percent']:.1f}% 的仓位价值,但最大允许 {max_position_percent*100:.1f}%"
})
# 方案2b如果condition2不满足也可以建议增加最小仓位百分比
if not max_leverage_result['condition2_ok']:
required_min_position_percent_max = (min_margin_usdt * max_leverage) / available_balance if available_balance > 0 else 0
suggested_min_position_percent_max = required_min_position_percent_max + 0.001
if required_min_position_percent_max > 0.02:
suggested_min_position_percent_max = required_min_position_percent_max + 0.002
if suggested_min_position_percent_max > max_position_percent:
suggested_min_position_percent_max = max_position_percent
suggested_min_position_percent_max = round(suggested_min_position_percent_max, 4)
if suggested_min_position_percent_max > min_position_percent and suggested_min_position_percent_max <= max_position_percent:
suggestions.append({
"type": "increase_min_position_percent_for_max_leverage",
"title": f"增加最小仓位百分比(支持{max_leverage}x杠杆",
"description": f"将 MIN_POSITION_PERCENT 调整为 {suggested_min_position_percent_max*100:.2f}%(当前: {min_position_percent*100:.2f}%),以支持{max_leverage}x杠杆下的最小保证金要求",
"config_key": "MIN_POSITION_PERCENT",
"suggested_value": suggested_min_position_percent_max,
"reason": f"{max_leverage}x杠杆下需要至少 {required_min_position_percent_max*100:.2f}% 的最小仓位才能满足 {min_margin_usdt:.2f} USDT 的要求"
})
# 方案3降低最大杠杆
if use_dynamic_leverage:

View File

@ -333,10 +333,18 @@ const StatsDashboard = () => {
: ((entryPrice - takeProfitPrice) / entryPrice) * 100
//
const formatEntryTime = (timeStr) => {
if (!timeStr) return null
// Unix
const formatEntryTime = (timeValue) => {
if (!timeValue) return null
try {
const date = new Date(timeStr)
let date
// Unix
if (typeof timeValue === 'number') {
date = new Date(timeValue * 1000)
} else {
date = new Date(timeValue)
}
if (isNaN(date.getTime())) return String(timeValue)
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, '0')
const day = String(date.getDate()).padStart(2, '0')
@ -345,7 +353,7 @@ const StatsDashboard = () => {
const seconds = String(date.getSeconds()).padStart(2, '0')
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
} catch (e) {
return timeStr
return String(timeValue)
}
}