def trade_message_from_exchange(cls,
                                    msg: Dict[str, Any],
                                    timestamp: Optional[float] = None,
                                    metadata: Optional[Dict] = None):
        """
        Convert a trade data into standard OrderBookMessage format
        :param record: a trade data from the database
        :return: HitbtcOrderBookMessage
        """

        if metadata:
            msg.update(metadata)

        msg.update({
            "exchange_order_id": msg.get("id"),
            "trade_type": msg.get("side"),
            "price": msg.get("price"),
            "amount": msg.get("quantity"),
        })

        return HitbtcOrderBookMessage(
            message_type=OrderBookMessageType.TRADE,
            content=msg,
            timestamp=timestamp
        )
 def diff_message_from_db(cls,
                          record: RowProxy,
                          metadata: Optional[Dict] = None):
     """
     *used for backtesting
     Convert a row of diff data into standard OrderBookMessage format
     :param record: a row of diff data from the database
     :return: HitbtcOrderBookMessage
     """
     return HitbtcOrderBookMessage(message_type=OrderBookMessageType.DIFF,
                                   content=record.json,
                                   timestamp=record.timestamp)
    def diff_message_from_exchange(cls,
                                   msg: Dict[str, any],
                                   timestamp: Optional[float] = None,
                                   metadata: Optional[Dict] = None):
        """
        Convert json diff data into standard OrderBookMessage format
        :param msg: json diff data from live web socket stream
        :param timestamp: timestamp attached to incoming data
        :return: HitbtcOrderBookMessage
        """

        if metadata:
            msg.update(metadata)

        return HitbtcOrderBookMessage(message_type=OrderBookMessageType.DIFF,
                                      content=msg,
                                      timestamp=timestamp)