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: DigifinexOrderBookMessage
     """
     return DigifinexOrderBookMessage(
         message_type=OrderBookMessageType.DIFF,
         content=record.json,
         timestamp=record.timestamp)
Exemplo n.º 2
0
    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: DigifinexOrderBookMessage
        """

        if metadata:
            msg.update(metadata)

        return DigifinexOrderBookMessage(
            message_type=OrderBookMessageType.DIFF,
            content=msg,
            timestamp=timestamp)
Exemplo n.º 3
0
    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: DigifinexOrderBookMessage
        """

        if metadata:
            msg.update(metadata)

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

        return DigifinexOrderBookMessage(
            message_type=OrderBookMessageType.TRADE,
            content=msg,
            timestamp=timestamp)