1
This commit is contained in:
parent
be1349c1fc
commit
80485e7271
|
|
@ -1399,8 +1399,13 @@ class BinanceClient:
|
||||||
order = await _submit(order_params)
|
order = await _submit(order_params)
|
||||||
except BinanceAPIException as e:
|
except BinanceAPIException as e:
|
||||||
code = getattr(e, "code", None)
|
code = getattr(e, "code", None)
|
||||||
if code in (-4061, -1106):
|
if code in (-4061, -1106, -1022):
|
||||||
retry_params = dict(order_params)
|
retry_params = dict(order_params)
|
||||||
|
# 关键修复:重试时必须清除之前的 timestamp 和 signature,
|
||||||
|
# 让 python-binance 重新生成,否则会报 -1022 Signature invalid
|
||||||
|
retry_params.pop('timestamp', None)
|
||||||
|
retry_params.pop('signature', None)
|
||||||
|
|
||||||
if code == -4061:
|
if code == -4061:
|
||||||
logger.error(f"{symbol} 触发 -4061(持仓模式不匹配),尝试自动兜底重试一次")
|
logger.error(f"{symbol} 触发 -4061(持仓模式不匹配),尝试自动兜底重试一次")
|
||||||
if "positionSide" in retry_params:
|
if "positionSide" in retry_params:
|
||||||
|
|
|
||||||
|
|
@ -1509,14 +1509,25 @@ class PositionManager:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug(f"{symbol} 检查止盈触发条件时出错: {e}")
|
logger.debug(f"{symbol} 检查止盈触发条件时出错: {e}")
|
||||||
|
|
||||||
tp_order = await self.client.place_trigger_close_position_order(
|
try:
|
||||||
symbol=symbol,
|
tp_order = await self.client.place_trigger_close_position_order(
|
||||||
position_direction=side,
|
symbol=symbol,
|
||||||
trigger_type="TAKE_PROFIT_MARKET",
|
position_direction=side,
|
||||||
stop_price=take_profit,
|
trigger_type="TAKE_PROFIT_MARKET",
|
||||||
current_price=current_price,
|
stop_price=take_profit,
|
||||||
working_type="MARK_PRICE",
|
current_price=current_price,
|
||||||
)
|
working_type="MARK_PRICE",
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
# 处理 -2021: Order would immediately trigger
|
||||||
|
error_msg = str(e)
|
||||||
|
if "-2021" in error_msg or "immediately trigger" in error_msg:
|
||||||
|
logger.warning(f"{symbol} ⚠️ 止盈单会立即触发(-2021),视为已到达止盈位,立即执行市价止盈")
|
||||||
|
await self.close_position(symbol, reason='take_profit')
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
logger.warning(f"{symbol} 挂止盈单失败: {e}")
|
||||||
|
tp_order = None
|
||||||
if tp_order:
|
if tp_order:
|
||||||
logger.info(f"{symbol} ✓ 止盈单已成功挂到交易所: {tp_order.get('algoId', 'N/A')}")
|
logger.info(f"{symbol} ✓ 止盈单已成功挂到交易所: {tp_order.get('algoId', 'N/A')}")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user