Ejemplo n.º 1
0
 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
Ejemplo n.º 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
Ejemplo n.º 3
0
 def push_order(self, way, price, quantity, instrument_identifier):
     create_order = CreateOrder(way=way,
                                price=price,
                                quantity=quantity,
                                instrument_identifier=instrument_identifier)
     encoded_create_order = self.marshaller.encode_create_order(
         create_order)
     if not self.server_socket:
         raise ClosedConnection
     self.output_message_stacks[self.server_socket].append(
         encoded_create_order)
Ejemplo n.º 4
0
 def test_simple_create_order(instrument_identifier, marshaller):
     create_order = CreateOrder(way=Buy(),
                                price=42.0,
                                quantity=10.0,
                                instrument_identifier=1)
     encoded_create_order = marshaller.encode_create_order(
         create_order=create_order)
     message_type, body, _ = marshaller.decode_header(encoded_create_order)
     decoded_create_order = marshaller.decode_create_order(body)
     assert message_type == MessageTypes.CreateOrder.value
     assert create_order.__dict__ == decoded_create_order.__dict__
Ejemplo n.º 5
0
 def test_simple_create_order(self):
     create_order = CreateOrder(way=Buy(),
                                price=42.0,
                                quantity=10.0,
                                instrument_identifier=1)
     encoded_create_order = self.marshaller.encode_create_order(
         create_order=create_order)
     message_type, body, _ = self.marshaller.decode_header(
         encoded_create_order)
     decoded_create_order = self.marshaller.decode_create_order(body)
     self.assertEqual(message_type, MessageTypes.CreateOrder.value)
     self.assertEqual(create_order.__dict__, decoded_create_order.__dict__)