# Buggy code
def handle_trade(self, trade: Trade) -> bool:
    """
    Sells the current pair if the threshold is reached and updates the trade record.
    :return: True if trade has been sold, False otherwise
    """
    if not trade.is_open:
        raise DependencyException(f"Attempt to handle closed trade: {trade}")

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

    (buy, sell) = (False, False)

    config_ask_strategy = self.config.get("ask_strategy", {})

    if config_ask_strategy.get("use_sell_signal", True) or config_ask_strategy.get(
        "ignore_roi_if_buy_signal", False
    ):
        (buy, sell) = self.strategy.get_signal(
            trade.pair,
            self.strategy.ticker_interval,
            self.dataprovider.ohlcv(trade.pair, self.strategy.ticker_interval),
        )

    if config_ask_strategy.get("use_order_book", False):
        logger.debug(f"Using order book for selling {trade.pair}...")
        # logger.debug('Order book %s',orderBook)
        order_book_min = config_ask_strategy.get("order_book_min", 1)
        order_book_max = config_ask_strategy.get("order_book_max", 1)

        order_book = self._order_book_gen(
            trade.pair,
            f"{config_ask_strategy['price_side']}s",
            order_book_min=order_book_min,
            order_book_max=order_book_max,
        )
        for i in range(order_book_min, order_book_max + 1):
            sell_rate = next(order_book)
            logger.debug(
                f"  order book {config_ask_strategy['price_side']} top {i}: "
                f"{sell_rate:0.8f}"
            )

            if self._check_and_execute_sell(trade, sell_rate, buy, sell):
                return True

    else:
        logger.debug("checking sell")
        sell_rate = self.get_sell_rate(trade.pair, True)
        if self._check_and_execute_sell(trade, sell_rate, buy, sell):
            return True

    logger.debug("Found no sell signal for %s.", trade)
    return False


# Traceback (IndexError)
2020-05-23 16:03:03,076 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
worker.run()
File "/freqtrade/freqtrade/worker.py", line 66, in run
state = self._worker(old_state=state)
File "/freqtrade/freqtrade/worker.py", line 104, in _worker
self._throttle(func=self._process_running, throttle_secs=self._throttle_secs)
File "/freqtrade/freqtrade/worker.py", line 125, in _throttle
result = func(*args, **kwargs)
File "/freqtrade/freqtrade/worker.py", line 139, in _process_running
self.freqtrade.process()
File "/freqtrade/freqtrade/freqtradebot.py", line 157, in process
self.exit_positions(trades)
File "/freqtrade/freqtrade/freqtradebot.py", line 613, in exit_positions
if trade.open_order_id is None and self.handle_trade(trade):
File "/freqtrade/freqtrade/freqtradebot.py", line 694, in handle_trade
sell_rate = next(order_book)
File "/freqtrade/freqtrade/freqtradebot.py", line 632, in _order_book_gen
yield order_book[side][i - 1][0]
IndexError: list index out of range
2020-05-23 16:03:13,989 - freqtrade.loggers - INFO - Verbosity set to 0

# Fixed code
def handle_trade(self, trade: Trade) -> bool:
    """
    Sells the current pair if the threshold is reached and updates the trade record.
    :return: True if trade has been sold, False otherwise
    """
    if not trade.is_open:
        raise DependencyException(f"Attempt to handle closed trade: {trade}")

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

    (buy, sell) = (False, False)

    config_ask_strategy = self.config.get("ask_strategy", {})

    if config_ask_strategy.get("use_sell_signal", True) or config_ask_strategy.get(
        "ignore_roi_if_buy_signal", False
    ):
        (buy, sell) = self.strategy.get_signal(
            trade.pair,
            self.strategy.ticker_interval,
            self.dataprovider.ohlcv(trade.pair, self.strategy.ticker_interval),
        )

    if config_ask_strategy.get("use_order_book", False):
        # logger.debug('Order book %s',orderBook)
        order_book_min = config_ask_strategy.get("order_book_min", 1)
        order_book_max = config_ask_strategy.get("order_book_max", 1)
        logger.info(
            f"Using order book between {order_book_min} and {order_book_max} "
            f"for selling {trade.pair}..."
        )

        order_book = self._order_book_gen(
            trade.pair,
            f"{config_ask_strategy['price_side']}s",
            order_book_min=order_book_min,
            order_book_max=order_book_max,
        )
        for i in range(order_book_min, order_book_max + 1):
            try:
                sell_rate = next(order_book)
            except (IndexError, KeyError) as e:
                logger.warning(
                    f"Sell Price at location {i} from orderbook could not be determined."
                )
                raise PricingError from e
            logger.debug(
                f"  order book {config_ask_strategy['price_side']} top {i}: "
                f"{sell_rate:0.8f}"
            )

            if self._check_and_execute_sell(trade, sell_rate, buy, sell):
                return True

    else:
        logger.debug("checking sell")
        sell_rate = self.get_sell_rate(trade.pair, True)
        if self._check_and_execute_sell(trade, sell_rate, buy, sell):
            return True

    logger.debug("Found no sell signal for %s.", trade)
    return False