# Buggy code
def check_exchange(config: Dict[str, Any], check_for_bad: bool = True) -> bool:
    """
    Check if the exchange name in the config file is supported by Freqtrade
    :param check_for_bad: if True, check the exchange against the list of known 'bad'
                          exchanges
    :return: False if exchange is 'bad', i.e. is known to work with the bot with
             critical issues or does not work at all, crashes, etc. True otherwise.
             raises an exception if the exchange if not supported by ccxt
             and thus is not known for the Freqtrade at all.
    """

    if config["runmode"] in [RunMode.PLOT] and not config.get("exchange", {}).get(
        "name"
    ):
        # Skip checking exchange in plot mode, since it requires no exchange
        return True
    logger.info("Checking exchange...")

    exchange = config.get("exchange", {}).get("name").lower()
    if not is_exchange_available(exchange):
        raise OperationalException(
            f'Exchange "{exchange}" is not supported by ccxt '
            f"and therefore not available for the bot.\n"
            f"The following exchanges are supported by ccxt: "
            f"{', '.join(available_exchanges())}"
        )

    if check_for_bad and is_exchange_bad(exchange):
        raise OperationalException(
            f'Exchange "{exchange}" is known to not work with the bot yet. '
            f"Reason: {get_exchange_bad_reason(exchange)}"
        )

    if is_exchange_officially_supported(exchange):
        logger.info(
            f'Exchange "{exchange}" is officially supported '
            f"by the Freqtrade development team."
        )
    else:
        logger.warning(
            f'Exchange "{exchange}" is supported by ccxt '
            f"and therefore available for the bot but not officially supported "
            f"by the Freqtrade development team. "
            f"It may work flawlessly (please report back) or have serious issues. "
            f"Use it at your own discretion."
        )

    return True


# Traceback (KeyError)
(.env) user@nuc:~/freqtrade-wrk/github-hroff-1902/freqtrade$ freqtrade download-data --exchange bittrex
2019-09-06 01:00:15,176 - freqtrade.loggers - INFO - Verbosity set to 0
2019-09-06 01:00:15,177 - freqtrade.configuration.configuration - INFO - Dry run is enabled
2019-09-06 01:00:15,177 - freqtrade.configuration.configuration - INFO - Using DB: "sqlite://"
2019-09-06 01:00:15,177 - freqtrade.configuration.configuration - INFO - Using max_open_trades: None ...
2019-09-06 01:00:15,177 - freqtrade.configuration.configuration - INFO - Using exchange bittrex
2019-09-06 01:00:15,178 - freqtrade.configuration.configuration - INFO - Using user-data directory: /home/user/freqtrade-wrk/github-hroff-1902/freqtrade/user_data ...
2019-09-06 01:00:15,178 - freqtrade.configuration.configuration - INFO - Using data directory: /home/user/freqtrade-wrk/github-hroff-1902/freqtrade/user_data/data/bittrex ...
2019-09-06 01:00:15,178 - freqtrade.configuration.configuration - INFO - timeframes --timeframes: ['1m', '5m']
2019-09-06 01:00:15,178 - freqtrade.configuration.check_exchange - INFO - Checking exchange...
2019-09-06 01:00:15,178 - freqtrade.configuration.check_exchange - INFO - Exchange "bittrex" is officially supported by the Freqtrade development team.
2019-09-06 01:00:15,179 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/home/user/freqtrade-wrk/github-hroff-1902/freqtrade/freqtrade/main.py", line 40, in main
args.func(args)
File "/home/user/freqtrade-wrk/github-hroff-1902/freqtrade/freqtrade/utils.py", line 75, in start_download_data
logger.info(f'About to download pairs: {config["pairs"]}, '
KeyError: 'pairs'

# Fixed code
def check_exchange(config: Dict[str, Any], check_for_bad: bool = True) -> bool:
    """
    Check if the exchange name in the config file is supported by Freqtrade
    :param check_for_bad: if True, check the exchange against the list of known 'bad'
                          exchanges
    :return: False if exchange is 'bad', i.e. is known to work with the bot with
             critical issues or does not work at all, crashes, etc. True otherwise.
             raises an exception if the exchange if not supported by ccxt
             and thus is not known for the Freqtrade at all.
    """

    if config["runmode"] in [RunMode.PLOT] and not config.get("exchange", {}).get(
        "name"
    ):
        # Skip checking exchange in plot mode, since it requires no exchange
        return True
    logger.info("Checking exchange...")

    exchange = config.get("exchange", {}).get("name").lower()
    if not exchange:
        raise OperationalException(
            f"This command requires a configured exchange. You should either use "
            f"`--exchange <exchange_name>` or specify a configuration file via `--config`.\n"
            f"The following exchanges are supported by ccxt: "
            f"{', '.join(available_exchanges())}"
        )

    if not is_exchange_available(exchange):
        raise OperationalException(
            f'Exchange "{exchange}" is not supported by ccxt '
            f"and therefore not available for the bot.\n"
            f"The following exchanges are supported by ccxt: "
            f"{', '.join(available_exchanges())}"
        )

    if check_for_bad and is_exchange_bad(exchange):
        raise OperationalException(
            f'Exchange "{exchange}" is known to not work with the bot yet. '
            f"Reason: {get_exchange_bad_reason(exchange)}"
        )

    if is_exchange_officially_supported(exchange):
        logger.info(
            f'Exchange "{exchange}" is officially supported '
            f"by the Freqtrade development team."
        )
    else:
        logger.warning(
            f'Exchange "{exchange}" is supported by ccxt '
            f"and therefore available for the bot but not officially supported "
            f"by the Freqtrade development team. "
            f"It may work flawlessly (please report back) or have serious issues. "
            f"Use it at your own discretion."
        )

    return True