@@ -393,28 +393,68 @@ def update_limit_execution(self, order_id: str, execution_price: float,
393393 self .logger .error (f"â Erreur update LIMIT: { e } " )
394394
395395 def get_order_commissions_from_binance (self , binance_client , symbol : str , order_id : str ) -> tuple :
396- """RécupÚre les commissions réelles depuis Binance"""
396+ """RĂ©cupĂšre les commissions rĂ©elles depuis Binance - VERSION CORRIGĂE """
397397 try :
398- order_details = binance_client ._make_request_with_retry (
399- binance_client .client .get_order ,
400- symbol = symbol ,
401- orderId = int (order_id )
402- )
398+ # 1. ESSAYER D'ABORD get_order (pour les ordres récents)
399+ try :
400+ order_details = binance_client ._make_request_with_retry (
401+ binance_client .client .get_order ,
402+ symbol = symbol ,
403+ orderId = int (order_id )
404+ )
405+
406+ if 'fills' in order_details and order_details ['fills' ]:
407+ total_commission = 0.0
408+ commission_asset = 'USDC'
409+
410+ for fill in order_details ['fills' ]:
411+ fill_commission = float (fill .get ('commission' , 0.0 ))
412+ fill_asset = fill .get ('commissionAsset' , 'USDC' )
413+
414+ # Simple : garder la commission dans son asset original
415+ total_commission += fill_commission
416+ commission_asset = fill_asset
417+
418+ if total_commission > 0 :
419+ self .logger .debug (f"â
Commissions via get_order: { total_commission } { commission_asset } " )
420+ return total_commission , commission_asset
421+ else :
422+ self .logger .debug (f"â ïž get_order: fills prĂ©sents mais commissions = 0" )
423+ else :
424+ self .logger .debug (f"â ïž get_order: pas de fills, essai get_my_trades" )
403425
404- if 'fills' in order_details and order_details ['fills' ]:
405- total_commission = 0.0
406- commission_asset = 'USDC'
407-
408- for fill in order_details ['fills' ]:
409- fill_commission = float (fill .get ('commission' , 0.0 ))
410- fill_asset = fill .get ('commissionAsset' , 'USDC' )
426+ except Exception as order_error :
427+ self .logger .debug (f"â ïž get_order Ă©chouĂ©: { order_error } " )
428+
429+ # 2. đ„ FALLBACK: get_my_trades (pour ordres anciens ou sans fills)
430+ try :
431+ trades = binance_client ._make_request_with_retry (
432+ binance_client .client .get_my_trades ,
433+ symbol = symbol ,
434+ orderId = int (order_id )
435+ )
436+
437+ if trades :
438+ total_commission = 0.0
439+ commission_asset = 'USDC'
411440
412- # Simple : garder la commission dans son asset original
413- total_commission += fill_commission
414- commission_asset = fill_asset
415-
416- return total_commission , commission_asset
441+ for trade in trades :
442+ trade_commission = float (trade .get ('commission' , 0.0 ))
443+ trade_asset = trade .get ('commissionAsset' , 'USDC' )
444+
445+ total_commission += trade_commission
446+ commission_asset = trade_asset # Garde le dernier
447+
448+ self .logger .debug (f"â
Commissions via get_my_trades: { total_commission } { commission_asset } " )
449+ return total_commission , commission_asset
450+ else :
451+ self .logger .warning (f"â ïž Aucun trade trouvĂ© pour ordre { order_id } " )
452+
453+ except Exception as trades_error :
454+ self .logger .warning (f"â ïž get_my_trades Ă©chouĂ©: { trades_error } " )
417455
456+ # 3. FALLBACK FINAL: Estimation
457+ self .logger .warning (f"â ïž Impossible de rĂ©cupĂ©rer commissions, utilisation estimation" )
418458 return 0.0 , 'USDC'
419459
420460 except Exception as e :
0 commit comments