# Buggy code
def get_buy_rate(self, pair: str, refresh: bool) -> float:
    """
    Calculates bid target between current ask price and last price
    :param pair: Pair to get rate for
    :param refresh: allow cached data
    :return: float: Price
    """
    if not refresh:
        rate = self._buy_rate_cache.get(pair)
        # Check if cache has been invalidated
        if rate:
            logger.info(f"Using cached buy rate for {pair}.")
            return rate

    bid_strategy = self.config.get("bid_strategy", {})
    if "use_order_book" in bid_strategy and bid_strategy.get("use_order_book", False):
        logger.info(
            f"Getting price from order book {bid_strategy['price_side'].capitalize()} side."
        )
        order_book_top = bid_strategy.get("order_book_top", 1)
        order_book = self.exchange.get_order_book(pair, order_book_top)
        logger.debug("order_book %s", order_book)
        # top 1 = index 0
        order_book_rate = order_book[f"{bid_strategy['price_side']}s"][
            order_book_top - 1
        ][0]
        logger.info(
            f"...top {order_book_top} order book buy rate {order_book_rate:.8f}"
        )
        used_rate = order_book_rate
    else:
        logger.info(
            f"Using Last {bid_strategy['price_side'].capitalize()} / Last Price"
        )
        ticker = self.exchange.fetch_ticker(pair)
        rate = ticker[bid_strategy["price_side"]]
        if rate < ticker["last"]:
            ticker_rate = rate
        else:
            balance = self.config["bid_strategy"]["ask_last_balance"]
            ticker_rate = rate + balance * (ticker["last"] - rate)
        used_rate = ticker_rate

    self._buy_rate_cache[pair] = used_rate

    return used_rate


# Traceback (TypeError)
2020-03-01 01:17:28,780 - freqtrade.wallets - INFO - Wallets synced.
2020-03-01 01:17:28,782 - freqtrade.freqtradebot - INFO - Buy signal found: about create a new trade with stake_amount: 108 ...
2020-03-01 01:17:28,782 - freqtrade.freqtradebot - INFO - Executing Buy for DOGEHEDGE/USD
2020-03-01 01:17:28,782 - freqtrade.freqtradebot - INFO - Using Last Ask / Last Price
2020-03-01 01:17:28,859 - freqtrade.commands.trade_commands - INFO - worker found ... calling exit
2020-03-01 01:17:28,859 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'process died'}
2020-03-01 01:17:29,229 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2020-03-01 01:17:29,229 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
^[[C^[[C2020-03-01 01:17:52,307 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/home/dante/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/home/dante/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
worker.run()
File "/home/dante/freqtrade/freqtrade/worker.py", line 66, in run
state = self._worker(old_state=state)
File "/home/dante/freqtrade/freqtrade/worker.py", line 104, in _worker
self._throttle(func=self._process_running, throttle_secs=self._throttle_secs)
File "/home/dante/freqtrade/freqtrade/worker.py", line 125, in _throttle
result = func(*args, **kwargs)
File "/home/dante/freqtrade/freqtrade/worker.py", line 139, in _process_running
self.freqtrade.process()
File "/home/dante/freqtrade/freqtrade/freqtradebot.py", line 151, in process
self.enter_positions()
File "/home/dante/freqtrade/freqtrade/freqtradebot.py", line 217, in enter_positions
trades_created += self.create_trade(pair)
File "/home/dante/freqtrade/freqtrade/freqtradebot.py", line 413, in create_trade    return self.execute_buy(pair, stake_amount)
File "/home/dante/freqtrade/freqtrade/freqtradebot.py", line 453, in execute_buy
buy_limit_requested = self.get_buy_rate(pair, True)
File "/home/dante/freqtrade/freqtrade/freqtradebot.py", line 249, in get_buy_rate    if ticker['ask'] < ticker['last']:
TypeError: '<' not supported between instances of 'float' and 'NoneType'

# Fixed code
def get_buy_rate(self, pair: str, refresh: bool) -> float:
    """
    Calculates bid target between current ask price and last price
    :param pair: Pair to get rate for
    :param refresh: allow cached data
    :return: float: Price
    """
    if not refresh:
        rate = self._buy_rate_cache.get(pair)
        # Check if cache has been invalidated
        if rate:
            logger.info(f"Using cached buy rate for {pair}.")
            return rate

    bid_strategy = self.config.get("bid_strategy", {})
    if "use_order_book" in bid_strategy and bid_strategy.get("use_order_book", False):
        logger.info(
            f"Getting price from order book {bid_strategy['price_side'].capitalize()} side."
        )
        order_book_top = bid_strategy.get("order_book_top", 1)
        order_book = self.exchange.get_order_book(pair, order_book_top)
        logger.debug("order_book %s", order_book)
        # top 1 = index 0
        order_book_rate = order_book[f"{bid_strategy['price_side']}s"][
            order_book_top - 1
        ][0]
        logger.info(
            f"...top {order_book_top} order book buy rate {order_book_rate:.8f}"
        )
        used_rate = order_book_rate
    else:
        logger.info(
            f"Using Last {bid_strategy['price_side'].capitalize()} / Last Price"
        )
        ticker = self.exchange.fetch_ticker(pair)
        ticker_rate = ticker[bid_strategy["price_side"]]
        if ticker["last"] and ticker_rate > ticker["last"]:
            balance = self.config["bid_strategy"]["ask_last_balance"]
            ticker_rate = ticker_rate + balance * (ticker["last"] - ticker_rate)
        used_rate = ticker_rate

    self._buy_rate_cache[pair] = used_rate

    return used_rate