1
This commit is contained in:
parent
965c1651cd
commit
66a78759d3
|
|
@ -2888,10 +2888,10 @@ class PositionManager:
|
||||||
system_order_prefix = (config.TRADING_CONFIG.get("SYSTEM_ORDER_ID_PREFIX") or "").strip()
|
system_order_prefix = (config.TRADING_CONFIG.get("SYSTEM_ORDER_ID_PREFIX") or "").strip()
|
||||||
if system_order_prefix:
|
if system_order_prefix:
|
||||||
logger.info(
|
logger.info(
|
||||||
f" → 补建「系统单」记录:仅当开仓订单 clientOrderId 明确非 {system_order_prefix!r} 前缀时跳过(视为手动单),其余一律补建"
|
f" → 补建缺失持仓:一律写入 DB、自动挂止损止盈并纳入监控(含 clientOrderId 非 {system_order_prefix!r} 前缀的来历不明仓)"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
logger.info(" → 补建「系统单」记录(仅当存在止损/止盈单时创建,避免手动单误建)" if sync_recover_only_has_sltp else " → 补建缺失持仓记录")
|
logger.info(" → 补建缺失持仓:一律写入 DB、自动挂止损止盈并纳入监控(含无 SL/TP 的仓位)")
|
||||||
for symbol in missing_in_db:
|
for symbol in missing_in_db:
|
||||||
try:
|
try:
|
||||||
binance_position = next((p for p in binance_positions if p.get("symbol") == symbol), None)
|
binance_position = next((p for p in binance_positions if p.get("symbol") == symbol), None)
|
||||||
|
|
@ -2915,7 +2915,7 @@ class PositionManager:
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
client_order_id_sync = None
|
client_order_id_sync = None
|
||||||
# 仅当「明确查到开仓订单且 clientOrderId 非空且不以系统前缀开头」时视为手动单并跳过;其余一律补建(避免漏掉系统单)
|
# 仅当「明确查到开仓订单且 clientOrderId 非空且不以系统前缀开头」时标记为来历不明(仍会补建+挂 SL/TP+监控)
|
||||||
is_clearly_manual = False
|
is_clearly_manual = False
|
||||||
if system_order_prefix:
|
if system_order_prefix:
|
||||||
if entry_order_id:
|
if entry_order_id:
|
||||||
|
|
@ -2925,17 +2925,22 @@ class PositionManager:
|
||||||
client_order_id_sync = cid or None
|
client_order_id_sync = cid or None
|
||||||
if cid and not cid.startswith(system_order_prefix):
|
if cid and not cid.startswith(system_order_prefix):
|
||||||
is_clearly_manual = True
|
is_clearly_manual = True
|
||||||
logger.debug(f" {symbol} 开仓订单 clientOrderId={cid!r} 非系统前缀,视为手动单,跳过补建")
|
logger.debug(f" {symbol} 开仓订单 clientOrderId={cid!r} 非系统前缀,将按来历不明仓补建并挂 SL/TP")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f" {symbol} 查询开仓订单失败: {e},按系统单补建")
|
logger.debug(f" {symbol} 查询开仓订单失败: {e},按系统单补建")
|
||||||
# 无法获取订单或 cid 为空(历史单/未带前缀)时不视为手动单,继续补建
|
# 无法获取订单或 cid 为空(历史单/未带前缀)时不视为手动单,继续补建
|
||||||
else:
|
# 例外:若开启「仅币安有仓且存在 SL/TP 也监控」,且该 symbol 有止损/止盈单,可视为系统单(仅影响日志)
|
||||||
# 未配置前缀时,用「是否有止损/止盈单」区分
|
if is_clearly_manual and config.TRADING_CONFIG.get("SYNC_MONITOR_BINANCE_POSITIONS_WITH_SLTP", True):
|
||||||
if sync_recover_only_has_sltp and not (await self._symbol_has_sltp_orders(symbol)):
|
if await self._symbol_has_sltp_orders(symbol):
|
||||||
logger.debug(f" {symbol} 无止损/止盈单,跳过补建")
|
is_clearly_manual = False
|
||||||
continue
|
logger.info(f" → {symbol} 开仓订单 clientOrderId 非系统前缀,但存在止损/止盈单,按系统单补建并监控")
|
||||||
if is_clearly_manual:
|
if is_clearly_manual:
|
||||||
continue
|
logger.info(f" → {symbol} 来历不明(开仓订单非系统前缀),将补建记录、自动挂止损止盈并纳入监控")
|
||||||
|
else:
|
||||||
|
# 未配置前缀时,不再因「无止损/止盈单」跳过:一律补建并自动挂 SL/TP、纳入监控
|
||||||
|
if sync_recover_only_has_sltp and not (await self._symbol_has_sltp_orders(symbol)):
|
||||||
|
logger.info(f" → {symbol} 无止损/止盈单,将补建记录、自动挂止损止盈并纳入监控")
|
||||||
|
# 不再因 is_clearly_manual 或 无 SL/TP 跳过,一律补建 + 挂 SL/TP + 监控
|
||||||
if entry_order_id and hasattr(Trade, "get_by_entry_order_id"):
|
if entry_order_id and hasattr(Trade, "get_by_entry_order_id"):
|
||||||
try:
|
try:
|
||||||
if Trade.get_by_entry_order_id(entry_order_id):
|
if Trade.get_by_entry_order_id(entry_order_id):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user