# Buggy code
def handle_timedout_limit_buy(self, trade: Trade, order: Dict) -> bool:
    """
    Buy timeout - cancel order
    :return: True if order was fully cancelled
    """
    if order["status"] != "canceled":
        reason = "cancelled due to timeout"
        corder = self.exchange.cancel_order(trade.open_order_id, trade.pair)
        logger.info("Buy order %s for %s.", reason, trade)
    else:
        # Order was cancelled already, so we can reuse the existing dict
        corder = order
        reason = "cancelled on exchange"
        logger.info("Buy order %s for %s.", reason, trade)

    if corder.get("remaining", order["remaining"]) == order["amount"]:
        # if trade is not partially completed, just delete the trade
        Trade.session.delete(trade)
        Trade.session.flush()
        return True

    # if trade is partially complete, edit the stake details for the trade
    # and close the order
    # cancel_order may not contain the full order dict, so we need to fallback
    # to the order dict aquired before cancelling.
    # we need to fall back to the values from order if corder does not contain these keys.
    trade.amount = order["amount"] - corder.get("remaining", order["remaining"])
    trade.stake_amount = trade.amount * trade.open_rate
    # verify if fees were taken from amount to avoid problems during selling
    try:
        new_amount = self.get_real_amount(
            trade, corder if "fee" in corder else order, trade.amount
        )
        if not isclose(order["amount"], new_amount, abs_tol=constants.MATH_CLOSE_PREC):
            trade.amount = new_amount
            # Fee was applied, so set to 0
            trade.fee_open = 0
            trade.recalc_open_trade_price()
    except DependencyException as e:
        logger.warning("Could not update trade amount: %s", e)

    trade.open_order_id = None
    logger.info("Partial buy order timeout for %s.", trade)
    self.rpc.send_msg(
        {
            "type": RPCMessageType.STATUS_NOTIFICATION,
            "status": f"Remaining buy order for {trade.pair} cancelled due to timeout",
        }
    )
    return False


# Traceback (AttributeError)
2020-03-19 10:40:19,048 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=3, pair=EOSBEAR/USD, amount=0.17200000, open_rate=58.07500000, open_since=2020-03-19 09:30:17)
2020-03-19 10:40:19,331 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=4, pair=XRPBEAR/USD, amount=0.00830000, open_rate=1196.00000000, open_since=2020-03-19 09:30:19)
2020-03-19 10:40:19,616 - freqtrade.freqtradebot - INFO - Found open order for Trade(id=5, pair=BNBBEAR/USD, amount=0.06620324, open_rate=151.05000000, open_since=2020-03-19 09:30:20)
2020-03-19 10:40:20,216 - freqtrade.freqtradebot - INFO - Pair BEAR/USD is currently locked.
2020-03-19 10:40:20,216 - freqtrade.freqtradebot - INFO - Pair ETHBEAR/USD is currently locked.
2020-03-19 10:40:22,234 - freqtrade.freqtradebot - INFO - Buy order cancelled due to timeout for Trade(id=5, pair=BNBBEAR/USD, amount=0.06620324, open_rate=151.05000000, open_since=2020-03-19 09:30:20).
2020-03-19 10:40:22,235 - freqtrade.commands.trade_commands - INFO - worker found ... calling exit
2020-03-19 10:40:22,235 - freqtrade.rpc.rpc_manager - INFO - Sending rpc message: {'type': status, 'status': 'process died'}
2020-03-19 10:40:22,278 - freqtrade.freqtradebot - INFO - Cleaning up modules ...
2020-03-19 10:40:22,279 - freqtrade.rpc.rpc_manager - INFO - Cleaning up rpc modules ...
2020-03-19 10:40:39,202 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/root/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/root/freqtrade/freqtrade/commands/trade_commands.py", line 20, in start_trading
worker.run()
File "/root/freqtrade/freqtrade/worker.py", line 66, in run
state = self._worker(old_state=state)
File "/root/freqtrade/freqtrade/worker.py", line 104, in _worker
self._throttle(func=self._process_running, throttle_secs=self._throttle_secs)
File "/root/freqtrade/freqtrade/worker.py", line 125, in _throttle
result = func(*args, **kwargs)
File "/root/freqtrade/freqtrade/worker.py", line 139, in _process_running
self.freqtrade.process()
File "/root/freqtrade/freqtrade/freqtradebot.py", line 158, in process
self.check_handle_timedout()
File "/root/freqtrade/freqtrade/freqtradebot.py", line 874, in check_handle_timedout
self.handle_timedout_limit_buy(trade, order)
File "/root/freqtrade/freqtrade/freqtradebot.py", line 901, in handle_timedout_limit_buy
if corder.get('remaining', order['remaining']) == order['amount']:
AttributeError: 'str' object has no attribute 'get'
2020-03-19 10:40:42,122 - freqtrade.loggers - INFO - Verbosity set to 0
2020-03-19 10:40:42,123 - freqtrade.configuration.configuration - INFO - Runmode set to live.

# Fixed code
def handle_timedout_limit_buy(self, trade: Trade, order: Dict) -> bool:
    """
    Buy timeout - cancel order
    :return: True if order was fully cancelled
    """
    if order["status"] != "canceled":
        reason = "cancelled due to timeout"
        corder = self.exchange.cancel_order(trade.open_order_id, trade.pair)
        # Some exchanges don't return a dict here.
        if not isinstance(corder, dict):
            corder = {}
        logger.info("Buy order %s for %s.", reason, trade)
    else:
        # Order was cancelled already, so we can reuse the existing dict
        corder = order
        reason = "cancelled on exchange"
        logger.info("Buy order %s for %s.", reason, trade)

    if corder.get("remaining", order["remaining"]) == order["amount"]:
        # if trade is not partially completed, just delete the trade
        Trade.session.delete(trade)
        Trade.session.flush()
        return True

    # if trade is partially complete, edit the stake details for the trade
    # and close the order
    # cancel_order may not contain the full order dict, so we need to fallback
    # to the order dict aquired before cancelling.
    # we need to fall back to the values from order if corder does not contain these keys.
    trade.amount = order["amount"] - corder.get("remaining", order["remaining"])
    trade.stake_amount = trade.amount * trade.open_rate
    # verify if fees were taken from amount to avoid problems during selling
    try:
        new_amount = self.get_real_amount(
            trade, corder if "fee" in corder else order, trade.amount
        )
        if not isclose(order["amount"], new_amount, abs_tol=constants.MATH_CLOSE_PREC):
            trade.amount = new_amount
            # Fee was applied, so set to 0
            trade.fee_open = 0
            trade.recalc_open_trade_price()
    except DependencyException as e:
        logger.warning("Could not update trade amount: %s", e)

    trade.open_order_id = None
    logger.info("Partial buy order timeout for %s.", trade)
    self.rpc.send_msg(
        {
            "type": RPCMessageType.STATUS_NOTIFICATION,
            "status": f"Remaining buy order for {trade.pair} cancelled due to timeout",
        }
    )
    return False