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
+21 -5
View File
@@ -3120,16 +3120,32 @@ def _gate_place_stop_loss_only_position(exchange_symbol, direction, stop_loss):
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 ensure_markets_loaded(force=False):