# Buggy code
def get_sell_rate(self, pair: str, refresh: bool) -> float:
    """
    Get sell rate - either using ticker bid or first bid based on orderbook
    The orderbook portion is only used for rpc messaging, which would otherwise fail
    for BitMex (has no bid/ask in fetch_ticker)
    or remain static in any other case since it's not updating.
    :param pair: Pair to get rate for
    :param refresh: allow cached data
    :return: Bid rate
    """
    if not refresh:
        rate = self._sell_rate_cache.get(pair)
        # Check if cache has been invalidated
        if rate:
            logger.info(f"Using cached sell rate for {pair}.")
            return rate

    ask_strategy = self.config.get("ask_strategy", {})
    if ask_strategy.get("use_order_book", False):
        # This code is only used for notifications, selling uses the generator directly
        logger.info(
            f"Getting price from order book {ask_strategy['price_side'].capitalize()} side."
        )
        rate = next(self._order_book_gen(pair, f"{ask_strategy['price_side']}s"))

    else:
        rate = self.exchange.fetch_ticker(pair)[ask_strategy["price_side"]]
    self._sell_rate_cache[pair] = rate
    return rate


# 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 get_sell_rate(self, pair: str, refresh: bool) -> float:
    """
    Get sell rate - either using ticker bid or first bid based on orderbook
    The orderbook portion is only used for rpc messaging, which would otherwise fail
    for BitMex (has no bid/ask in fetch_ticker)
    or remain static in any other case since it's not updating.
    :param pair: Pair to get rate for
    :param refresh: allow cached data
    :return: Bid rate
    """
    if not refresh:
        rate = self._sell_rate_cache.get(pair)
        # Check if cache has been invalidated
        if rate:
            logger.info(f"Using cached sell rate for {pair}.")
            return rate

    ask_strategy = self.config.get("ask_strategy", {})
    if ask_strategy.get("use_order_book", False):
        # This code is only used for notifications, selling uses the generator directly
        logger.info(
            f"Getting price from order book {ask_strategy['price_side'].capitalize()} side."
        )
        try:
            rate = next(self._order_book_gen(pair, f"{ask_strategy['price_side']}s"))
        except (IndexError, KeyError) as e:
            logger.warning(
                "Sell Price at location from orderbook could not be determined."
            )
            raise PricingError from e
    else:
        rate = self.exchange.fetch_ticker(pair)[ask_strategy["price_side"]]
    self._sell_rate_cache[pair] = rate
    return rate