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