예제 #1
0
    def from_network(cls, data):
        """
        Restore a declined trade from the network

        :param data: DeclinedTradePayload
        :return: Restored declined trade
        :rtype: DeclinedTrade
        """
        assert hasattr(data, 'trader_id'), isinstance(data.trader_id, TraderId)
        assert hasattr(data,
                       'message_number'), isinstance(data.message_number,
                                                     MessageNumber)
        assert hasattr(data,
                       'order_number'), isinstance(data.order_number,
                                                   OrderNumber)
        assert hasattr(data, 'recipient_trader_id'), isinstance(
            data.recipient_trader_id, TraderId)
        assert hasattr(data, 'recipient_order_number'), isinstance(
            data.recipient_order_number, OrderNumber)
        assert hasattr(data, 'timestamp'), isinstance(data.timestamp,
                                                      Timestamp)

        return cls(
            MessageId(data.trader_id, data.message_number),
            OrderId(data.trader_id, data.order_number),
            OrderId(data.recipient_trader_id, data.recipient_order_number),
            data.timestamp)
예제 #2
0
    def from_network(cls, data):
        """
        Restore a counter trade from the network

        :param data: TradePayload
        :return: Restored counter trade
        :rtype: CounterTrade
        """
        assert hasattr(data, 'trader_id'), isinstance(data.trader_id, TraderId)
        assert hasattr(data,
                       'message_number'), isinstance(data.message_number,
                                                     MessageNumber)
        assert hasattr(data,
                       'order_number'), isinstance(data.order_number,
                                                   OrderNumber)
        assert hasattr(data, 'recipient_trader_id'), isinstance(
            data.recipient_trader_id, TraderId)
        assert hasattr(data, 'recipient_order_number'), isinstance(
            data.recipient_order_number, OrderNumber)
        assert hasattr(data, 'price'), isinstance(data.price, Price)
        assert hasattr(data, 'quantity'), isinstance(data.quantity, Quantity)
        assert hasattr(data, 'timestamp'), isinstance(data.timestamp,
                                                      Timestamp)

        return cls(
            MessageId(data.trader_id, data.message_number),
            OrderId(data.trader_id, data.order_number),
            OrderId(data.recipient_trader_id, data.recipient_order_number),
            data.price, data.quantity, data.timestamp)
예제 #3
0
    def from_network(cls, data):
        """
        Restore a start transaction message from the network

        :param data: StartTransactionPayload
        :return: Restored start transaction
        :rtype: StartTransaction
        """
        assert hasattr(data, 'trader_id'), isinstance(data.trader_id, TraderId)
        assert hasattr(data, 'message_number'), isinstance(
            data.message_message_number, MessageNumber)
        assert hasattr(data, 'transaction_trader_id'), isinstance(
            data.transaction_trader_id, TraderId)
        assert hasattr(data, 'transaction_number'), isinstance(
            data.transaction_number, TransactionNumber)
        assert hasattr(data,
                       'order_trader_id'), isinstance(data.order_trader_id,
                                                      TraderId)
        assert hasattr(data,
                       'order_number'), isinstance(data.order_number,
                                                   OrderNumber)
        assert hasattr(data, 'recipient_trader_id'), isinstance(
            data.recipient_trader_id, TraderId)
        assert hasattr(data, 'recipient_order_number'), isinstance(
            data.recipient_order_number, OrderNumber)
        assert hasattr(data, 'price'), isinstance(data.price, Price)
        assert hasattr(data, 'quantity'), isinstance(data.quantity, Quantity)
        assert hasattr(data, 'timestamp'), isinstance(data.timestamp,
                                                      Timestamp)

        return cls(
            MessageId(data.trader_id, data.message_number),
            TransactionId(data.transaction_trader_id, data.transaction_number),
            OrderId(data.order_trader_id, data.order_number),
            OrderId(data.recipient_trader_id, data.recipient_order_number),
            data.price, data.quantity, data.timestamp)
예제 #4
0
    def from_network(cls, data):
        """
        Restore a bid from the network

        :param data: OfferPayload
        :return: Restored bid
        :rtype: Bid
        """
        assert hasattr(data, 'trader_id'), isinstance(data.trader_id, TraderId)
        assert hasattr(data, 'message_number'), isinstance(data.message_number, MessageNumber)
        assert hasattr(data, 'order_number'), isinstance(data.order_number, OrderNumber)
        assert hasattr(data, 'price'), isinstance(data.price, Price)
        assert hasattr(data, 'quantity'), isinstance(data.quantity, Quantity)
        assert hasattr(data, 'timeout'), isinstance(data.timeout, Timeout)
        assert hasattr(data, 'timestamp'), isinstance(data.timestamp, Timestamp)

        return cls(
            MessageId(data.trader_id, data.message_number),
            OrderId(data.trader_id, data.order_number),
            data.price,
            data.quantity,
            data.timeout,
            data.timestamp,
        )
예제 #5
0
 def next_identity(self):
     """
     :rtype: OrderId
     """
     self._next_id += 1
     return OrderId(TraderId(self._pubkey), OrderNumber(str(self._next_id)))