@@ -483,17 +483,22 @@ async def _sell_everything(self, symbol, inverted, timeout=None):
483
483
quantity = 0
484
484
else :
485
485
quantity = current_symbol_holding
486
- for order_quantity , order_price in decimal_order_adapter .decimal_check_and_adapt_order_details_if_necessary (
487
- quantity , price ,
488
- symbol_market ):
489
- current_order = order_factory .create_order_instance (trader = self ,
490
- order_type = order_type ,
491
- symbol = symbol ,
492
- current_price = order_price ,
493
- quantity = order_quantity ,
494
- price = order_price )
495
- created_orders .append (
496
- await self .create_order (current_order ))
486
+ try :
487
+ for order_quantity , order_price in decimal_order_adapter .decimal_check_and_adapt_order_details_if_necessary (
488
+ quantity , price ,
489
+ symbol_market ):
490
+ current_order = order_factory .create_order_instance (trader = self ,
491
+ order_type = order_type ,
492
+ symbol = symbol ,
493
+ current_price = order_price ,
494
+ quantity = order_quantity ,
495
+ price = order_price )
496
+ created_orders .append (
497
+ await self .create_order (current_order ))
498
+ except errors .MinimumOrderCostNotReachedError as error :
499
+ self .logger .exception (
500
+ error , True ,
501
+ f"Failed to sell everything - error: { error } " )
497
502
return created_orders
498
503
499
504
async def sell_all (self , currencies_to_sell = None , timeout = None ):
@@ -553,35 +558,42 @@ async def close_position(self, position, limit_price=None, timeout=1, emit_tradi
553
558
_ , _ , _ , price , symbol_market = await order_util .get_pre_order_data (self .exchange_manager ,
554
559
position .symbol ,
555
560
timeout = timeout )
556
- for order_quantity , order_price in decimal_order_adapter .decimal_check_and_adapt_order_details_if_necessary (
557
- position .get_quantity_to_close ().copy_abs (), price , symbol_market ):
558
-
559
- if limit_price is not None :
560
- order_type = enums .TraderOrderType .SELL_LIMIT \
561
- if position .is_long () else enums .TraderOrderType .BUY_LIMIT
562
- else :
563
- order_type = enums .TraderOrderType .SELL_MARKET \
564
- if position .is_long () else enums .TraderOrderType .BUY_MARKET
565
-
566
- current_order = order_factory .create_order_instance (trader = self ,
567
- order_type = order_type ,
568
- symbol = position .symbol ,
569
- current_price = order_price ,
570
- quantity = order_quantity ,
571
- price = limit_price
572
- if limit_price is not None else order_price ,
573
- reduce_only = True ,
574
- close_position = True )
575
- async with signals .remote_signal_publisher (self .exchange_manager , current_order .symbol ,
576
- emit_trading_signals ):
577
- order = await signals .create_order (
578
- self .exchange_manager ,
579
- emit_trading_signals and signals .should_emit_trading_signal (self .exchange_manager ),
580
- current_order ,
581
- wait_for_creation = wait_for_creation ,
582
- creation_timeout = creation_timeout
583
- )
584
- created_orders .append (order )
561
+ try :
562
+ for order_quantity , order_price in decimal_order_adapter .decimal_check_and_adapt_order_details_if_necessary (
563
+ position .get_quantity_to_close ().copy_abs (), price , symbol_market ):
564
+
565
+ if limit_price is not None :
566
+ order_type = enums .TraderOrderType .SELL_LIMIT \
567
+ if position .is_long () else enums .TraderOrderType .BUY_LIMIT
568
+ else :
569
+ order_type = enums .TraderOrderType .SELL_MARKET \
570
+ if position .is_long () else enums .TraderOrderType .BUY_MARKET
571
+
572
+ current_order = order_factory .create_order_instance (trader = self ,
573
+ order_type = order_type ,
574
+ symbol = position .symbol ,
575
+ current_price = order_price ,
576
+ quantity = order_quantity ,
577
+ price = limit_price
578
+ if limit_price is not None else order_price ,
579
+ reduce_only = True ,
580
+ close_position = True )
581
+ async with signals .remote_signal_publisher (self .exchange_manager , current_order .symbol ,
582
+ emit_trading_signals ):
583
+ order = await signals .create_order (
584
+ self .exchange_manager ,
585
+ emit_trading_signals and signals .should_emit_trading_signal (self .exchange_manager ),
586
+ current_order ,
587
+ wait_for_creation = wait_for_creation ,
588
+ creation_timeout = creation_timeout
589
+ )
590
+ created_orders .append (order )
591
+ except errors .MinimumOrderCostNotReachedError as error :
592
+ # this error should never happen as you are
593
+ # able to always close a position
594
+ self .logger .exception (
595
+ error , True ,
596
+ f"Failed close position - error: { error } " )
585
597
return created_orders
586
598
587
599
async def withdraw (self , amount , currency ):
0 commit comments