Skip to content

Commit

Permalink
Fix and improve process_maybe_execute_sells()
Browse files Browse the repository at this point in the history
  • Loading branch information
hroff-1902 committed Oct 2, 2019
1 parent 15aae8a commit 89729ae
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions freqtrade/freqtradebot.py
Expand Up @@ -446,25 +446,26 @@ def process_maybe_execute_sells(self, trades: List[Any]) -> None:
"""
Tries to execute sell trades in a safe way
"""
result = False
for trade in trades:
try:
self.update_trade_state(trade)

if trade.is_open:
result = False
if self.strategy.order_types.get('stoploss_on_exchange'):
result = self.handle_stoploss_on_exchange(trade)
elif trade.open_order_id is None:
# Check if we can sell our current pair
result = self.handle_trade(trade)

# Updating wallets if any trade occured
if result:
self.wallets.update()
if (self.strategy.order_types.get('stoploss_on_exchange') and
self.handle_stoploss_on_exchange(trade)):
result = True
continue
# Check if we can sell our current pair
if trade.open_order_id is None and self.handle_trade(trade):
result = True

except DependencyException as exception:
logger.warning('Unable to sell trade: %s', exception)

# Updating wallets if any trade occured
if result:
self.wallets.update()

def get_real_amount(self, trade: Trade, order: Dict) -> float:
"""
Get real amount for the trade
Expand Down Expand Up @@ -569,7 +570,7 @@ def handle_trade(self, trade: Trade) -> bool:
:return: True if trade has been sold, False otherwise
"""
if not trade.is_open:
raise ValueError(f'Attempt to handle closed trade: {trade}')
raise DependencyException(f'Attempt to handle closed trade: {trade}')

logger.debug('Handling %s ...', trade)

Expand Down

0 comments on commit 89729ae

Please sign in to comment.