# Buggy code
def _check_depth_of_market_buy(self, pair: str, conf: Dict) -> bool:
    """
    Checks depth of market before executing a buy
    """
    conf_bids_to_ask_delta = conf.get("bids_to_ask_delta", 0)
    logger.info(f"Checking depth of market for {pair} ...")
    order_book = self.exchange.get_order_book(pair, 1000)
    order_book_data_frame = order_book_to_dataframe(
        order_book["bids"], order_book["asks"]
    )
    order_book_bids = order_book_data_frame["b_size"].sum()
    order_book_asks = order_book_data_frame["a_size"].sum()
    bids_ask_delta = order_book_bids / order_book_asks
    logger.info(
        f"Bids: {order_book_bids}, Asks: {order_book_asks}, Delta: {bids_ask_delta}, "
        f"Bid Price: {order_book['bids'][0][0]}, Ask Price: {order_book['asks'][0][0]}, "
        f"Immediate Bid Quantity: {order_book['bids'][0][1]}, "
        f"Immediate Ask Quantity: {order_book['asks'][0][1]}."
    )
    if bids_ask_delta >= conf_bids_to_ask_delta:
        logger.info(f"Bids to asks delta for {pair} DOES satisfy condition.")
        return True
    else:
        logger.info(f"Bids to asks delta for {pair} does not satisfy condition.")
        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 _check_depth_of_market_buy(self, pair: str, conf: Dict) -> bool:
    """
    Checks depth of market before executing a buy
    """
    conf_bids_to_ask_delta = conf.get("bids_to_ask_delta", 0)
    logger.info(f"Checking depth of market for {pair} ...")
    order_book = self.exchange.fetch_l2_order_book(pair, 1000)
    order_book_data_frame = order_book_to_dataframe(
        order_book["bids"], order_book["asks"]
    )
    order_book_bids = order_book_data_frame["b_size"].sum()
    order_book_asks = order_book_data_frame["a_size"].sum()
    bids_ask_delta = order_book_bids / order_book_asks
    logger.info(
        f"Bids: {order_book_bids}, Asks: {order_book_asks}, Delta: {bids_ask_delta}, "
        f"Bid Price: {order_book['bids'][0][0]}, Ask Price: {order_book['asks'][0][0]}, "
        f"Immediate Bid Quantity: {order_book['bids'][0][1]}, "
        f"Immediate Ask Quantity: {order_book['asks'][0][1]}."
    )
    if bids_ask_delta >= conf_bids_to_ask_delta:
        logger.info(f"Bids to asks delta for {pair} DOES satisfy condition.")
        return True
    else:
        logger.info(f"Bids to asks delta for {pair} does not satisfy condition.")
        return False