Exemple #1
0
 def decode_order_book(self, encoded_order_book):
     order_book_message = orderbook_pb2.OrderBook()
     order_book_message.ParseFromString(encoded_order_book)
     order_book = OrderBook(order_book_message.instrument_identifier)
     order_book.last_price = order_book_message.statistics.last_price
     order_book.high_price = order_book_message.statistics.high_price
     order_book.low_price = order_book_message.statistics.low_price
     for decoded_order in order_book_message.orders:
         order = ServerOrder(identifier=decoded_order.identifier,
                             way=OrderWay(decoded_order.way),
                             instrument_identifier=order_book_message.instrument_identifier,
                             quantity=decoded_order.quantity,
                             canceled_quantity=decoded_order.canceled_quantity,
                             executed_quantity=decoded_order.executed_quantity,
                             price=decoded_order.price,
                             counterparty=decoded_order.counterparty,
                             timestamp=decoded_order.timestamp)
         order_book.add_order(order)
     self.logger.debug(order_book)
     return order_book
    def decode_order_book(self, encoded_order_book):
        tokens = list(filter(None, encoded_order_book.split(self.separator)))

        instrument_identifier = int(tokens[0])
        order_book = OrderBook(instrument_identifier)
        order_book.last_price = float(tokens[1])
        order_book.high_price = float(tokens[2])
        order_book.low_price = float(tokens[3])

        order_tokens = tokens[4:]
        for x in range(0, len(order_tokens), 8):
            order_book.add_order(
                ServerOrder(instrument_identifier=instrument_identifier,
                            identifier=order_tokens[x],
                            way=OrderWay(int(order_tokens[x + 1])),
                            quantity=float(order_tokens[x + 2]),
                            canceled_quantity=float(order_tokens[x + 3]),
                            executed_quantity=float(order_tokens[x + 4]),
                            price=float(order_tokens[x + 5]),
                            counterparty=order_tokens[x + 6],
                            timestamp=order_tokens[x + 7]))

        return order_book