# Buggy code
def update(self, order: Dict) -> None:
    """
    Updates this entity with amount and actual open/close rates.
    :param order: order retrieved by exchange.get_order()
    :return: None
    """
    order_type = order["type"]
    # Ignore open and cancelled orders
    if order["status"] == "open" or order["price"] is None:
        return

    logger.info("Updating trade (id=%d) ...", self.id)

    if order_type == "limit" and order["side"] == "buy":
        # Update open rate and actual amount
        self.open_rate = Decimal(order["price"])
        self.amount = Decimal(order["amount"])
        logger.info("LIMIT_BUY has been fulfilled for %s.", self)
        self.open_order_id = None
    elif order_type == "limit" and order["side"] == "sell":
        self.close(order["price"])
    elif order_type == "stop_loss_limit":
        self.stoploss_order_id = None
        logger.info("STOP_LOSS_LIMIT is hit for %s.", self)
        self.close(order["average"])
    else:
        raise ValueError(f"Unknown order type: {order_type}")
    cleanup()


# Traceback (ValueError)
A  2018-12-21 10:27:24,440 - freqtrade.persistence - INFO - Updating trade (id=4) ...

A  2018-12-21 10:27:24,440 - freqtrade - ERROR - Fatal exception!

A  Traceback (most recent call last):

A    File "/freqtrade/freqtrade/main.py", line 49, in main

A      state = freqtrade.worker(old_state=state)

A    File "/freqtrade/freqtrade/freqtradebot.py", line 122, in worker

A      min_secs=min_secs)

A    File "/freqtrade/freqtrade/freqtradebot.py", line 134, in _throttle

A      result = func(*args, **kwargs)

A    File "/freqtrade/freqtrade/freqtradebot.py", line 174, in _process

A      state_changed |= self.process_maybe_execute_sell(trade)

A    File "/freqtrade/freqtrade/freqtradebot.py", line 502, in process_maybe_execute_sell

A      trade.update(order)

A    File "/freqtrade/freqtrade/persistence.py", line 265, in update

A      raise ValueError(f'Unknown order type: {order_type}')

A  ValueError: Unknown order type: market

# Fixed code
def update(self, order: Dict) -> None:
    """
    Updates this entity with amount and actual open/close rates.
    :param order: order retrieved by exchange.get_order()
    :return: None
    """
    order_type = order["type"]
    # Ignore open and cancelled orders
    if order["status"] == "open" or order["price"] is None:
        return

    logger.info("Updating trade (id=%s) ...", self.id)

    if order_type in ("market", "limit") and order["side"] == "buy":
        # Update open rate and actual amount
        self.open_rate = Decimal(order["price"])
        self.amount = Decimal(order["amount"])
        logger.info("%s_BUY has been fulfilled for %s.", order_type.upper(), self)
        self.open_order_id = None
    elif order_type in ("market", "limit") and order["side"] == "sell":
        self.close(order["price"])
        logger.info("%s_SELL has been fulfilled for %s.", order_type.upper(), self)
    elif order_type == "stop_loss_limit":
        self.stoploss_order_id = None
        logger.info("STOP_LOSS_LIMIT is hit for %s.", self)
        self.close(order["average"])
    else:
        raise ValueError(f"Unknown order type: {order_type}")
    cleanup()