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: CoinzoomOrderBookMessage
     """
     return CoinzoomOrderBookMessage(
         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: CoinzoomOrderBookMessage
        """

        if metadata:
            msg.update(metadata)

        return CoinzoomOrderBookMessage(message_type=OrderBookMessageType.DIFF,
                                        content=msg,
                                        timestamp=timestamp)
    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: CoinzoomOrderBookMessage
        """

        trade_msg = {
            "price": msg[1],
            "amount": msg[2],
            "trading_pair": convert_from_exchange_trading_pair(msg[0]),
            "trade_type": None,
        }
        trade_timestamp = str_date_to_ts(msg[3])

        return CoinzoomOrderBookMessage(
            message_type=OrderBookMessageType.TRADE,
            content=trade_msg,
            timestamp=trade_timestamp)