fix(hub,gate): cross-margin TP/SL and dedupe hub conditional orders

Gate hedge position triggers use close=false; stop silent ccxt fallback on cross margin. Hub merges agent and Flask TP/SL by trigger price and labels Gate orders correctly.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-04 19:48:04 +08:00
parent ed0805538f
commit 24270944e7
7 changed files with 220 additions and 25 deletions
+23 -5
View File
@@ -2958,6 +2958,8 @@ def _gate_place_tp_sl_orders_position_price_orders(exchange_symbol, direction, s
}
if GATE_POS_MODE == "hedge":
initial["auto_size"] = "close_long" if direction == "long" else "close_short"
# Gate API 1018auto_size=close_long|close_short 时 initial.close 须为 false
initial["close"] = False
sl_s = exchange.price_to_precision(exchange_symbol, float(stop_loss))
tp_s = exchange.price_to_precision(exchange_symbol, float(take_profit))
@@ -2993,16 +2995,32 @@ def _gate_place_tp_sl_orders_position_price_orders(exchange_symbol, direction, s
raise RuntimeError(f"交易所未接受仓位类条件止盈/止损:{last_err}")
def _gate_td_mode_is_cross():
return _GATE_DEFAULT_MARGIN_MODE == "cross"
def _gate_place_tp_sl_orders(exchange_symbol, direction, contracts_amount, stop_loss, take_profit):
pos_err = None
if GATE_TPSL_USE_POSITION_ORDER:
try:
_gate_place_tp_sl_orders_position_price_orders(exchange_symbol, direction, stop_loss, take_profit)
return
except Exception:
pass
_gate_place_tp_sl_orders_legacy_conditional(
exchange_symbol, direction, contracts_amount, stop_loss, take_profit,
)
except Exception as e:
pos_err = e
if _gate_td_mode_is_cross():
raise RuntimeError(
f"交易所未接受仓位类条件止盈/止损(全仓不支持 ccxt 条件单回退):{pos_err}"
) from e
try:
_gate_place_tp_sl_orders_legacy_conditional(
exchange_symbol, direction, contracts_amount, stop_loss, take_profit,
)
except Exception as legacy_err:
if pos_err is not None:
raise RuntimeError(
f"交易所未接受仓位类条件止盈/止损:{pos_err};条件单回退亦失败:{legacy_err}"
) from legacy_err
raise
def _gate_place_stop_loss_only_position(exchange_symbol, direction, stop_loss):