# Buggy code
def __init__(self, config: Dict[str, Any]) -> None:
    """
    Init all variables and objects the bot needs to work
    :param config: configuration dict, you can use Configuration.get_config()
    to get the config dict.
    """

    logger.info("Starting freqtrade %s", __version__)

    # Init bot state
    self.state = State.STOPPED

    # Init objects
    self.config = config

    self.strategy: IStrategy = StrategyResolver(self.config).strategy

    # Check config consistency here since strategies can set certain options
    validate_config_consistency(config)

    self.rpc: RPCManager = RPCManager(self)

    self.exchange = ExchangeResolver(
        self.config["exchange"]["name"], self.config
    ).exchange

    self.wallets = Wallets(self.config, self.exchange)
    self.dataprovider = DataProvider(self.config, self.exchange)

    # Attach Dataprovider to Strategy baseclass
    IStrategy.dp = self.dataprovider
    # Attach Wallets to Strategy baseclass
    IStrategy.wallets = self.wallets

    pairlistname = self.config.get("pairlist", {}).get("method", "StaticPairList")
    self.pairlists = PairListResolver(pairlistname, self, self.config).pairlist

    # Initializing Edge only if enabled
    self.edge = (
        Edge(self.config, self.exchange, self.strategy)
        if self.config.get("edge", {}).get("enabled", False)
        else None
    )

    self.active_pair_whitelist: List[str] = self.config["exchange"]["pair_whitelist"]

    persistence.init(
        self.config.get("db_url", None),
        clean_open_orders=self.config.get("dry_run", False),
    )

    # Stoploss on exchange does not make sense, therefore we need to disable that.
    if self.dataprovider.runmode == RunMode.DRY_RUN and self.strategy.order_types.get(
        "stoploss_on_exchange", False
    ):
        logger.info("Disabling stoploss_on_exchange during dry-run.")
        self.strategy.order_types["stoploss_on_exchange"] = False
        config["order_types"]["stoploss_on_exchange"] = False
    # Set initial bot state from config
    initial_state = self.config.get("initial_state")
    self.state = State[initial_state.upper()] if initial_state else State.STOPPED


# Traceback (KeyError)
2019-08-06 22:44:55,366 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-06 22:44:59,196 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-06 22:45:05,099 - freqtrade.freqtradebot - INFO - Buy signal found: about create a new trade with stake_amount: 980 ...
2019-08-06 22:45:05,099 - freqtrade.freqtradebot - INFO - Using Last Ask / Last Price
2019-08-06 22:45:05,400 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': buy, 'exchange': 'Binance', 'pair': 'BTC/USDT', 'limit': 11642.115000000002, 'order_type': 'limit', 'stake_amount': 980, 'stake_currency': 'USDT', 'fiat_currency': 'USD'}
2019-08-06 22:45:05,928 - freqtrade.wallets - INFO - Wallets synced.
/root/freqtrade/.env/lib/python3.7/site-packages/arrow/factory.py:201: ArrowParseWarning: The .get() parsing method without a format string will parse more strictly in version 0.15.0.See https://github.com/crsmithdev/arrow/issues/612 for more details.
ArrowParseWarning,
2019-08-06 22:45:05,986 - freqtrade.wallets - INFO - Wallets synced.
2019-08-06 22:45:07,044 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=1, pair=BTC/USDT, amount=0.08417714, open_rate=11642.11500000, open_since=just now)
2019-08-06 22:45:07,045 - freqtrade.freqtradebot - INFO - Applying fee on amount for Trade(id=1, pair=BTC/USDT, amount=0.08417714, open_rate=11642.11500000, open_since=just now) failed: myTrade-Dict empty found
2019-08-06 22:45:07,046 - freqtrade.persistence - INFO - Updating trade (id=1) ...
2019-08-06 22:45:07,046 - freqtrade.persistence - INFO - LIMIT_BUY has been fulfilled for Trade(id=1, pair=BTC/USDT, amount=0.08417714, open_rate=11642.11500000, open_since=just now).
2019-08-06 22:45:07,632 - freqtrade.freqtradebot - INFO - Found no buy signals for whitelisted currencies. Trying again..
2019-08-06 22:45:11,045 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/root/freqtrade/freqtrade/main.py", line 49, in main
worker.run()
File "/root/freqtrade/freqtrade/worker.py", line 72, in run
state = self._worker(old_state=state)
File "/root/freqtrade/freqtrade/worker.py", line 110, in _worker
self._throttle(func=self._process, min_secs=throttle_secs)
File "/root/freqtrade/freqtrade/worker.py", line 123, in _throttle
result = func(*args, **kwargs)
File "/root/freqtrade/freqtrade/worker.py", line 134, in _process
state_changed = self.freqtrade.process()
File "/root/freqtrade/freqtrade/freqtradebot.py", line 135, in process
state_changed |= self.process_maybe_execute_sell(trade)
File "/root/freqtrade/freqtrade/freqtradebot.py", line 451, in process_maybe_execute_sell
result = self.handle_stoploss_on_exchange(trade)
File "/root/freqtrade/freqtrade/freqtradebot.py", line 683, in handle_stoploss_on_exchange
self.handle_trailing_stoploss_on_exchange(trade, stoploss_order)
File "/root/freqtrade/freqtrade/freqtradebot.py", line 696, in handle_trailing_stoploss_on_exchange
if trade.stop_loss > float(order['info']['stopPrice']):
KeyError: 'stopPrice'
2019-08-06 22:45:11,099 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'process died'}
2019-08-06 22:45:11,143 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2019-08-06 22:45:11,143 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
(.env) (base) root@vmanager6003:~/freqtrade#

# Fixed code
def __init__(self, config: Dict[str, Any]) -> None:
    """
    Init all variables and objects the bot needs to work
    :param config: configuration dict, you can use Configuration.get_config()
    to get the config dict.
    """

    logger.info("Starting freqtrade %s", __version__)

    # Init bot state
    self.state = State.STOPPED

    # Init objects
    self.config = config

    self.strategy: IStrategy = StrategyResolver(self.config).strategy

    # Check config consistency here since strategies can set certain options
    validate_config_consistency(config)

    self.rpc: RPCManager = RPCManager(self)

    self.exchange = ExchangeResolver(
        self.config["exchange"]["name"], self.config
    ).exchange

    self.wallets = Wallets(self.config, self.exchange)
    self.dataprovider = DataProvider(self.config, self.exchange)

    # Attach Dataprovider to Strategy baseclass
    IStrategy.dp = self.dataprovider
    # Attach Wallets to Strategy baseclass
    IStrategy.wallets = self.wallets

    pairlistname = self.config.get("pairlist", {}).get("method", "StaticPairList")
    self.pairlists = PairListResolver(pairlistname, self, self.config).pairlist

    # Initializing Edge only if enabled
    self.edge = (
        Edge(self.config, self.exchange, self.strategy)
        if self.config.get("edge", {}).get("enabled", False)
        else None
    )

    self.active_pair_whitelist: List[str] = self.config["exchange"]["pair_whitelist"]

    persistence.init(
        self.config.get("db_url", None),
        clean_open_orders=self.config.get("dry_run", False),
    )

    # Set initial bot state from config
    initial_state = self.config.get("initial_state")
    self.state = State[initial_state.upper()] if initial_state else State.STOPPED