Skip to content

Commit 908c908

Browse files
author
Franz VETTER
committed
🔧 Fix quantity precision error for OCO orders
🐛 Critical Bug Fix: - Fixed 'Parameter quantity has too much precision' error (-1111) - OCO orders failing on symbols with specific precision requirements - ADA and other cryptos could not create OCO orders 🔧 Technical Problem: - sell_quantity formatted with step_size alignment but wrong decimal precision - Example: 40.90000000 ADA sent instead of 40.90 (ADA requires 2 decimals) - Binance rejects orders with excessive decimal places 📊 Impact: - OCO orders completely broken for precision-sensitive symbols - Fallback to LIMIT orders (no stop-loss protection) - ADA, DOGE and potentially other cryptos affected ✅ Solution: - Calculate quantity precision from step_size: qty_precision = -log10(step_size) - Apply proper rounding: round(quantity, qty_precision) - Added debug logging for precision verification - Consistent formatting across all symbols 🎯 All symbols now create OCO orders with correct quantity precision
1 parent 461632c commit 908c908

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/trading_engine.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,13 +476,24 @@ def execute_sell_order_with_stop_loss(self, symbol: str, bought_quantity: float,
476476
tick_size = float(next(f for f in symbol_info['filters'] if f['filterType'] == 'PRICE_FILTER')['tickSize'])
477477
step_size = float(next(f for f in symbol_info['filters'] if f['filterType'] == 'LOT_SIZE')['stepSize'])
478478

479-
# Formatage précis
479+
# Formatage précis avec gestion complète des précisions
480480
price_precision = max(0, -int(np.log10(tick_size)))
481+
qty_precision = max(0, -int(np.log10(step_size)))
482+
483+
# Prix formatés
481484
target_price = round(target_price / tick_size) * tick_size
482-
stop_price = round(stop_price / tick_size) * tick_size
485+
stop_price = round(stop_price / tick_size) * tick_size
483486
stop_limit_price = round(stop_limit_price / tick_size) * tick_size
484-
487+
488+
# 🔧 CORRECTION: Quantité formatée avec précision exacte
485489
sell_quantity = round(sell_quantity / step_size) * step_size
490+
sell_quantity = round(sell_quantity, qty_precision)
491+
492+
# Debug pour vérification
493+
self.logger.debug(f"🔧 Formatage {symbol}:")
494+
self.logger.debug(f" Tick size: {tick_size} -> Prix précision: {price_precision}")
495+
self.logger.debug(f" Step size: {step_size} -> Qty précision: {qty_precision}")
496+
self.logger.debug(f" Quantité finale: {sell_quantity:.{qty_precision}f}")
486497

487498
self.logger.info(f"🔄 Future transfer: {'Activé' if future_transfer_enabled else 'Désactivé'}")
488499
if future_transfer_enabled:

0 commit comments

Comments
 (0)