This commit is contained in:
薇薇安 2026-02-16 12:05:11 +08:00
parent 22efd377a7
commit a402007b99

View File

@ -2608,7 +2608,7 @@ class PositionManager:
import traceback
logger.debug(f"{symbol} [状态同步] 错误详情:\n{traceback.format_exc()}")
# 如果无法从订单获取,使用当前价格
# 如果无法从订单获取,尝试使用当前价格若当前价格也无法获取则保留open状态等待下次同步
if not exit_price or exit_price <= 0:
try:
ticker = await self.client.get_ticker_24h(symbol)
@ -2616,31 +2616,25 @@ class PositionManager:
exit_price = float(ticker['price'])
logger.warning(f"{symbol} [状态同步] 使用当前价格作为平仓价格: {exit_price:.4f} USDT")
else:
exit_price = float(trade.get('entry_price', 0))
logger.warning(
f"{symbol} [状态同步] 无法获取当前价格ticker={ticker}"
f"使用入场价: {exit_price:.4f} USDT"
f"保留open状态等待下次同步"
)
continue
except KeyError as key_error:
# KeyError 可能是访问 ticker['price'] 时出错
logger.error(
f"{symbol} [状态同步] ❌ 获取当前价格时KeyError: {key_error}, "
f"ticker数据: {ticker if 'ticker' in locals() else 'N/A'}"
)
exit_price = float(trade.get('entry_price', 0))
if exit_price <= 0:
logger.error(f"{symbol} [状态同步] ❌ 无法获取有效的平仓价格,跳过更新")
continue
continue
except Exception as ticker_error:
logger.warning(
f"{symbol} [状态同步] 获取当前价格失败: "
f"错误类型={type(ticker_error).__name__}, 错误消息={str(ticker_error)}"
f"使用入场价: {trade.get('entry_price', 'N/A')}"
f"将保留open状态等待下次同步"
)
exit_price = float(trade.get('entry_price', 0))
if exit_price <= 0:
logger.error(f"{symbol} [状态同步] ❌ 无法获取有效的平仓价格,跳过更新")
continue
continue
# 计算盈亏确保所有值都是float类型避免Decimal类型问题
try: