1
This commit is contained in:
parent
47151f5721
commit
665fa4782e
@ -503,6 +503,37 @@ class BitgetTradingAPI:
|
|||||||
logger.warning(f"⚠️ 止盈止损价格均不合理,无法设置")
|
logger.warning(f"⚠️ 止盈止损价格均不合理,无法设置")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
rounded_sl = self._price_to_precision(ccxt_symbol, valid_sl) if valid_sl else None
|
||||||
|
rounded_tp = self._price_to_precision(ccxt_symbol, valid_tp) if valid_tp else None
|
||||||
|
if rounded_sl and rounded_sl != valid_sl:
|
||||||
|
logger.info(f"Bitget 止损价按交易所精度规整: {valid_sl} -> {rounded_sl}")
|
||||||
|
valid_sl = rounded_sl
|
||||||
|
if rounded_tp and rounded_tp != valid_tp:
|
||||||
|
logger.info(f"Bitget 止盈价按交易所精度规整: {valid_tp} -> {rounded_tp}")
|
||||||
|
valid_tp = rounded_tp
|
||||||
|
if pos_side == 'long':
|
||||||
|
if valid_sl and valid_sl >= mark_price:
|
||||||
|
logger.warning(f"规整后做多止损无效: SL={valid_sl}, Mark={mark_price},跳过止损")
|
||||||
|
result["errors"].append(f"规整后止损价 {valid_sl} >= 标记价 {mark_price}")
|
||||||
|
valid_sl = None
|
||||||
|
if valid_tp and valid_tp <= mark_price:
|
||||||
|
logger.warning(f"规整后做多止盈无效: TP={valid_tp}, Mark={mark_price},跳过止盈")
|
||||||
|
result["errors"].append(f"规整后止盈价 {valid_tp} <= 标记价 {mark_price}")
|
||||||
|
valid_tp = None
|
||||||
|
else:
|
||||||
|
if valid_sl and valid_sl <= mark_price:
|
||||||
|
logger.warning(f"规整后做空止损无效: SL={valid_sl}, Mark={mark_price},跳过止损")
|
||||||
|
result["errors"].append(f"规整后止损价 {valid_sl} <= 标记价 {mark_price}")
|
||||||
|
valid_sl = None
|
||||||
|
if valid_tp and valid_tp >= mark_price:
|
||||||
|
logger.warning(f"规整后做空止盈无效: TP={valid_tp}, Mark={mark_price},跳过止盈")
|
||||||
|
result["errors"].append(f"规整后止盈价 {valid_tp} >= 标记价 {mark_price}")
|
||||||
|
valid_tp = None
|
||||||
|
|
||||||
|
if not valid_sl and not valid_tp:
|
||||||
|
logger.warning("⚠️ 止盈止损价格规整后均不合理,无法设置")
|
||||||
|
return result
|
||||||
|
|
||||||
# 使用独立的止损/止盈计划订单
|
# 使用独立的止损/止盈计划订单
|
||||||
# 注意:这种方式需要在平仓时也取消这些计划订单
|
# 注意:这种方式需要在平仓时也取消这些计划订单
|
||||||
|
|
||||||
@ -1125,6 +1156,16 @@ class BitgetTradingAPI:
|
|||||||
# 回退:4 位小数截断
|
# 回退:4 位小数截断
|
||||||
return math.floor(amount * 10000) / 10000
|
return math.floor(amount * 10000) / 10000
|
||||||
|
|
||||||
|
def _price_to_precision(self, ccxt_symbol: str, price: Optional[float]) -> Optional[float]:
|
||||||
|
"""按交易所价格精度规整触发价,避免 Bitget 拒绝 TP/SL 策略单。"""
|
||||||
|
if price is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
return float(self.exchange.price_to_precision(ccxt_symbol, price))
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"{ccxt_symbol} 价格精度规整失败,使用兜底四位小数: {price}, error={e}")
|
||||||
|
return round(float(price), 4)
|
||||||
|
|
||||||
def _get_min_amount(self, ccxt_symbol: str) -> float:
|
def _get_min_amount(self, ccxt_symbol: str) -> float:
|
||||||
"""获取交易对最小下单数量"""
|
"""获取交易对最小下单数量"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user