a
This commit is contained in:
parent
0570ff6823
commit
dc2aa49035
|
|
@ -142,30 +142,93 @@ 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:
|
||||
# 计算能支持的最大杠杆
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user