修复okx 趋势回调
This commit is contained in:
@@ -2971,7 +2971,11 @@ def replace_active_monitor_tpsl_on_exchange(order_row, stop_loss, take_profit):
|
||||
|
||||
|
||||
def _okx_place_stop_loss_only(exchange_symbol, direction, stop_loss):
|
||||
"""OKX 永续:仅挂止损(趋势回调),止盈由程序监控。"""
|
||||
"""OKX 永续:仅挂止损(趋势回调),止盈由程序监控。
|
||||
|
||||
须用 stopLossPrice 挂条件单;勿用 reduce-only 市价单 + params['stopLoss'],
|
||||
后者会当成立即市价平仓(开仓后约 1 秒内全平)。
|
||||
"""
|
||||
ensure_markets_loaded()
|
||||
pos_amt = get_live_position_contracts(exchange_symbol, direction)
|
||||
if pos_amt is None or float(pos_amt) <= 0:
|
||||
@@ -2979,12 +2983,27 @@ def _okx_place_stop_loss_only(exchange_symbol, direction, stop_loss):
|
||||
cancel_okx_swap_open_orders(exchange_symbol)
|
||||
close_side = "sell" if direction == "long" else "buy"
|
||||
amt = float(exchange.amount_to_precision(exchange_symbol, float(pos_amt)))
|
||||
params = build_okx_order_params(direction, reduce_only=True)
|
||||
params["stopLoss"] = {
|
||||
"triggerPrice": _okx_algo_trigger_price_str(exchange_symbol, stop_loss),
|
||||
"type": "market",
|
||||
}
|
||||
exchange.create_order(exchange_symbol, "market", close_side, amt, None, params)
|
||||
if amt <= 0:
|
||||
raise RuntimeError("止损:可平数量经精度舍入后为 0")
|
||||
base = build_okx_order_params(direction, reduce_only=True)
|
||||
sl_px = float(stop_loss)
|
||||
last_err = None
|
||||
for attempt in range(6):
|
||||
try:
|
||||
exchange.create_order(
|
||||
exchange_symbol,
|
||||
"market",
|
||||
close_side,
|
||||
amt,
|
||||
None,
|
||||
{**base, "stopLossPrice": sl_px},
|
||||
)
|
||||
return
|
||||
except Exception as e:
|
||||
last_err = e
|
||||
cancel_okx_swap_open_orders(exchange_symbol)
|
||||
time.sleep(0.2 * (attempt + 1))
|
||||
raise RuntimeError(f"OKX 未接受止损条件单:{last_err}")
|
||||
|
||||
|
||||
def calc_trend_manual_breakeven_stop(direction, entry_price, offset_pct=None):
|
||||
|
||||
Reference in New Issue
Block a user