fix: исправить 4 бага Bybit spot (fetchOrder, safety stop, numpy warning, setLeverage spam)
- fetchOrder → fetchClosedOrder с fallback (Bybit v5 ограничивает историю) - safety stop: tpslOrder вместо StopOrder (triggerDirection не поддерживается spot) - numpy RuntimeWarning: подавить при stddev=0 в corrcoef (NaN уже обрабатывается) - setLeverage: не повторять каждый цикл если API не поддерживает Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -143,7 +143,8 @@ def check_shape_confirmation(pred_new: np.ndarray, confirm_prices: np.ndarray,
|
||||
return 0.0, False
|
||||
|
||||
actual_norm = (confirm_prices[:K] - mu) / std
|
||||
corr = np.corrcoef(pred_confirm, actual_norm)[0, 1]
|
||||
with np.errstate(invalid="ignore"):
|
||||
corr = np.corrcoef(pred_confirm, actual_norm)[0, 1]
|
||||
|
||||
if np.isnan(corr):
|
||||
return 0.0, False
|
||||
|
||||
@@ -54,7 +54,8 @@ class SpotExecutor:
|
||||
self._margin_enabled = True
|
||||
log.info(f"Spot margin enabled: {self.leverage}x for {symbol}")
|
||||
except Exception as e:
|
||||
log.warning(f"Could not set margin {self.leverage}x: {e}")
|
||||
self._margin_enabled = True # don't retry every cycle
|
||||
log.info(f"Spot margin API not available ({e}), using exchange default")
|
||||
|
||||
def get_balance(self, coin: str) -> float:
|
||||
"""Get free balance for a coin."""
|
||||
@@ -75,11 +76,15 @@ class SpotExecutor:
|
||||
return order
|
||||
try:
|
||||
time.sleep(1) # wait for order to settle
|
||||
full = self.exchange.fetch_order(order_id, symbol)
|
||||
full = self.exchange.fetch_closed_order(order_id, symbol)
|
||||
return full
|
||||
except Exception as e:
|
||||
log.warning(f"Could not fetch order details {order_id}: {e}")
|
||||
return order
|
||||
except Exception:
|
||||
try:
|
||||
full = self.exchange.fetch_order(order_id, symbol)
|
||||
return full
|
||||
except Exception as e:
|
||||
log.warning(f"Could not fetch order details {order_id}: {e}")
|
||||
return order
|
||||
|
||||
def get_price(self, symbol: str) -> float | None:
|
||||
"""Get current market price."""
|
||||
@@ -182,20 +187,20 @@ class SpotExecutor:
|
||||
"symbol": symbol, "amount": amount, "stopPrice": stop_price}
|
||||
|
||||
try:
|
||||
# Bybit spot stop-loss: trigger at stop_price, sell at market
|
||||
# Bybit spot: use tpslOrder instead of StopOrder (triggerDirection not supported)
|
||||
order = self.exchange.create_order(
|
||||
symbol, "market", "sell", amount,
|
||||
params={
|
||||
"triggerPrice": str(stop_price),
|
||||
"triggerDirection": 2, # 2 = triggered when price falls below
|
||||
"orderFilter": "StopOrder",
|
||||
"orderFilter": "tpslOrder",
|
||||
"slOrderType": "Market",
|
||||
},
|
||||
)
|
||||
log.info(f"SAFETY STOP placed: {amount} {coin} trigger=${stop_price:,.2f} "
|
||||
f"order={order.get('id')}")
|
||||
return order
|
||||
except Exception as e:
|
||||
log.error(f"SAFETY STOP {symbol} FAILED: {e}")
|
||||
log.warning(f"SAFETY STOP {symbol} not supported on spot: {e}")
|
||||
return None
|
||||
|
||||
def cancel_order(self, symbol: str, order_id: str) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user