def decode_create_order(self, encoded_create_order):
     tokens = list(filter(None, encoded_create_order.split(self.separator)))
     create_order = CreateOrder(way=OrderWay(int(tokens[0])),
                                price=float(tokens[1]),
                                quantity=float(tokens[2]),
                                instrument_identifier=int(tokens[3]))
     return create_order
Exemple #2
0
 def decode_create_order(self, encoded_create_order):
     create_order_message = createorder_pb2.CreateOrder()
     create_order_message.ParseFromString(encoded_create_order)
     create_order = CreateOrder(way=OrderWay(create_order_message.way),
                                quantity=create_order_message.quantity,
                                price=create_order_message.price,
                                instrument_identifier=create_order_message.instrument_identifier)
     return create_order
    def main_loop_hook(self):
        # Read the order books
        for _, order_book in self.feedhandler.order_books.items():
            all_orders = order_book.get_all_orders()

            # Create opposite orders to get executed on every order
            for order in all_orders:
                if order.counterparty != self.ordersender.login:
                    self.ordersender.push_order(
                        way=OrderWay.get_opposite_way(order.way),
                        price=order.price,
                        quantity=order.quantity,
                        instrument_identifier=order.instrument_identifier)
Exemple #4
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
Exemple #6
0
 def test_invalid_way(self):
     wrong_way_value = 42
     with self.assertRaises(InvalidWay):
         OrderWay(way=wrong_way_value)